Skip to contentSkip to conversation

NFS: kmalloc() doesn't return an ERR_PTR()

PATCH In review Dan Carpenter 5 participants 8 messages May 14, 2012 – May 16, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFS: kmalloc() doesn't return an ERR_PTR()

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +4 -4
index ba3019f..233beea 100644
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
 	/* msg and im are freed in idmap_pipe_destroy_msg */
 	msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-	if (IS_ERR(msg)) {
-		ret = PTR_ERR(msg);
+	if (!msg) {
+		ret = -ENOMEM;
 		goto out0;
 	}
 
 	im = kmalloc(sizeof(*im), GFP_KERNEL);
-	if (IS_ERR(im)) {
-		ret = PTR_ERR(im);
+	if (!im) {
+		ret = -ENOMEM;
 		goto out1;
 	}
 
#1 lore raw
Quoted 9 lines · Dan Carpenter

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +0 -0
index ba3019f..233beea 100644

fs/nfs/idmap.c static int nfs_idmap_legacy_upcall(struct key_construction *cons, · line 647

Quoted 6 lines
fs/nfs/idmap.c +1 -2
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
 	/* msg and im are freed in idmap_pipe_destroy_msg */
 	msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-	if (IS_ERR(msg)) {
-		ret = PTR_ERR(msg);
+	if (!msg) {

While at it please put an unlikely()

Thanks
Boaz

Quoted 16 lines
fs/nfs/idmap.c +3 -3
+		ret = -ENOMEM;
 		goto out0;
 	}
 
 	im = kmalloc(sizeof(*im), GFP_KERNEL);
-	if (IS_ERR(im)) {
-		ret = PTR_ERR(im);
+	if (!im) {
+		ret = -ENOMEM;
 		goto out1;
 	}
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 12 lines · Boaz Harrosh
Quoted 10 lines · Dan Carpenter

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +0 -0
index ba3019f..233beea 100644
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
Quoted 9 lines

fs/nfs/idmap.c static int nfs_idmap_legacy_upcall(struct key_construction *cons, · line 647

Quoted 5 lines
fs/nfs/idmap.c +1 -2
 	/* msg and im are freed in idmap_pipe_destroy_msg */
 	msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-	if (IS_ERR(msg)) {
-		ret = PTR_ERR(msg);
+	if (!msg) {

While at it please put an unlikely()

Normally we wouldn't put an unlikely() here. It makes the code less readable and it's not going to affect benchmarks. But I can add one if people prefer.

regards,
dan carpenter

#3 lore raw
Quoted 23 lines · Dan Carpenter
Quoted 12 lines · Boaz Harrosh
Quoted 10 lines · Dan Carpenter

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +0 -0
index ba3019f..233beea 100644
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
Quoted 9 lines

fs/nfs/idmap.c static int nfs_idmap_legacy_upcall(struct key_construction *cons, · line 647

Quoted 5 lines
fs/nfs/idmap.c +1 -2
 	/* msg and im are freed in idmap_pipe_destroy_msg */
 	msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-	if (IS_ERR(msg)) {
-		ret = PTR_ERR(msg);
+	if (!msg) {

While at it please put an unlikely()

Quoted 4 lines

Normally we wouldn't put an unlikely() here. It makes the code less readable and it's not going to affect benchmarks. But I can add one if people prefer.

Personally It makes it more readable for me. It's like a statement:
"error, always slow-path case here". I have brain parsers set for these.

Specifically here the if () is very small but if it is more code it is exactly where it counts. But as a general rule I like the error/slow-path case to be in an unlikely(). Later someone might add more code which will matter.

Quoted 3 lines

regards,
dan carpenter

Thanks
Boaz

#4 lore raw
Quoted 4 lines · Boaz Harrosh

Normally we wouldn't put an unlikely() here. It makes the code less readable and it's not going to affect benchmarks. But I can add one if people prefer.

Personally It makes it more readable for me. It's like a statement:
"error, always slow-path case here". I have brain parsers set for these.

Personally I don't like it. It's a hint for the compiler. Remember when code was liberally sprinkled with "register" modifiers on local variables? Turned out the compiler was smarter than we were, and those modifiers were hurting performance. I'd rather let the compiler decide how to optimize.

#5 lore raw
Quoted 7 lines · Jim Rees
Quoted 4 lines · Boaz Harrosh

Normally we wouldn't put an unlikely() here. It makes the code less readable and it's not going to affect benchmarks. But I can add one if people prefer.

Quoted 8 lines

Personally It makes it more readable for me. It's like a statement:
"error, always slow-path case here". I have brain parsers set for these.

Personally I don't like it. It's a hint for the compiler. Remember when code was liberally sprinkled with "register" modifiers on local variables? Turned out the compiler was smarter than we were, and those modifiers were hurting performance. I'd rather let the compiler decide how to optimize.

Actually the compiler cannot. This is specifying:
"against all judgment I consider this path as the cold path, even if it is
taken more times or generates less compact code. Remove this branch from branch prediction permanently, and never pre-fetch this path"

Again for me it's a programming style programmer-to-programmer hint. And is very unlike "register".

The Kernel style does use unlikely() extensively in error paths, so it's not only me. I'm not sure what the official stance is though.

I agree that it's all just shop talk ;-)

Thanks
Boaz

#6 lore raw
In reply to Boaz Harrosh

Am 15.05.2012 16:18, schrieb Boaz Harrosh:

Quoted 31 lines · Dan Carpenter
Quoted 24 lines · Boaz Harrosh
Quoted 12 lines · Dan Carpenter
Quoted 11 lines

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +0 -0
index ba3019f..233beea 100644
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
Quoted 9 lines

fs/nfs/idmap.c static int nfs_idmap_legacy_upcall(struct key_construction *cons, · line 647

Quoted 5 lines
fs/nfs/idmap.c +1 -2
 	/* msg and im are freed in idmap_pipe_destroy_msg */
 	msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-	if (IS_ERR(msg)) {
-		ret = PTR_ERR(msg);
+	if (!msg) {

While at it please put an unlikely()

Quoted 4 lines

Normally we wouldn't put an unlikely() here. It makes the code less readable and it's not going to affect benchmarks. But I can add one if people prefer.

Quoted 14 lines

Personally It makes it more readable for me. It's like a statement:
"error, always slow-path case here". I have brain parsers set for these.

Specifically here the if () is very small but if it is more code it is exactly where it counts. But as a general rule I like the error/slow-path case to be in an unlikely(). Later someone might add more code which will matter.

Quoted 3 lines

regards,
dan carpenter

Not long a go we had a hint from one of the developers that this likely()-stuff should be used in the scheduler and has no use outside.

re,
wh

#7 lore raw
Quoted 43 lines · walter harms

Am 15.05.2012 16:18, schrieb Boaz Harrosh:

Quoted 40 lines · Dan Carpenter
Quoted 24 lines · Boaz Harrosh
Quoted 12 lines · Dan Carpenter
Quoted 11 lines

Obviously we should check for NULL here instead of IS_ERR().

fs/nfs/idmap.c +0 -0
index ba3019f..233beea 100644
@@ -644,14 +644,14 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons,
 
Quoted 9 lines

fs/nfs/idmap.c static int nfs_idmap_legacy_upcall(struct key_construction *cons, · line 647

Quoted 5 lines
fs/nfs/idmap.c +1 -2
    /* msg and im are freed in idmap_pipe_destroy_msg */
    msg = kmalloc(sizeof(*msg), GFP_KERNEL);
-  if (IS_ERR(msg)) {
-          ret = PTR_ERR(msg);
+  if (!msg) {

While at it please put an unlikely()

Quoted 4 lines

Normally we wouldn't put an unlikely() here.  It makes the code less readable and it's not going to affect benchmarks.  But I can add one if people prefer.

Personally It makes it more readable for me. It's like a statement:
"error, always slow-path case here". I have brain parsers set for these.

Specifically here the if () is very small but if it is more code it is exactly where it counts. But as a general rule I like the error/slow-path case to be in an unlikely(). Later someone might add more code which will matter.

My impression is these hints are useful iif the code is on performance critical path like scheduler, path walking, etc. Apparently nfs idmap isn't the case.

Thanks,
Tao

Quoted 15 lines
Quoted 5 lines
Quoted 3 lines

regards,
dan carpenter

Not long a go we had a hint from one of the developers that this likely()-stuff should be used in the scheduler and has no use outside.

re,
 wh
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html