Skip to contentSkip to conversation

video: backlight: adp5520: fix compiler warning in adp5520_show

PATCH Superseded Devendra Naga 3 participants 5 messages Mar 8, 2013 – Mar 11, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 video: backlight: adp5520: fix compiler warning in adp5520_show

while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8))

found the following warning

drivers/video/backlight/adp5520_bl.c: In function ‘adp5520_show’:
drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ‘error’ set but not used [-Wunused-but-set-variable]

fixed by removing the variable

Cc Jingoo Han <[email protected]>
Cc Michael Hennerich <[email protected]>
Cc Richard Purdie <[email protected]>
---
 drivers/video/backlight/adp5520_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/adp5520_bl.c +1 -2
index a1e41d4..9f8b20b 100644
@@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl)
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {
 	struct adp5520_bl *data = dev_get_drvdata(dev);
-	int error;
 	uint8_t reg_val;
 
 	mutex_lock(&data->lock);
-	error = adp5520_read(data->master, reg, &reg_val);
+	adp5520_read(data->master, reg, &reg_val);
 	mutex_unlock(&data->lock);
 
 	return sprintf(buf, "%u\n", reg_val);
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 16 lines · On Fri, 8 Mar 2013 14:31:07 -0500 Devendra Naga <[email protected]>…

while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8))

found the following warning

drivers/video/backlight/adp5520_bl.c: In function ___adp5520_show___:
drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ___error___ set but not used [-Wunused-but-set-variable]

fixed by removing the variable

...

drivers/video/backlight/adp5520_bl.c +0 -0
@@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl)
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {

drivers/video/backlight/adp5520_bl.c static int adp5520_bl_setup(struct backlight_device *bl) · line 152

Quoted 10 lines
drivers/video/backlight/adp5520_bl.c +1 -2
 	struct adp5520_bl *data = dev_get_drvdata(dev);
-	int error;
 	uint8_t reg_val;
 
 	mutex_lock(&data->lock);
-	error = adp5520_read(data->master, reg, &reg_val);
+	adp5520_read(data->master, reg, &reg_val);
 	mutex_unlock(&data->lock);
 
 	return sprintf(buf, "%u\n", reg_val);

We shouldn't just ignore the error; with the code as it stands, a adp5520_read() failure will result in the kernel displaying uninitialised garbage.

So it would be better to propagate the adp5520_read() return value back to the caller if it's negative.

(This assumes that the i2c layer returns a sane return value - if it does, that would make i2c pretty unique :( We could get paranoid and return a hard-wired -EIO, but it would be bad of us to overwrite things like -ENOMEM).

So I'd suggest this:

drivers/video/backlight/adp5520_bl.c renamed from drivers/video/backlight/adp5520_bl.c~video-backlight-adp5520-fix-compiler-warning-in-adp5520_show +4 -2
@@ -143,13 +143,15 @@ static int adp5520_bl_setup(struct backl
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {
 	struct adp5520_bl *data = dev_get_drvdata(dev);
-	int error;
+	int ret;
 	uint8_t reg_val;
 
 	mutex_lock(&data->lock);
-	error = adp5520_read(data->master, reg, &reg_val);
+	ret = adp5520_read(data->master, reg, &reg_val);
 	mutex_unlock(&data->lock);
 
+	if (ret < 0)
+		return ret;
 	return sprintf(buf, "%u\n", reg_val);
 }
 

_

#2 lore raw
In reply to Devendra Naga
Quoted 25 lines · Devendra Naga

while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8))

found the following warning

drivers/video/backlight/adp5520_bl.c: In function ‘adp5520_show’:
drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ‘error’ set but not used [-Wunused-but- set-variable]

fixed by removing the variable

Cc Jingoo Han <[email protected]>
Cc Michael Hennerich <[email protected]>
Cc Richard Purdie <[email protected]>
---
 drivers/video/backlight/adp5520_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/adp5520_bl.c +0 -0
index a1e41d4..9f8b20b 100644

drivers/video/backlight/adp5520_bl.c static int adp5520_bl_setup(struct backlight_device *bl) · line 150

Quoted 10 lines
drivers/video/backlight/adp5520_bl.c +1 -2
@@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl)
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {
 	struct adp5520_bl *data = dev_get_drvdata(dev);
-	int error;
 	uint8_t reg_val;
 
 	mutex_lock(&data->lock);
-	error = adp5520_read(data->master, reg, &reg_val);
+	adp5520_read(data->master, reg, &reg_val);
 	mutex_unlock(&data->lock);

Hi Devendra Naga,

I also agree with Andrew Morton's opinion.
It would be better to check return value from I2C read/write functions.

Best regards,
Jingoo Han

Quoted 4 lines
drivers/video/backlight/adp5520_bl.c +0 -1
 	return sprintf(buf, "%u\n", reg_val);
--

1.8.1.2

#3 lore raw
In reply to Devendra Naga
Quoted 54 lines · Andrew Morton
Quoted 16 lines · On Fri, 8 Mar 2013 14:31:07 -0500 Devendra Naga <[email protected]>…

while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8))

found the following warning

drivers/video/backlight/adp5520_bl.c: In function ___adp5520_show___:
drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ___error___ set but not used [-Wunused-but-set-variable]

fixed by removing the variable

...

drivers/video/backlight/adp5520_bl.c +0 -0
@@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl)
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {

drivers/video/backlight/adp5520_bl.c static int adp5520_bl_setup(struct backlight_device *bl) · line 152

Quoted 10 lines
drivers/video/backlight/adp5520_bl.c +1 -2
      struct adp5520_bl *data = dev_get_drvdata(dev);
-     int error;
      uint8_t reg_val;
 
      mutex_lock(&data->lock);
-     error = adp5520_read(data->master, reg, &reg_val);
+     adp5520_read(data->master, reg, &reg_val);
      mutex_unlock(&data->lock);
 
      return sprintf(buf, "%u\n", reg_val);

We shouldn't just ignore the error; with the code as it stands, a adp5520_read() failure will result in the kernel displaying uninitialised garbage.

So it would be better to propagate the adp5520_read() return value back to the caller if it's negative.

(This assumes that the i2c layer returns a sane return value - if it does, that would make i2c pretty unique :( We could get paranoid and return a hard-wired -EIO, but it would be bad of us to overwrite things like -ENOMEM).

So I'd suggest this:

drivers/video/backlight/adp5520_bl.c renamed from drivers/video/backlight/adp5520_bl.c~video-backlight-adp5520-fix-compiler-warning-in-adp5520_show +1 -1
@@ -143,13 +143,15 @@ static int adp5520_bl_setup(struct backl
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {
        struct adp5520_bl *data = dev_get_drvdata(dev);
-       int error;
+       int ret;
        uint8_t reg_val;
 

drivers/video/backlight/adp5520_bl.c static int adp5520_bl_setup(struct backl · line 157

Quoted 10 lines
drivers/video/backlight/adp5520_bl.c renamed from drivers/video/backlight/adp5520_bl.c~video-backlight-adp5520-fix-compiler-warning-in-adp5520_show +3 -1
        mutex_lock(&data->lock);
-       error = adp5520_read(data->master, reg, &reg_val);
+       ret = adp5520_read(data->master, reg, &reg_val);
        mutex_unlock(&data->lock);
 
+       if (ret < 0)
+               return ret;
        return sprintf(buf, "%u\n", reg_val);
 }
 

Thanks for the suggestion, i will do the same and i will send you a patch sooner.

or you can merge your change with my Acked By too :).

Quoted 2 lines

_

#4 lore raw
In reply to Devendra Naga
Quoted 39 lines · Jingoo Han
Quoted 25 lines · Devendra Naga

while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8))

found the following warning

drivers/video/backlight/adp5520_bl.c: In function ‘adp5520_show’:
drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ‘error’ set but not used [-Wunused-but- set-variable]

fixed by removing the variable

Cc Jingoo Han <[email protected]>
Cc Michael Hennerich <[email protected]>
Cc Richard Purdie <[email protected]>
---
 drivers/video/backlight/adp5520_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/adp5520_bl.c +0 -0
index a1e41d4..9f8b20b 100644

drivers/video/backlight/adp5520_bl.c static int adp5520_bl_setup(struct backlight_device *bl) · line 150

Quoted 10 lines
drivers/video/backlight/adp5520_bl.c +1 -2
@@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl)
 static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
 {
      struct adp5520_bl *data = dev_get_drvdata(dev);
-     int error;
      uint8_t reg_val;
 
      mutex_lock(&data->lock);
-     error = adp5520_read(data->master, reg, &reg_val);
+     adp5520_read(data->master, reg, &reg_val);
      mutex_unlock(&data->lock);

Hi Devendra Naga,

Quoted 3 lines

I also agree with Andrew Morton's opinion.
It would be better to check return value from I2C read/write functions.

thanks, i will do and send a patch sooner or Andrew can merge his patch with my Acked By.

Quoted 8 lines

Best regards,
Jingoo Han

Quoted 4 lines
drivers/video/backlight/adp5520_bl.c +0 -1
      return sprintf(buf, "%u\n", reg_val);
--

1.8.1.2