linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: lp55xx: fix the sysfs read operation
@ 2013-03-15  0:19 Kim, Milo
  2013-03-15  0:39 ` Bryan Wu
  0 siblings, 1 reply; 2+ messages in thread
From: Kim, Milo @ 2013-03-15  0:19 UTC (permalink / raw)
  To: Bryan Wu; +Cc: linux-leds, linux-kernel

According to a sysfs documentation(Documentation/filesystem/sysfs.txt),
scnprintf() should be used in a read operation method.
It guarantees safe buffer size(PAGE_SIZE) which is allocated by the sysfs.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
---
 drivers/leds/leds-lp5521.c        |    3 ++-
 drivers/leds/leds-lp55xx-common.c |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 1001347..7f10304 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -360,7 +360,8 @@ static ssize_t lp5521_selftest(struct device *dev,
 	mutex_lock(&chip->lock);
 	ret = lp5521_run_selftest(chip, buf);
 	mutex_unlock(&chip->lock);
-	return sprintf(buf, "%s\n", ret ? "FAIL" : "OK");
+
+	return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK");
 }
 
 /* device attributes */
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 8a388a4..715a602 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -80,7 +80,7 @@ static ssize_t lp55xx_show_current(struct device *dev,
 {
 	struct lp55xx_led *led = dev_to_lp55xx_led(dev);
 
-	return sprintf(buf, "%d\n", led->led_current);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current);
 }
 
 static ssize_t lp55xx_store_current(struct device *dev,
@@ -113,7 +113,7 @@ static ssize_t lp55xx_show_max_current(struct device *dev,
 {
 	struct lp55xx_led *led = dev_to_lp55xx_led(dev);
 
-	return sprintf(buf, "%d\n", led->max_current);
+	return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current);
 }
 
 static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
-- 
1.7.9.5


Best Regards,
Milo



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] leds: lp55xx: fix the sysfs read operation
  2013-03-15  0:19 [PATCH] leds: lp55xx: fix the sysfs read operation Kim, Milo
@ 2013-03-15  0:39 ` Bryan Wu
  0 siblings, 0 replies; 2+ messages in thread
From: Bryan Wu @ 2013-03-15  0:39 UTC (permalink / raw)
  To: Kim, Milo; +Cc: linux-leds, linux-kernel

On Thu, Mar 14, 2013 at 5:19 PM, Kim, Milo <Milo.Kim@ti.com> wrote:
> According to a sysfs documentation(Documentation/filesystem/sysfs.txt),
> scnprintf() should be used in a read operation method.
> It guarantees safe buffer size(PAGE_SIZE) which is allocated by the sysfs.
>

Oh, I missed that. Great, I merged it.
Thanks,
-Bryan

> Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
> ---
>  drivers/leds/leds-lp5521.c        |    3 ++-
>  drivers/leds/leds-lp55xx-common.c |    4 ++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
> index 1001347..7f10304 100644
> --- a/drivers/leds/leds-lp5521.c
> +++ b/drivers/leds/leds-lp5521.c
> @@ -360,7 +360,8 @@ static ssize_t lp5521_selftest(struct device *dev,
>         mutex_lock(&chip->lock);
>         ret = lp5521_run_selftest(chip, buf);
>         mutex_unlock(&chip->lock);
> -       return sprintf(buf, "%s\n", ret ? "FAIL" : "OK");
> +
> +       return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK");
>  }
>
>  /* device attributes */
> diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
> index 8a388a4..715a602 100644
> --- a/drivers/leds/leds-lp55xx-common.c
> +++ b/drivers/leds/leds-lp55xx-common.c
> @@ -80,7 +80,7 @@ static ssize_t lp55xx_show_current(struct device *dev,
>  {
>         struct lp55xx_led *led = dev_to_lp55xx_led(dev);
>
> -       return sprintf(buf, "%d\n", led->led_current);
> +       return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current);
>  }
>
>  static ssize_t lp55xx_store_current(struct device *dev,
> @@ -113,7 +113,7 @@ static ssize_t lp55xx_show_max_current(struct device *dev,
>  {
>         struct lp55xx_led *led = dev_to_lp55xx_led(dev);
>
> -       return sprintf(buf, "%d\n", led->max_current);
> +       return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current);
>  }
>
>  static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,
> --
> 1.7.9.5
>
>
> Best Regards,
> Milo
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-15  0:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-15  0:19 [PATCH] leds: lp55xx: fix the sysfs read operation Kim, Milo
2013-03-15  0:39 ` Bryan Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).