Skip to contentSkip to conversation

Staging: lustre: llite: Remove NULL check before kfree

PATCH Superseded Bhumika Goyal 2 participants 7 messages Feb 12, 2016 – Feb 13, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: lustre: llite: Remove NULL check before kfree

NULL check before kfree is unnecessary so remove it. Semantic patch used:
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>

---
 drivers/staging/lustre/lustre/llite/xattr.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/lustre/lustre/llite/xattr.c +1 -5
index 8eb43f1..310e381 100644
@@ -192,11 +192,7 @@ int ll_setxattr_common(struct inode *inode, const char *name,
 			 valid, name, pv, size, 0, flags,
 			 ll_i2suppgid(inode), &req);
 #ifdef CONFIG_FS_POSIX_ACL
-	if (new_value != NULL)
-		/*
-		 * Release the posix ACL space.
-		 */
-		kfree(new_value);
+	kfree(new_value);
 	if (acl != NULL)
 		lustre_ext_acl_xattr_free(acl);
 #endif
Signature · 1 line
1.9.1
#1 lore raw
Quoted 5 lines · Bhumika Goyal

NULL check before kfree is unnecessary so remove it. Semantic patch used:
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }

Normally, the braces in this rule should not be useful, because the kernel coding style is that a single statement in an if branch should not be enclosed in braces, at least unless another branch is present and that one requires braces. But here there is no other branch.

However, as you see in your example, when you put a single statement with braces, Coccinelle will also consider the case where the braces are not there, via an isomoprhism.

Quoted 17 lines

+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>

---
 drivers/staging/lustre/lustre/llite/xattr.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/lustre/lustre/llite/xattr.c +0 -0
index 8eb43f1..310e381 100644

drivers/staging/lustre/lustre/llite/xattr.c int ll_setxattr_common(struct inode *inode, const char *name, · line 195

Quoted 9 lines
drivers/staging/lustre/lustre/llite/xattr.c +1 -5
@@ -192,11 +192,7 @@ int ll_setxattr_common(struct inode *inode, const char *name,
 			 valid, name, pv, size, 0, flags,
 			 ll_i2suppgid(inode), &req);
 #ifdef CONFIG_FS_POSIX_ACL
-	if (new_value != NULL)
-		/*
-		 * Release the posix ACL space.
-		 */
-		kfree(new_value);
+	kfree(new_value);

I'm not sure that it's a good idea to remove the comment. Coccinelle has a strategy for removing comments, but it is just a heuristic. There is no guarantee that it makes the right decision in all cases.

Concretely, the comment is removed because you remoce both the if header and the kfree. Coccinelle doesn't realize that you added the kfree back.

julia

Quoted 13 lines
drivers/staging/lustre/lustre/llite/xattr.c +0 -0
 	if (acl != NULL)
 		lustre_ext_acl_xattr_free(acl);
 #endif
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455272748-14400-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

I will send a v2 with the comments added back.

Thanks,
Bhumika

#3 lore raw

PATCH v2 1/1 Staging: lustre: llite: Remove NULL check before kfree

In reply to Bhumika Goyal

NULL check before kfree is unnecessary so remove it. Semantic patch used:
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>

---
Changes since v1:
*Add the comment before kfree back.

---
 drivers/staging/lustre/lustre/llite/xattr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/lustre/lustre/llite/xattr.c +4 -5
index 8eb43f1..fa477e7 100644
@@ -192,11 +192,10 @@ int ll_setxattr_common(struct inode *inode, const char *name,
 			 valid, name, pv, size, 0, flags,
 			 ll_i2suppgid(inode), &req);
 #ifdef CONFIG_FS_POSIX_ACL
-	if (new_value != NULL)
-		/*
-		 * Release the posix ACL space.
-		 */
-		kfree(new_value);
+	/*
+	 * Release the posix ACL space.
+	 */
+	kfree(new_value);
 	if (acl != NULL)
 		lustre_ext_acl_xattr_free(acl);
 #endif
Signature · 1 line
1.9.1
#4 lore raw
Quoted 12 lines · Bhumika Goyal

NULL check before kfree is unnecessary so remove it. Semantic patch used:
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>

Quoted 5 lines

---
Changes since v1:
*Add the comment before kfree back.
---

The --- below your comemnt is not necessary.

julia

Quoted 33 lines
 drivers/staging/lustre/lustre/llite/xattr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/lustre/lustre/llite/xattr.c +4 -6
index 8eb43f1..fa477e7 100644
@@ -192,11 +192,10 @@ int ll_setxattr_common(struct inode *inode, const char *name,
 			 valid, name, pv, size, 0, flags,
 			 ll_i2suppgid(inode), &req);
 #ifdef CONFIG_FS_POSIX_ACL
-	if (new_value != NULL)
-		/*
-		 * Release the posix ACL space.
-		 */
-		kfree(new_value);
+	/*
+	 * Release the posix ACL space.
+	 */
+	kfree(new_value);
 	if (acl != NULL)
 		lustre_ext_acl_xattr_free(acl);
 #endif
--

1.9.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455287874-18123-1-git-send-email-bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#5 lore raw

Thank you. Will surely keep in mind for future patches.

Thanks,
Bhumika

#6 lore raw
Quoted 1 line · Bhumika Goyal

Thank you. Will surely keep in mind for future patches.

It is nice to quote some of the message that you are responding to. Otherwise, it is hard to follow the conversation.

julia

Quoted 15 lines

Thanks,
Bhumika

--
You received this message because you are subscribed to the Google Groups
"outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/710bbc9f-1914-4b29-b135- a229028e47ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.