iio:imu: adis16480: show_firmware() buffer too small
Subsystems (3)
PATCH 1/1 iio:imu: adis16480: show_firmware() buffer too small
Smatch complains that snprintf() returns the number of characters, not counting the NUL terminator, which *would* have been printed if there were enough space. In other words the return value could be more than sizeof(buf).
In this case, we are printing something like "ff.ff\n" which is at most 6 characters and a NUL so that's not an issue. I changed snprintf() to scnprintf() to silence the warning.
But since the buffer doesn't include space for the NUL terminator, we need to make it bigger or the "\n" will be truncated off.
drivers/iio/imu/adis16480.c +2 -2
@@ -125,7 +125,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct adis16480 *adis16480 = file->private_data; -char buf[6 ]; +char buf[7 ];size_t len;u16 rev;int ret;
@@ -134,7 +134,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file,if (ret <0 )return ret; - len =snprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff ); + len =scnprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff );return simple_read_from_buffer (userbuf, count, ppos, buf, len); }
Quoted 5 lines · Dan Carpenter
Smatch complains that
snprintf()returns the number of characters, not counting the NUL terminator, which *would* have been printed if there were enough space. In other words the return value could be more than sizeof(buf).
Quoted 7 lines
In this case, we are printing something like "ff.ff\n" which is at most 6 characters and a NUL so that's not an issue. I changed
snprintf()toscnprintf()to silence the warning.But since the buffer doesn't include space for the NUL terminator, we need to make it bigger or the "\n" will be truncated off.
Thanks,
Quoted 24 lines
Signed-off-by Dan Carpenter <[email protected]>drivers/iio/imu/adis16480.c +2
-2@@ -125,7 +125,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct adis16480 *adis16480 = file->private_data; -char buf[6 ]; +char buf[7 ];size_t len;u16 rev;int ret;@@ -134,7 +134,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file,if (ret <0 )return ret; - len =snprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff ); + len =scnprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff );return simple_read_from_buffer (userbuf, count, ppos, buf, len); }
Jonathan Cameron
maintainerQuoted 10 lines · Lars-Peter Clausen
Quoted 9 lines · Dan Carpenter
Smatch complains that
snprintf()returns the number of characters, not counting the NUL terminator, which *would* have been printed if there were enough space. In other words the return value could be more than sizeof(buf).In this case, we are printing something like "ff.ff\n" which is at most 6 characters and a NUL so that's not an issue. I changed
snprintf()toscnprintf()to silence the warning.
Quoted 9 lines
Quoted 3 lines
But since the buffer doesn't include space for the NUL terminator, we need to make it bigger or the "\n" will be truncated off.
Thanks,
Added to togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
Quoted 30 lines
Quoted 16 lines
Signed-off-by Dan Carpenter <[email protected]>drivers/iio/imu/adis16480.c +1
-1@@ -125,7 +125,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) { struct adis16480 *adis16480 = file->private_data; -char buf[6 ]; +char buf[7 ];size_t len;u16 rev;int ret;drivers/iio/imu/adis16480.c static ssize_t adis16480_show_firmware_revision(struct file *file, · line 140
Quoted 8 lines
drivers/iio/imu/adis16480.c +1
-1@@ -134,7 +134,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file,if (ret <0 )return ret; - len =snprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff ); + len =scnprintf (buf,sizeof (buf),"%x.%x\n" , rev >>8 , rev &0xff );return simple_read_from_buffer (userbuf, count, ppos, buf, len); }--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html