Thread (4 messages) 4 messages, 4 authors, 2011-04-12

Re: [PATCH] drivers, video: Add a check for strict_strtoul()

From: Andrew Morton <akpm@linux-foundation.org>
Date: 2011-04-12 22:00:09

On Thu,  7 Apr 2011 17:06:18 +0800
Liu Yuan [off-list ref] wrote:
quoted hunk ↗ jump to hunk
From: Liu Yuan <redacted>

It should check if strict_strtoul() succeeds.This
patch fixes it.

Signed-off-by: Liu Yuan <redacted>
---
 drivers/video/backlight/adp5520_bl.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index af31197..fdef632 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -212,7 +212,9 @@ static ssize_t adp5520_bl_daylight_max_store(struct device *dev,
 {
 	struct adp5520_bl *data = dev_get_drvdata(dev);
 
-	strict_strtoul(buf, 10, &data->cached_daylight_max);
+	if (strict_strtoul(buf, 10, &data->cached_daylight_max) < 0)
+		return -EINVAL;
+
 	return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX);
 }
It is better to propagate strict_strtoul()'s errno, rather than
overriding it:
--- a/drivers/video/backlight/adp5520_bl.c~drivers-video-backlight-adp5520_blc-check-strict_strtoul-return-value-fix
+++ a/drivers/video/backlight/adp5520_bl.c
@@ -211,9 +211,11 @@ static ssize_t adp5520_bl_daylight_max_s
 			const char *buf, size_t count)
 {
 	struct adp5520_bl *data = dev_get_drvdata(dev);
+	int ret;
 
-	if (strict_strtoul(buf, 10, &data->cached_daylight_max) < 0)
-		return -EINVAL;
+	ret = strict_strtoul(buf, 10, &data->cached_daylight_max);
+	if (ret < 0)
+		return ret;
 
 	return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX);
 }
_
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help