All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: trival fix of __btrfs_set_acl error handling
@ 2015-09-08  8:46 Sheng Yong
  2015-09-08  8:50 ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Sheng Yong @ 2015-09-08  8:46 UTC (permalink / raw)
  To: linux-btrfs

* If the allocation failed, don't free to free it, even though kfree
  allows to free a NULL pointer.
* If posix_acl_to_xattr() failed, cleanup the allocation and return
  the error directly.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 fs/btrfs/acl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 9a0124a..6d01d09 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -103,18 +103,18 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
 	if (acl) {
 		size = posix_acl_xattr_size(acl->a_count);
 		value = kmalloc(size, GFP_NOFS);
-		if (!value) {
-			ret = -ENOMEM;
-			goto out;
-		}
+		if (!value)
+			return -ENOMEM;
 
 		ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
-		if (ret < 0)
-			goto out;
+		if (ret < 0) {
+			kfree(value);
+			return ret;
+		}
 	}
 
 	ret = __btrfs_setxattr(trans, inode, name, value, size, 0);
-out:
+
 	kfree(value);
 
 	if (!ret)
-- 
1.8.3.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: trival fix of __btrfs_set_acl error handling
  2015-09-08  8:46 [PATCH] btrfs: trival fix of __btrfs_set_acl error handling Sheng Yong
@ 2015-09-08  8:50 ` Qu Wenruo
  2015-09-08  9:02   ` Sheng Yong
  0 siblings, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2015-09-08  8:50 UTC (permalink / raw)
  To: Sheng Yong, linux-btrfs

Sheng Yong wrote on 2015/09/08 08:46 +0000:
> * If the allocation failed, don't free to free it, even though kfree
>    allows to free a NULL pointer.
> * If posix_acl_to_xattr() failed, cleanup the allocation and return
>    the error directly.
So, what's the point?
For me, I didn't see the pros of the change.
As kfree() allow NULL pointer, why not use it?

Thanks,
Qu
>
> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
> ---
>   fs/btrfs/acl.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
> index 9a0124a..6d01d09 100644
> --- a/fs/btrfs/acl.c
> +++ b/fs/btrfs/acl.c
> @@ -103,18 +103,18 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
>   	if (acl) {
>   		size = posix_acl_xattr_size(acl->a_count);
>   		value = kmalloc(size, GFP_NOFS);
> -		if (!value) {
> -			ret = -ENOMEM;
> -			goto out;
> -		}
> +		if (!value)
> +			return -ENOMEM;
>
>   		ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
> -		if (ret < 0)
> -			goto out;
> +		if (ret < 0) {
> +			kfree(value);
> +			return ret;
> +		}
>   	}
>
>   	ret = __btrfs_setxattr(trans, inode, name, value, size, 0);
> -out:
> +
>   	kfree(value);
>
>   	if (!ret)
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: trival fix of __btrfs_set_acl error handling
  2015-09-08  8:50 ` Qu Wenruo
@ 2015-09-08  9:02   ` Sheng Yong
  2015-09-08 11:51     ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Sheng Yong @ 2015-09-08  9:02 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs

Hi, Qu

On 9/8/2015 4:50 PM, Qu Wenruo wrote:
> Sheng Yong wrote on 2015/09/08 08:46 +0000:
>> * If the allocation failed, don't free to free it, even though kfree
>>    allows to free a NULL pointer.
>> * If posix_acl_to_xattr() failed, cleanup the allocation and return
>>    the error directly.
> So, what's the point?
> For me, I didn't see the pros of the change.
> As kfree() allow NULL pointer, why not use it?
In fact, there is no semantic changes. It's just because when I walk through
the code, and find there is no need to call kfree(), and could be cleaned up.
It's fine to keep as it is :)

thanks,
Sheng
> 
> Thanks,
> Qu
>>
>> Signed-off-by: Sheng Yong <shengyong1@huawei.com>
>> ---
>>   fs/btrfs/acl.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
>> index 9a0124a..6d01d09 100644
>> --- a/fs/btrfs/acl.c
>> +++ b/fs/btrfs/acl.c
>> @@ -103,18 +103,18 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
>>       if (acl) {
>>           size = posix_acl_xattr_size(acl->a_count);
>>           value = kmalloc(size, GFP_NOFS);
>> -        if (!value) {
>> -            ret = -ENOMEM;
>> -            goto out;
>> -        }
>> +        if (!value)
>> +            return -ENOMEM;
>>
>>           ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
>> -        if (ret < 0)
>> -            goto out;
>> +        if (ret < 0) {
>> +            kfree(value);
>> +            return ret;
>> +        }
>>       }
>>
>>       ret = __btrfs_setxattr(trans, inode, name, value, size, 0);
>> -out:
>> +
>>       kfree(value);
>>
>>       if (!ret)
>>
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: trival fix of __btrfs_set_acl error handling
  2015-09-08  9:02   ` Sheng Yong
@ 2015-09-08 11:51     ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2015-09-08 11:51 UTC (permalink / raw)
  To: Sheng Yong; +Cc: Qu Wenruo, linux-btrfs

On Tue, Sep 08, 2015 at 05:02:32PM +0800, Sheng Yong wrote:
> Hi, Qu
> 
> On 9/8/2015 4:50 PM, Qu Wenruo wrote:
> > Sheng Yong wrote on 2015/09/08 08:46 +0000:
> >> * If the allocation failed, don't free to free it, even though kfree
> >>    allows to free a NULL pointer.
> >> * If posix_acl_to_xattr() failed, cleanup the allocation and return
> >>    the error directly.
> > So, what's the point?
> > For me, I didn't see the pros of the change.
> > As kfree() allow NULL pointer, why not use it?
> In fact, there is no semantic changes. It's just because when I walk through
> the code, and find there is no need to call kfree(), and could be cleaned up.
> It's fine to keep as it is :)

I agree with Qu. In this case it's not performance critical and conforms
to the widely used pattern of single return point from branches.
However, the acl functions are not consistent in that respect. It's more
a matter of style that gets unified eventually.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-08 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-08  8:46 [PATCH] btrfs: trival fix of __btrfs_set_acl error handling Sheng Yong
2015-09-08  8:50 ` Qu Wenruo
2015-09-08  9:02   ` Sheng Yong
2015-09-08 11:51     ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.