fuse: don't set file->private_data in fuse_conn_waiting_read
Subsystems (2)
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
@@ -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]>
Quoted 6 lines · Jeff Layton
I see no reason to set the
private_dataon the file to this value. Just grab the result of theatomic_read()and output it without settingprivate_data.Signed-off-by Jeff Layton <[email protected]>
Quoted 9 lines
--- fs/fuse/control.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/fuse/control.c +0
-0
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
-4if (!*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-03882c05c1b1Best 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-03882c05c1b1Best regards,
--
Jeff Layton <[email protected]>
Miklos Szeredi
maintainerQuoted 20 lines · Jeff Layton
I see no reason to set the
private_dataon the file to this value. Just grab the result of theatomic_read()and output it without settingprivate_data.Signed-off-by Jeff Layton <[email protected]>--- fs/fuse/control.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)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;
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
-2if (!*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
Quoted 27 lines · Miklos Szeredi
Quoted 26 lines · Jeff Layton
I see no reason to set the
private_dataon the file to this value. Just grab the result of theatomic_read()and output it without settingprivate_data.Signed-off-by Jeff Layton <[email protected]>--- fs/fuse/control.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/fuse/control.c +1
-1@@ -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
-1value =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]>
Miklos Szeredi
maintainerQuoted 2 lines · Jeff Layton
It's just an unnecessary assignment. Nothing will look at or use
private_datain 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