You just copied the logic to "cleanup and leave" the function several
times. The (current, next and subsequent) maintainers at the next
change in that function simply _have_ to check all cases as if they
are different.
Yes, _now_ you (and all others) know that they are identical. But in 6
month after tons of patches?
Perhaps you want to avoid goto's with:
---- snip (yes, it is purposely not a `diff -urN`) ----
switch(0==0) {
default:
error = -EINVAL;
if (length < 0) /* sorry, but loff_t says... */
break;
error = user_path_walk(path, &nd);
if (error)
break;
inode = nd.dentry->d_inode;
switch(0==0) {
default:
/* For directories it's -EISDIR, for other non-regulars - -EINVAL */
error = -EISDIR;
if (S_ISDIR(inode->i_mode))
break;
error = -EINVAL;
if (!S_ISREG(inode->i_mode))
break;
error = permission(inode,MAY_WRITE);
if (error)
break;
error = -EROFS;
if(IS_RDONLY(inode))
break;
/* the rest omitted - the pattern should be clear */
put_write_access(inode);
break;
}
path_release(&nd);
break;
}
return error;
---- snip ----
FYI, backward goto's can be rewritten with:
---- snip ----
for(;;) {
<do something>
if(i_want_to_go_back)
continue;
<do something_else>
break;
}
---- snip ----
Are these two more understandable because the avoid the 'goto'?
And try to see it not from the viewpoint of a first time reader, but
from the viewpoint of a/the maintainer/developer (who reads this code
probably quite often)?
Bernd
-- Bernd Petrovitsch Email : bernd@gams.at g.a.m.s gmbh Fax : +43 1 205255-900 Prinz-Eugen-Straße 8 A-1040 Vienna/Austria/Europe LUGA : http://www.luga.at
- 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/