Skip to content

Commit

Permalink
iio:imu: adis16480: show_firmware() buffer too small
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-By: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Dan Carpenter authored and Jonathan Cameron committed Nov 30, 2012
1 parent 1266013 commit afc3a57
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/iio/imu/adis16480.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit afc3a57

Please sign in to comment.