Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: lp55xx: fix the sysfs read operation

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>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

authored by

Kim, Milo and committed by
Bryan Wu
24d32128 313bf0b1

+4 -3
+2 -1
drivers/leds/leds-lp5521.c
··· 360 360 mutex_lock(&chip->lock); 361 361 ret = lp5521_run_selftest(chip, buf); 362 362 mutex_unlock(&chip->lock); 363 - return sprintf(buf, "%s\n", ret ? "FAIL" : "OK"); 363 + 364 + return scnprintf(buf, PAGE_SIZE, "%s\n", ret ? "FAIL" : "OK"); 364 365 } 365 366 366 367 /* device attributes */
+2 -2
drivers/leds/leds-lp55xx-common.c
··· 80 80 { 81 81 struct lp55xx_led *led = dev_to_lp55xx_led(dev); 82 82 83 - return sprintf(buf, "%d\n", led->led_current); 83 + return scnprintf(buf, PAGE_SIZE, "%d\n", led->led_current); 84 84 } 85 85 86 86 static ssize_t lp55xx_store_current(struct device *dev, ··· 113 113 { 114 114 struct lp55xx_led *led = dev_to_lp55xx_led(dev); 115 115 116 - return sprintf(buf, "%d\n", led->max_current); 116 + return scnprintf(buf, PAGE_SIZE, "%d\n", led->max_current); 117 117 } 118 118 119 119 static DEVICE_ATTR(led_current, S_IRUGO | S_IWUSR, lp55xx_show_current,