Skip to contentSkip to conversation

iio: core: fix uninitialized data in debugfs

PATCH Applied Dan Carpenter 4 participants 6 messages May 25 – Jun 4

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

PATCH 1/1 iio: core: fix uninitialized data in debugfs

If *ppos is non-zero then simple_write_to_buffer() will not initialize the start of buf[]. Non zero values for *ppos aren't going to work anyway. Test for them at the start of the function and return -EINVAL.

Fixes 6d5dd486c715 ("iio: core: make use of simple_write_to_buffer()")

---
The original copy_from_user() code was better:
https://staticthinking.wordpress.com/2026/05/23/simple_write_to_buffer-is-complicated/

---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -1
index bd6f4f9f4533..1308a534582b 100644
@@ -419,7 +419,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
 	char buf[80];
 	int ret;
 
-	if (count >= sizeof(buf))
+	if (*ppos != 0 || count >= sizeof(buf))
 		return -EINVAL;
 
 	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 5 lines · Dan Carpenter

If *ppos is non-zero then simple_write_to_buffer() will not initialize the start of buf[]. Non zero values for *ppos aren't going to work anyway. Test for them at the start of the function and return -EINVAL.

Quoted 9 lines
Fixes 6d5dd486c715 ("iio: core: make use of simple_write_to_buffer()")

---
The original copy_from_user() code was better:
https://staticthinking.wordpress.com/2026/05/23/simple_write_to_buffer-is-complicated/

---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Codewise looks good but often times people will prefer

if (*ppos || count >= sizeof(buf))

over

if (*ppos != 0 || count >= sizeof(buf))

Regardless,

best regards,
max

#2 lore raw
Quoted 18 lines · Maxwell Doose

Hi Dan,

Quoted 5 lines · Dan Carpenter

If *ppos is non-zero then simple_write_to_buffer() will not initialize the start of buf[]. Non zero values for *ppos aren't going to work anyway. Test for them at the start of the function and return -EINVAL.

Quoted 9 lines
Fixes 6d5dd486c715 ("iio: core: make use of simple_write_to_buffer()")

---
The original copy_from_user() code was better:
https://staticthinking.wordpress.com/2026/05/23/simple_write_to_buffer-is-complicated/

---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines

Codewise looks good but often times people will prefer

if (*ppos || count >= sizeof(buf))

over

if (*ppos != 0 || count >= sizeof(buf))

In this context, I feel like either is acceptable since zero represents the number zero. I have a blog about that which I have been trying to promote. #SEO

https://staticthinking.wordpress.com/2024/02/20/when-to-use-0/

Quoted 5 lines

Regardless,

Thanks. And you're other comments with regards to -EINVAL and -ENOSPC are obviously correct.

regards,
dan carpenter

#3 lore raw
Quoted 26 lines · Dan Carpenter
Quoted 24 lines · Maxwell Doose

Hi Dan,

Quoted 5 lines · Dan Carpenter

If *ppos is non-zero then simple_write_to_buffer() will not initialize the start of buf[]. Non zero values for *ppos aren't going to work anyway. Test for them at the start of the function and return -EINVAL.

Quoted 9 lines
Fixes 6d5dd486c715 ("iio: core: make use of simple_write_to_buffer()")

---
The original copy_from_user() code was better:
https://staticthinking.wordpress.com/2026/05/23/simple_write_to_buffer-is-complicated/

---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Codewise looks good but often times people will prefer

if (*ppos || count >= sizeof(buf))

over

Quoted 8 lines
Quoted 1 line

if (*ppos != 0 || count >= sizeof(buf))

In this context, I feel like either is acceptable since zero represents the number zero. I have a blog about that which I have been trying to promote. #SEO

https://staticthinking.wordpress.com/2024/02/20/when-to-use-0/

Interesting article, and I do agree that either is appropriate, just wanted to give you a heads up in case Jonathan or Andy ask you to change it.

best regards,
max

Quoted 13 lines
Quoted 6 lines

Regardless,

Thanks. And you're other comments with regards to -EINVAL and -ENOSPC are obviously correct.

regards,
dan carpenter

maintainer Applied
#4 lore raw
Quoted 36 lines · On Mon, 25 May 2026 15:08:14 -0500 Maxwell Doose <[email protected]> wrote:
Quoted 26 lines · Dan Carpenter
Quoted 24 lines · Maxwell Doose

Hi Dan,

Quoted 5 lines · Dan Carpenter

If *ppos is non-zero then simple_write_to_buffer() will not initialize the start of buf[]. Non zero values for *ppos aren't going to work anyway. Test for them at the start of the function and return -EINVAL.

Quoted 9 lines
Fixes 6d5dd486c715 ("iio: core: make use of simple_write_to_buffer()")

---
The original copy_from_user() code was better:
https://staticthinking.wordpress.com/2026/05/23/simple_write_to_buffer-is-complicated/

---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Codewise looks good but often times people will prefer

if (*ppos || count >= sizeof(buf))

over

Quoted 8 lines
Quoted 1 line

if (*ppos != 0 || count >= sizeof(buf))

In this context, I feel like either is acceptable since zero represents the number zero. I have a blog about that which I have been trying to promote. #SEO

https://staticthinking.wordpress.com/2024/02/20/when-to-use-0/

Quoted 7 lines

Interesting article, and I do agree that either is appropriate, just wanted to give you a heads up in case Jonathan or Andy ask you to change it.

best regards,
max

Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Regardless,

Thanks. And you're other comments with regards to -EINVAL and -ENOSPC are obviously correct.

regards,
dan carpenter

#5 lore raw
Quoted 2 lines · Jonathan Cameron

On Mon, 25 May 2026 15:08:14 -0500
Maxwell Doose <[email protected]> wrote:

...

Quoted 1 line

Applied to the fixes-togreg branch of iio.git and marked for stable.

Same Q as per other patch.

Signature · 2 lines
With Best Regards,
Andy Shevchenko