Congratulations. You've possibly increased the speed of an error path by
an infintessimal amount at the expense of increasing the size of kernel
image and making the code harder to read and maintain. (I say "possibly"
since with caching effects you may have actually slowed the code down.)
Harder to read: The primary code path is polluted with repetative code
that has no bearing on its primary mission.
Harder to maintain: Add an extra resource allocation near the top and
now you have to hunt out every failure case and manually update them all
(with yet more duplicate code) instead of just amending the cleanup code
at the end of the function.
> error = -EINVAL;
> if (length < 0) /* sorry, but loff_t says... */
> - goto out;
> + return error;
Possibly an improvement, though there are maintenance and consistency
arguments against it.
> /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
> error = -EISDIR;
> - if (S_ISDIR(inode->i_mode))
> - goto dput_and_out;
> + if (S_ISDIR(inode->i_mode)){
> + path_release(&nd);
> + return error;
> + }
Nope. This code is precisely what the on-error-goto method is used
to avoid.
The use of goto in the kernel surprised me the first time I saw it, too.
However, rather than hurry to point out how much more I knew about C
style than the kernel hackers, I stayed quiet and made a learning
experience of it. I suggest you do the same.
--Adam
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/