From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163041AbdEYGqo (ORCPT ); Thu, 25 May 2017 02:46:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44114 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968496AbdEYGqk (ORCPT ); Thu, 25 May 2017 02:46:40 -0400 Date: Thu, 25 May 2017 08:46:27 +0200 From: Greg KH To: Harinath Nampally Cc: lars@metafoo.de, devel@driverdev.osuosl.org, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, pmeerw@pmeerw.net, knaack.h@gmx.de, jic23@kernel.org Subject: Re: [PATCH] staging: iio: light: Replace snprintf calls with scnprintf Message-ID: <20170525064627.GA7597@kroah.com> References: <1495668131-5239-1-git-send-email-harinath922@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1495668131-5239-1-git-send-email-harinath922@gmail.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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