Re: [PATCH] staging: iio: light: Replace snprintf calls with scnprintf

From: Greg KH
Date: Thu May 25 2017 - 02:47:10 EST


On Wed, May 24, 2017 at 07:22:11PM -0400, Harinath Nampally wrote:
> This patch fixes the miscoded use of return value of snprintf
> by using the scnprintf function which returns the length of actual
> string created in the buffer.
>
> Signed-off-by: Harinath Nampally <harinath922@xxxxxxxxx>
> ---
> drivers/staging/iio/light/tsl2x7x.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c
> index 1467199..6908bc1 100644
> --- a/drivers/staging/iio/light/tsl2x7x.c
> +++ b/drivers/staging/iio/light/tsl2x7x.c
> @@ -921,7 +921,7 @@ static ssize_t power_state_show(struct device *dev,
> {
> struct tsl2X7X_chip *chip = iio_priv(dev_to_iio_dev(dev));
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", chip->tsl2x7x_chip_status);
> + return scnprintf(buf, PAGE_SIZE, "%d\n", chip->tsl2x7x_chip_status);

It should just be sprintf(), no need for testing for PAGE_SIZE for sysfs
attributes, we "know" an integer will not overflow that buffer.

thanks,

greg k-h