LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] ext4: remove unnecessary gotos in ext4_xattr_set_entry
@ 2019-05-31 12:10 Pavel Tikhomirov
2019-05-31 21:46 ` Andreas Dilger
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Tikhomirov @ 2019-05-31 12:10 UTC (permalink / raw)
To: Theodore Ts'o, Pavel Tikhomirov
Cc: Andreas Dilger, linux-ext4, linux-kernel
In the "out" label we only iput old/new_ea_inode-s, in all these places
these variables are always NULL so there is no point in goto to "out".
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
fs/ext4/xattr.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 491f9ee4040e..ac2ddd4446b3 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1601,8 +1601,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
next = EXT4_XATTR_NEXT(last);
if ((void *)next >= s->end) {
EXT4_ERROR_INODE(inode, "corrupted xattr entries");
- ret = -EFSCORRUPTED;
- goto out;
+ return -EFSCORRUPTED;
}
if (!last->e_value_inum && last->e_value_size) {
size_t offs = le16_to_cpu(last->e_value_offs);
@@ -1620,8 +1619,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
free += EXT4_XATTR_LEN(name_len) + old_size;
if (free < EXT4_XATTR_LEN(name_len) + new_size) {
- ret = -ENOSPC;
- goto out;
+ return -ENOSPC;
}
/*
@@ -1634,8 +1632,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
new_size && is_block &&
(min_offs + old_size - new_size) <
EXT4_XATTR_BLOCK_RESERVE(inode)) {
- ret = -ENOSPC;
- goto out;
+ return -ENOSPC;
}
}
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: remove unnecessary gotos in ext4_xattr_set_entry
2019-05-31 12:10 [PATCH] ext4: remove unnecessary gotos in ext4_xattr_set_entry Pavel Tikhomirov
@ 2019-05-31 21:46 ` Andreas Dilger
2019-06-02 0:15 ` Theodore Ts'o
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Dilger @ 2019-05-31 21:46 UTC (permalink / raw)
To: Pavel Tikhomirov; +Cc: Theodore Ts'o, linux-ext4, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]
On May 31, 2019, at 6:10 AM, Pavel Tikhomirov <ptikhomirov@virtuozzo.com> wrote:
>
> In the "out" label we only iput old/new_ea_inode-s, in all these places
> these variables are always NULL so there is no point in goto to "out".
>
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
I'm not a fan of changes like this, since it adds potential complexity/bugs
if the error handling path is changed in the future. That is one of the major
benefits of the "goto out_*" model of error handling is that you only need to
add one new label to the end of the function when some new state is added that
needs to be cleaned up, compared to having to check each individual error to
see if something needs to be cleaned up.
Cheers, Andreas
> ---
> fs/ext4/xattr.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 491f9ee4040e..ac2ddd4446b3 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1601,8 +1601,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
> next = EXT4_XATTR_NEXT(last);
> if ((void *)next >= s->end) {
> EXT4_ERROR_INODE(inode, "corrupted xattr entries");
> - ret = -EFSCORRUPTED;
> - goto out;
> + return -EFSCORRUPTED;
> }
> if (!last->e_value_inum && last->e_value_size) {
> size_t offs = le16_to_cpu(last->e_value_offs);
> @@ -1620,8 +1619,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
> free += EXT4_XATTR_LEN(name_len) + old_size;
>
> if (free < EXT4_XATTR_LEN(name_len) + new_size) {
> - ret = -ENOSPC;
> - goto out;
> + return -ENOSPC;
> }
>
> /*
> @@ -1634,8 +1632,7 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
> new_size && is_block &&
> (min_offs + old_size - new_size) <
> EXT4_XATTR_BLOCK_RESERVE(inode)) {
> - ret = -ENOSPC;
> - goto out;
> + return -ENOSPC;
> }
> }
>
> --
> 2.20.1
>
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ext4: remove unnecessary gotos in ext4_xattr_set_entry
2019-05-31 21:46 ` Andreas Dilger
@ 2019-06-02 0:15 ` Theodore Ts'o
0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2019-06-02 0:15 UTC (permalink / raw)
To: Andreas Dilger; +Cc: Pavel Tikhomirov, linux-ext4, linux-kernel
On Fri, May 31, 2019 at 03:46:54PM -0600, Andreas Dilger wrote:
> On May 31, 2019, at 6:10 AM, Pavel Tikhomirov <ptikhomirov@virtuozzo.com> wrote:
> >
> > In the "out" label we only iput old/new_ea_inode-s, in all these places
> > these variables are always NULL so there is no point in goto to "out".
> >
> > Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
>
> I'm not a fan of changes like this, since it adds potential complexity/bugs
> if the error handling path is changed in the future. That is one of the major
> benefits of the "goto out_*" model of error handling is that you only need to
> add one new label to the end of the function when some new state is added that
> needs to be cleaned up, compared to having to check each individual error to
> see if something needs to be cleaned up.
I'm not a fan either, for the reasons Andreas stated; if you ever move
code around, it's much more hazardous because you now have to check if
what had previously been a "return ret" now has to change into "goto
outl". In some case, it's really obvious, if the code is at the very
beginning of the function, but when you're 35 lines down, well over
the size of many of an editor window, it's no longer quite so obvious
whether or not "goto out" is necessary.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-02 0:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31 12:10 [PATCH] ext4: remove unnecessary gotos in ext4_xattr_set_entry Pavel Tikhomirov
2019-05-31 21:46 ` Andreas Dilger
2019-06-02 0:15 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).