Skip to contentSkip to conversation

fuse: drop redundant check in fuse_sync_bucket_alloc()

PATCH Superseded Li Wang 3 participants 4 messages Apr 20 – Apr 23

Subsystems (2)
lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 fuse: drop redundant check in fuse_sync_bucket_alloc()

kzalloc_obj with __GFP_NOFAIL is documented to never return failure, and checking for NULL is redundant (__GFP_NOFAIL in gfp_types.h). Besides, its caller fuse_sync_fs_writes() uses it without a NULL check (atomic_inc on new_bucket, rcu_assign_pointer). fuse_fill_super_common() passes fuse_sync_bucket_alloc() directly to rcu_assign_pointer() without NULL check either.

---
 fs/fuse/inode.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/fuse/inode.c +3 -5
index 33009227e91d..e5069d2f8e90 100644
@@ -676,11 +676,9 @@ static struct fuse_sync_bucket *fuse_sync_bucket_alloc(void)
 	struct fuse_sync_bucket *bucket;
 
 	bucket = kzalloc_obj(*bucket, GFP_KERNEL | __GFP_NOFAIL);
-	if (bucket) {
-		init_waitqueue_head(&bucket->waitq);
-		/* Initial active count */
-		atomic_set(&bucket->count, 1);
-	}
+	init_waitqueue_head(&bucket->waitq);
+	/* Initial active count */
+	atomic_set(&bucket->count, 1);
 	return bucket;
 }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Li Wang

kzalloc_obj with __GFP_NOFAIL is documented to never return failure, and checking for NULL is redundant (__GFP_NOFAIL in gfp_types.h). Besides, its caller fuse_sync_fs_writes() uses it without a NULL check (atomic_inc on new_bucket, rcu_assign_pointer). fuse_fill_super_common() passes fuse_sync_bucket_alloc() directly to rcu_assign_pointer() without NULL check either.

Sorry to be pedantic, but imo the commit message would be better if you dropped these last 2 sentences - the way it's phrased reads as if the callers not checking for null is a reason to drop the check. Your first sentence is the complete justification for the patch.

Quoted 2 lines

btw just as a sidenote, as per this post by Amir [1], there is now a transition where fuse patches should be sent to the [email protected] list

Thanks,
Joanne

[1] https://lore.kernel.org/linux-fsdevel/[email protected]/

Quoted 26 lines
---
 fs/fuse/inode.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/fuse/inode.c +3 -6
index 33009227e91d..e5069d2f8e90 100644
@@ -676,11 +676,9 @@ static struct fuse_sync_bucket *fuse_sync_bucket_alloc(void)
        struct fuse_sync_bucket *bucket;
 
        bucket = kzalloc_obj(*bucket, GFP_KERNEL | __GFP_NOFAIL);
-       if (bucket) {
-               init_waitqueue_head(&bucket->waitq);
-               /* Initial active count */
-               atomic_set(&bucket->count, 1);
-       }
+       init_waitqueue_head(&bucket->waitq);
+       /* Initial active count */
+       atomic_set(&bucket->count, 1);
        return bucket;
 }
 
--

2.34.1

author
#2 lore raw

PATCH v2 1/1 fuse: drop redundant check in fuse_sync_bucket_alloc()

In reply to Li Wang

kzalloc_obj with __GFP_NOFAIL is documented to never return failure, and checking for NULL is redundant (__GFP_NOFAIL in gfp_types.h).

---
Changes since v1:
- Per review, removed the last two sentences of the commit message.

 fs/fuse/inode.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/fuse/inode.c +3 -5
index 33009227e91d..e5069d2f8e90 100644
@@ -676,11 +676,9 @@ static struct fuse_sync_bucket *fuse_sync_bucket_alloc(void)
 	struct fuse_sync_bucket *bucket;
 
 	bucket = kzalloc_obj(*bucket, GFP_KERNEL | __GFP_NOFAIL);
-	if (bucket) {
-		init_waitqueue_head(&bucket->waitq);
-		/* Initial active count */
-		atomic_set(&bucket->count, 1);
-	}
+	init_waitqueue_head(&bucket->waitq);
+	/* Initial active count */
+	atomic_set(&bucket->count, 1);
 	return bucket;
 }
 
Signature · 1 line
2.34.1