Skip to contentSkip to conversation

GFS2: Return -ENOMEM only if kmalloc fails

PATCH In review Emil Goode 3 participants 4 messages Apr 26, 2012

Subsystems (2)
lore
Share & tools
lore

Emil Goode

author
#0 lore raw

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
index 230eb0f..90f6328 100644
@@ -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
#1 lore raw

Am Donnerstag, 26. April 2012, 23:12:58 schrieb Emil Goode:

Quoted 13 lines

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 +0 -0
index 230eb0f..90f6328 100644

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

author
#2 lore raw

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 -ENOMEM after the NULL check and not before.

---
 fs/gfs2/acl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/acl.c +0 -0
index 230eb0f..90f6328 100644

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

#3 lore raw
In reply to Emil Goode
Quoted 13 lines · Emil Goode

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 +0 -0
index 230eb0f..90f6328 100644

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