Skip to contentSkip to conversation

staging: lustre: llite: Use IS_ERR_OR_NULL

PATCH In review Amitoj Kaur Chawla 3 participants 9 messages Feb 13, 2016 – Feb 15, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre: llite: Use IS_ERR_OR_NULL

Use macro IS_ERR_OR_NULL in place of tests for NULL and IS_ERR.

The Coccinelle semantic patch used to make the change is as follows:

//<smpl>
@@
expression e;
@@

- e == NULL || IS_ERR(e)
+ IS_ERR_OR_NULL(e)
//</smpl>

---
 drivers/staging/lustre/lustre/llite/llite_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +2 -2
index 446e4b8..5a32f9f 100644
@@ -493,7 +493,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
 	md_free_lustre_md(sbi->ll_md_exp, &lmd);
 	ptlrpc_req_finished(request);
 
-	if (root == NULL || IS_ERR(root)) {
+	if (IS_ERR_OR_NULL(root)) {
 		if (lmd.lsm)
 			obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
 #ifdef CONFIG_FS_POSIX_ACL
@@ -1965,7 +1965,7 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
 		*inode = ll_iget(sb, cl_fid_build_ino(&md.body->fid1,
 					     sbi->ll_flags & LL_SBI_32BIT_API),
 				 &md);
-		if (*inode == NULL || IS_ERR(*inode)) {
+		if (IS_ERR_OR_NULL(*inode)) {
 #ifdef CONFIG_FS_POSIX_ACL
 			if (md.posix_acl) {
 				posix_acl_release(md.posix_acl);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · Amitoj Kaur Chawla

Use macro IS_ERR_OR_NULL in place of tests for NULL and IS_ERR.

The Coccinelle semantic patch used to make the change is as follows:

//<smpl>
@@
expression e;
@@

- e == NULL || IS_ERR(e)
+ IS_ERR_OR_NULL(e)

Nice :)

julia

Quoted 39 lines

//</smpl>

---
 drivers/staging/lustre/lustre/llite/llite_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +2 -2
index 446e4b8..5a32f9f 100644
@@ -493,7 +493,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
 	md_free_lustre_md(sbi->ll_md_exp, &lmd);
 	ptlrpc_req_finished(request);
 
-	if (root == NULL || IS_ERR(root)) {
+	if (IS_ERR_OR_NULL(root)) {
 		if (lmd.lsm)
 			obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
 #ifdef CONFIG_FS_POSIX_ACL
@@ -1965,7 +1965,7 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
 		*inode = ll_iget(sb, cl_fid_build_ino(&md.body->fid1,
 					     sbi->ll_flags & LL_SBI_32BIT_API),
 				 &md);
-		if (*inode == NULL || IS_ERR(*inode)) {
+		if (IS_ERR_OR_NULL(*inode)) {
 #ifdef CONFIG_FS_POSIX_ACL
 			if (md.posix_acl) {
 				posix_acl_release(md.posix_acl);
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/20160213150641.GA26097%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw
In reply to Amitoj Kaur Chawla

drivers/staging/lustre/lustre/llite/llite_lib.c static int client_common_fill_super(struct super_block *sb, char *md, char *dt, · line 499

Quoted 13 lines · On Saturday 13 February 2016 20:36:41 Amitoj Kaur Chawla wrote:
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
index 446e4b8..5a32f9f 100644
@@ -493,7 +493,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        md_free_lustre_md(sbi->ll_md_exp, &lmd);
        ptlrpc_req_finished(request);
 
-       if (root == NULL || IS_ERR(root)) {
+       if (IS_ERR_OR_NULL(root)) {
                if (lmd.lsm)
                        obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
 

There is almost always a bug if you have to use IS_ERR_OR_NULL().

Please check if that is actually required here at all, any why the two cases should be handled the same way.

Normally a function that can return an error pointer should never return a NULL pointer and vice versa, so a better fix would be to change the function that returned the root variable to have a consistent behavior.

Arnd

#3 lore raw
Quoted 12 lines · Arnd Bergmann

drivers/staging/lustre/lustre/llite/llite_lib.c static int client_common_fill_super(struct super_block *sb, char *md, char *dt, · line 498

Quoted 5 lines
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
-       if (root == NULL || IS_ERR(root)) {
+       if (IS_ERR_OR_NULL(root)) {
                if (lmd.lsm)
                        obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);

There is almost always a bug if you have to use IS_ERR_OR_NULL().

Please check if that is actually required here at all, any why the two cases should be handled the same way.

Quoted 6 lines

Normally a function that can return an error pointer should never return a NULL pointer and vice versa, so a better fix would be to change the function that returned the root variable to have a consistent behavior.

Arnd

This is how the variable root is defined:

struct *inode root;
root = ll_iget(...)

and then we have the above statement.

ll_iget returns a *inode or NULL pointer

Similar for the second case in the above patch wherein instead of having a variable root, *inode is used directly.

What would be the correct change here?

Amitoj

#4 lore raw
Quoted 25 lines · Amitoj Kaur Chawla
Quoted 12 lines · Arnd Bergmann

drivers/staging/lustre/lustre/llite/llite_lib.c static int client_common_fill_super(struct super_block *sb, char *md, char *dt, · line 498

Quoted 5 lines
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
-       if (root == NULL || IS_ERR(root)) {
+       if (IS_ERR_OR_NULL(root)) {
                if (lmd.lsm)
                        obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);

There is almost always a bug if you have to use IS_ERR_OR_NULL().

Please check if that is actually required here at all, any why the two cases should be handled the same way.

Quoted 6 lines

Normally a function that can return an error pointer should never return a NULL pointer and vice versa, so a better fix would be to change the function that returned the root variable to have a consistent behavior.

Arnd

This is how the variable root is defined:

struct *inode root;
root = ll_iget(...)

Quoted 8 lines

and then we have the above statement.

ll_iget returns a *inode or NULL pointer

Similar for the second case in the above patch wherein instead of having a variable root, *inode is used directly.

What would be the correct change here?

You have to check all of the return points in ll_iget to see if any of them could return and ERR_PTR value. This may require checking in some other functions to see what values they return. If none of them can return an ERR_PTR value, you should just remove the ERR_PTR test.

julia

Quoted 10 lines

Amitoj

Signature · 5 lines
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/CA%2B5yK5HTPxk9EtTgUki%2B47-1G0fhHL-t1YUvaeeha_Ltd%3D3F9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
#5 lore raw
Quoted 6 lines · Julia Lawall

You have to check all of the return points in ll_iget to see if any of them could return and ERR_PTR value. This may require checking in some other functions to see what values they return. If none of them can return an ERR_PTR value, you should just remove the ERR_PTR test.

julia

For one case, ll_iget is returning a ERR_PTR value.

Amitoj

#6 lore raw
Quoted 9 lines · Amitoj Kaur Chawla
Quoted 6 lines · Julia Lawall

You have to check all of the return points in ll_iget to see if any of them could return and ERR_PTR value. This may require checking in some other functions to see what values they return. If none of them can return an ERR_PTR value, you should just remove the ERR_PTR test.

julia

For one case, ll_iget is returning a ERR_PTR value.

I agree. Maybe a reasonable solution would be to check for NULL and, if it is found return ERR_PTR(-ENOMEM).

julia

#7 lore raw
Quoted 8 lines · On Sunday 14 February 2016 18:46:48 Julia Lawall wrote:
Quoted 6 lines · Amitoj Kaur Chawla
Quoted 5 lines · Julia Lawall

You have to check all of the return points in ll_iget to see if any of them could return and ERR_PTR value. This may require checking in some other functions to see what values they return. If none of them can return an ERR_PTR value, you should just remove the ERR_PTR test.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

julia

For one case, ll_iget is returning a ERR_PTR value.

I agree. Maybe a reasonable solution would be to check for NULL and, if it is found return ERR_PTR(-ENOMEM).

That sounds good, it would even simplify the function.

Arnd

#8 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · On Sunday 14 February 2016 18:46:48 Julia Lawall wrote:

I agree. Maybe a reasonable solution would be to check for NULL and, if it is found return ERR_PTR(-ENOMEM).

That sounds good, it would even simplify the function.

Arnd

Okay. Will send v2.

Thanks,
Amitoj