Skip to content

Commit

Permalink
remoteproc: snprintf() can return more than was printed
Browse files Browse the repository at this point in the history
snprintf() returns the number of characters which would have been
printed if there were enough space.  For example, on the first print if
we fill up the 28 character string then it would return a number more
than 30.  Use scnprintf() instead because that returns the actual number
of characters printed.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
  • Loading branch information
Dan Carpenter authored and Ohad Ben-Cohen committed Sep 30, 2012
1 parent ec4d02d commit ae768d5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/remoteproc/remoteproc_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static ssize_t rproc_state_read(struct file *filp, char __user *userbuf,

state = rproc->state > RPROC_LAST ? RPROC_LAST : rproc->state;

i = snprintf(buf, 30, "%.28s (%d)\n", rproc_state_string[state],
i = scnprintf(buf, 30, "%.28s (%d)\n", rproc_state_string[state],
rproc->state);

return simple_read_from_buffer(userbuf, count, ppos, buf, i);
Expand All @@ -103,7 +103,7 @@ static ssize_t rproc_name_read(struct file *filp, char __user *userbuf,
char buf[100];
int i;

i = snprintf(buf, sizeof(buf), "%.98s\n", rproc->name);
i = scnprintf(buf, sizeof(buf), "%.98s\n", rproc->name);

return simple_read_from_buffer(userbuf, count, ppos, buf, i);
}
Expand Down

0 comments on commit ae768d5

Please sign in to comment.