GFS2: Return -ENOMEM only if kmalloc fails
Subsystems (2)
PATCH 1/1 GFS2: Return -ENOMEM only if kmalloc fails
The error variable should be assigned the value of -ENOMEM after the NULL check and not before.
--- fs/gfs2/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/acl.c +1 -1
@@ -174,8 +174,8 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) len =posix_acl_to_xattr (acl,NULL ,0 ); data =kmalloc (len,GFP_NOFS ); - error = -ENOMEM ;if (data =NULL ) + error = -ENOMEM ; goto out;posix_acl_to_xattr (acl, data, len); error =gfs2_xattr_acl_chmod (ip, attr, data);
Signature · 1 line
1.7.10
Am Donnerstag, 26. April 2012, 23:12:58 schrieb Emil Goode:
Quoted 13 lines
The error variable should be assigned the value of
-ENOMEMafter the NULL check and not before.Signed-off-by Emil Goode <[email protected]>--- fs/gfs2/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/gfs2/acl.c +0
-0
fs/gfs2/acl.c int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) · line 179
Quoted 7 lines
fs/gfs2/acl.c +1
-1@@ -174,8 +174,8 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) len =posix_acl_to_xattr (acl,NULL ,0 ); data =kmalloc (len,GFP_NOFS ); - error = -ENOMEM ;if (data =NULL ) + error = -ENOMEM ; goto out;
Hint: read about the syntax of the if statement. Secondly, consider how the compiler can optimize the original.
Regards
Oliver
Quoted 13 lines · Emil Goode
The error variable should be assigned the value of
-ENOMEMafter the NULL check and not before.Signed-off-by Emil Goode <[email protected]>--- fs/gfs2/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/gfs2/acl.c +0
-0
fs/gfs2/acl.c int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) · line 181
Quoted 9 lines
fs/gfs2/acl.c +1
-1@@ -174,8 +174,8 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) len =posix_acl_to_xattr (acl,NULL ,0 ); data =kmalloc (len,GFP_NOFS ); - error = -ENOMEM ;if (data =NULL ) + error = -ENOMEM ; goto out;posix_acl_to_xattr (acl, data, len); error =gfs2_xattr_acl_chmod (ip, attr, data);
You missed the brackets on the if, introducing a bug that will cause it to now always fail.
As 'error' gets overwritten in the successful case, there is no reason to change this afaics.
Dave
I forgot the braces, embarrassing!
I see your point, thanks.
Best regards, Emil
Quoted 27 lines · Oliver Neukum
Am Donnerstag, 26. April 2012, 23:12:58 schrieb Emil Goode:
Quoted 13 lines
The error variable should be assigned the value of
-ENOMEMafter the NULL check and not before.Signed-off-by Emil Goode <[email protected]>--- fs/gfs2/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/gfs2/acl.c +0
-0fs/gfs2/acl.c int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) · line 179
Quoted 7 lines
fs/gfs2/acl.c +1
-1@@ -174,8 +174,8 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr) len =posix_acl_to_xattr (acl,NULL ,0 ); data =kmalloc (len,GFP_NOFS ); - error = -ENOMEM ;if (data =NULL ) + error = -ENOMEM ; goto out;Hint: read about the syntax of the if statement. Secondly, consider how the compiler can optimize the original.
Regards
Oliver