Skip to contentSkip to conversation

fuse: don't set file->private_data in fuse_conn_waiting_read

PATCH In review Jeff Layton 3 participants 5 messages Feb 4, 2025 – Feb 14, 2025

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

PATCH 1/1 fuse: don't set file->private_data in fuse_conn_waiting_read

I see no reason to set the private_data on the file to this value. Just grab the result of the atomic_read() and output it without setting private_data.

---
 fs/fuse/control.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/control.c +2 -3
index 2a730d88cc3bdb50ea1f8a3185faad5f05fc6e74..17ef07cf0c38e44bd7eadb3450bd53a8acc5e885 100644
@@ -49,18 +49,17 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
 {
 	char tmp[32];
 	size_t size;
+	int value;
 
 	if (!*ppos) {
-		long value;
 		struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
 		if (!fc)
 			return 0;
 
 		value = atomic_read(&fc->num_waiting);
-		file->private_data = (void *)value;
 		fuse_conn_put(fc);
 	}
-	size = sprintf(tmp, "%ld\n", (long)file->private_data);
+	size = sprintf(tmp, "%d\n", value);
 	return simple_read_from_buffer(buf, len, ppos, tmp, size);
 }
 

---
base-commit: 9afd7336f3acbe5678cca3b3bc5baefb51ce9564
change-id: 20250204-fuse-fixes-03882c05c1b1

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jeff Layton

I see no reason to set the private_data on the file to this value. Just grab the result of the atomic_read() and output it without setting private_data.

Quoted 9 lines
---
 fs/fuse/control.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/control.c +0 -0
index 2a730d88cc3bdb50ea1f8a3185faad5f05fc6e74..17ef07cf0c38e44bd7eadb3450bd53a8acc5e885 100644

fs/fuse/control.c static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf, · line 53

Quoted 5 lines
fs/fuse/control.c +1 -0
@@ -49,18 +49,17 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
 {
        char tmp[32];
        size_t size;
+       int value;
 

It might be helpful if a "if (*ppos) return -EINVAL;" check gets added here too?

Quoted 52 lines
fs/fuse/control.c +1 -4
        if (!*ppos) {
-               long value;
                struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
                if (!fc)
                        return 0;
 
                value = atomic_read(&fc->num_waiting);
-               file->private_data = (void *)value;
                fuse_conn_put(fc);
        }
-       size = sprintf(tmp, "%ld\n", (long)file->private_data);
+       size = sprintf(tmp, "%d\n", value);
        return simple_read_from_buffer(buf, len, ppos, tmp, size);
 }
 
 
---

base-commit: 9afd7336f3acbe5678cca3b3bc5baefb51ce9564
change-id: 20250204-fuse-fixes-03882c05c1b1

Best regards,
--
Jeff Layton <[email protected]>

        if (!*ppos) {
fs/fuse/control.c +1 -4
-               long value;
                struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
                if (!fc)
                        return 0;
 
                value = atomic_read(&fc->num_waiting);
-               file->private_data = (void *)value;
                fuse_conn_put(fc);
        }
-       size = sprintf(tmp, "%ld\n", (long)file->private_data);
+       size = sprintf(tmp, "%d\n", value);
        return simple_read_from_buffer(buf, len, ppos, tmp, size);
 }
 
 
---

base-commit: 9afd7336f3acbe5678cca3b3bc5baefb51ce9564
change-id: 20250204-fuse-fixes-03882c05c1b1

Best regards,
--
Jeff Layton <[email protected]>

maintainer
#2 lore raw
In reply to Jeff Layton
Quoted 20 lines · Jeff Layton

I see no reason to set the private_data on the file to this value. Just grab the result of the atomic_read() and output it without setting private_data.

---
 fs/fuse/control.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/control.c +1 -0
index 2a730d88cc3bdb50ea1f8a3185faad5f05fc6e74..17ef07cf0c38e44bd7eadb3450bd53a8acc5e885 100644
@@ -49,18 +49,17 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
 {
        char tmp[32];
        size_t size;
+       int value;
 

fs/fuse/control.c static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf, · line 61

Quoted 10 lines
fs/fuse/control.c +0 -2
        if (!*ppos) {
-               long value;
                struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
                if (!fc)
                        return 0;
 
                value = atomic_read(&fc->num_waiting);
-               file->private_data = (void *)value;
                fuse_conn_put(fc);
        }

"value" is uninitialized if *ppos is non-zero.

I also wonder why this patch is an improvement (with the bug fixed)?

Thanks,
Mikos

#3 lore raw
Quoted 27 lines · Miklos Szeredi
Quoted 26 lines · Jeff Layton

I see no reason to set the private_data on the file to this value. Just grab the result of the atomic_read() and output it without setting private_data.

---
 fs/fuse/control.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/fuse/control.c +1 -1
index 2a730d88cc3bdb50ea1f8a3185faad5f05fc6e74..17ef07cf0c38e44bd7eadb3450bd53a8acc5e885 100644
@@ -49,18 +49,17 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
 {
        char tmp[32];
        size_t size;
+       int value;
 
        if (!*ppos) {
-               long value;
                struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
                if (!fc)
                        return 0;
 
Quoted 7 lines

fs/fuse/control.c static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf, · line 61

Quoted 4 lines
fs/fuse/control.c +0 -1
                value = atomic_read(&fc->num_waiting);
-               file->private_data = (void *)value;
                fuse_conn_put(fc);
        }

"value" is uninitialized if *ppos is non-zero.

Good catch. Thanks. Do you want me to resend?

Quoted 2 lines

I also wonder why this patch is an improvement (with the bug fixed)?

It's just an unnecessary assignment. Nothing will look at or use private_data in this codepath, so there is no need to set it.

Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#4 lore raw
Quoted 2 lines · Jeff Layton

It's just an unnecessary assignment. Nothing will look at or use private_data in this codepath, so there is no need to set it.

I think the reason it was done this way is to return a sane value even in the case of small reads (i.e. char-by-char). It's unlikely to matter in real life, but removing it is not a big enough win to be worth risking it.

Thanks,
Miklos