backlight: lm3639: Unconditionally call led_classdev_unregister
Subsystems (2)
PATCH 1/1 backlight: lm3639: Unconditionally call led_classdev_unregister
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]
if (&pchip->cdev_torch)
~~ ~~~~~~~^~~~~~~~~~
drivers/video/backlight/lm3639_bl.c:405:14: warning: address of
'pchip->cdev_flash' will always evaluate to 'true'
[-Wpointer-bool-conversion]
if (&pchip->cdev_flash)
~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
These statements have been present since 2012, introduced by commit 0f59858d5119 ("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.
---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/video/backlight/lm3639_bl.c +2 -4
@@ -400,10 +400,8 @@ static int lm3639_remove(struct i2c_client *client)regmap_write (pchip->regmap,REG_ENABLE ,0x00 ); -if (&pchip->cdev_torch) -led_classdev_unregister (&pchip->cdev_torch); -if (&pchip->cdev_flash) -led_classdev_unregister (&pchip->cdev_flash); +led_classdev_unregister (&pchip->cdev_torch); +led_classdev_unregister (&pchip->cdev_flash);if (pchip->bled)device_remove_file (&(pchip->bled->dev), &dev_attr_bled_mode);return 0 ;
Signature · 1 line
2.19.0
Quoted 41 lines · Nathan Chancellor
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]if (&pchip->cdev_torch) ~~ ~~~~~~~^~~~~~~~~~ drivers/video/backlight/lm3639_bl.c:405:14: warning: address of 'pchip->cdev_flash' will always evaluate to 'true' [-Wpointer-bool-conversion] if (&pchip->cdev_flash) ~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
These statements have been present since 2012, introduced by commit
0f59858d5119("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.Signed-off-by Nathan Chancellor <[email protected]>---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/video/backlight/lm3639_bl.c +0
-0
drivers/video/backlight/lm3639_bl.c static int lm3639_remove(struct i2c_client *client) · line 404
Quoted 9 lines
drivers/video/backlight/lm3639_bl.c +2
-4@@ -400,10 +400,8 @@ static int lm3639_remove(struct i2c_client *client)regmap_write (pchip->regmap,REG_ENABLE ,0x00 ); -if (&pchip->cdev_torch) -led_classdev_unregister (&pchip->cdev_torch); -if (&pchip->cdev_flash) -led_classdev_unregister (&pchip->cdev_flash); +led_classdev_unregister (&pchip->cdev_torch); +led_classdev_unregister (&pchip->cdev_flash);
led_classdev_unregister() requires that its arg is non-null (as it dereferences it without any kind of check). It's not clear that i2c_get_clientdata() can never return a null pointer, so I think all references to pchip in this function should instead be guarded with a null check. Would you mind making that change and sending a v2?
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +0
-1if (pchip->bled)device_remove_file (&(pchip->bled->dev), &dev_attr_bled_mode);return 0 ; --2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 46 lines · Nick Desaulniers
Quoted 44 lines · Nathan Chancellor
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]if (&pchip->cdev_torch) ~~ ~~~~~~~^~~~~~~~~~ drivers/video/backlight/lm3639_bl.c:405:14: warning: address of 'pchip->cdev_flash' will always evaluate to 'true' [-Wpointer-bool-conversion] if (&pchip->cdev_flash) ~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
These statements have been present since 2012, introduced by commit
0f59858d5119("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.Signed-off-by Nathan Chancellor <[email protected]>---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/video/backlight/lm3639_bl.c +0
-0@@ -400,10 +400,8 @@ static int lm3639_remove(struct i2c_client *client)regmap_write (pchip->regmap,REG_ENABLE ,0x00 );
Quoted 13 lines
drivers/video/backlight/lm3639_bl.c static int lm3639_remove(struct i2c_client *client) · line 404
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +2
-4-if (&pchip->cdev_torch) -led_classdev_unregister (&pchip->cdev_torch); -if (&pchip->cdev_flash) -led_classdev_unregister (&pchip->cdev_flash); +led_classdev_unregister (&pchip->cdev_torch); +led_classdev_unregister (&pchip->cdev_flash);
led_classdev_unregister()requires that its arg is non-null (as it dereferences it without any kind of check). It's not clear thati2c_get_clientdata()can never return a null pointer, so I think all references to pchip in this function should instead be guarded with a null check. Would you mind making that change and sending a v2?
Hi Nick,
I did a quick grep throughout the tree and I didn't see any place where there were null checks for i2c_get_clientdata, leading me to believe that such a check isn't necessary although I am nowhere close to an expert into this stuff. I'm not sure I follow the rest of the request though, where should the check be? Before regmap_write?
Furthermore, the probe function seems to make sure all of these get initialized properly, doesn't remove imply that probe was successful?
Thank you for the comment and review!
Nathan
Quoted 11 lines
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +0
-1if (pchip->bled)device_remove_file (&(pchip->bled->dev), &dev_attr_bled_mode);return 0 ; --2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 62 lines · Nathan Chancellor
Quoted 46 lines · Nick Desaulniers
Quoted 44 lines · Nathan Chancellor
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]if (&pchip->cdev_torch) ~~ ~~~~~~~^~~~~~~~~~ drivers/video/backlight/lm3639_bl.c:405:14: warning: address of 'pchip->cdev_flash' will always evaluate to 'true' [-Wpointer-bool-conversion] if (&pchip->cdev_flash) ~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
These statements have been present since 2012, introduced by commit
0f59858d5119("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.Signed-off-by Nathan Chancellor <[email protected]>---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/video/backlight/lm3639_bl.c +0
-0@@ -400,10 +400,8 @@ static int lm3639_remove(struct i2c_client *client)regmap_write (pchip->regmap,REG_ENABLE ,0x00 );Quoted 13 lines
drivers/video/backlight/lm3639_bl.c static int lm3639_remove(struct i2c_client *client) · line 404
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +2
-4-if (&pchip->cdev_torch) -led_classdev_unregister (&pchip->cdev_torch); -if (&pchip->cdev_flash) -led_classdev_unregister (&pchip->cdev_flash); +led_classdev_unregister (&pchip->cdev_torch); +led_classdev_unregister (&pchip->cdev_flash);
led_classdev_unregister()requires that its arg is non-null (as it dereferences it without any kind of check). It's not clear thati2c_get_clientdata()can never return a null pointer, so I think all references to pchip in this function should instead be guarded with a null check. Would you mind making that change and sending a v2?
Quoted 6 lines
Hi Nick,
I did a quick grep throughout the tree and I didn't see any place where there were null checks for
i2c_get_clientdata, leading me to believe that such a check isn't necessary although I am nowhere close to an expert into this stuff.
This seems to be the case. We should start using __attribute__((returns_nonnull)) (gated on gcc 5+).
I *think* that the device's driver_data is actually set in drivers/video/backlight/backlight.c. Looks like CONFIG_BACKLIGHT_LM3639 depends on CONFIG_BACKLIGHT_CLASS_DEVICE so I feel more confident in your patch.
I would still prefer the maintainers to review though.
Quoted 20 lines
I'm not sure I follow the rest of the request though, where should the check be? Before
regmap_write?Furthermore, the probe function seems to make sure all of these get initialized properly, doesn't remove imply that probe was successful?
Thank you for the comment and review!
NathanQuoted 11 lines
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +0
-1if (pchip->bled)device_remove_file (&(pchip->bled->dev), &dev_attr_bled_mode);return 0 ; --2.19.0
--
Thanks,
~Nick Desaulniers
Signature · 2 lines
Thanks, ~Nick Desaulniers
Daniel Thompson
Reviewed-byQuoted 22 lines · Nick Desaulniers
Quoted 20 lines · Nathan Chancellor
Quoted 18 lines · Nick Desaulniers
Quoted 16 lines · Nathan Chancellor
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]if (&pchip->cdev_torch) ~~ ~~~~~~~^~~~~~~~~~ drivers/video/backlight/lm3639_bl.c:405:14: warning: address of 'pchip->cdev_flash' will always evaluate to 'true' [-Wpointer-bool-conversion] if (&pchip->cdev_flash) ~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
These statements have been present since 2012, introduced by commit
0f59858d5119("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.
Based on conversation below...
Quoted 41 lines
Quoted 34 lines
Quoted 20 lines
Quoted 20 lines
---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/video/backlight/lm3639_bl.c +0
-0@@ -400,10 +400,8 @@ static int lm3639_remove(struct i2c_client *client)regmap_write (pchip->regmap,REG_ENABLE ,0x00 );Quoted 13 lines
drivers/video/backlight/lm3639_bl.c static int lm3639_remove(struct i2c_client *client) · line 404
Quoted 6 lines
drivers/video/backlight/lm3639_bl.c +2
-4-if (&pchip->cdev_torch) -led_classdev_unregister (&pchip->cdev_torch); -if (&pchip->cdev_flash) -led_classdev_unregister (&pchip->cdev_flash); +led_classdev_unregister (&pchip->cdev_torch); +led_classdev_unregister (&pchip->cdev_flash);
led_classdev_unregister()requires that its arg is non-null (as it dereferences it without any kind of check). It's not clear thati2c_get_clientdata()can never return a null pointer, so I think all references to pchip in this function should instead be guarded with a null check. Would you mind making that change and sending a v2?Quoted 6 lines
Hi Nick,
I did a quick grep throughout the tree and I didn't see any place where there were null checks for
i2c_get_clientdata, leading me to believe that such a check isn't necessary although I am nowhere close to an expert into this stuff.
Quoted 7 lines
This seems to be the case. We should start using __attribute__((returns_nonnull)) (gated on gcc 5+).
I *think* that the device'sdriver_datais actually set indrivers/video/backlight/backlight.c. Looks likeCONFIG_BACKLIGHT_LM3639depends onCONFIG_BACKLIGHT_CLASS_DEVICEso I feel more confident in your patch.
I would still prefer the maintainers to review though.
AFAICT it is impossible for the probe function to complete successfully without having called i2c_set_clientdata() and therefore it is impossible for pchip to be NULL in the remove function.
Not sure it is possible to use return_nonnull though. It is not that i2c_get_clientdata() can *never* return non-NULL, it is that in *this* case (which is actually a fairly common one) it can never return non-NULL.
Daniel.
Lee Jones
AppliedQuoted 30 lines · Nathan Chancellor
Clang warns that the address of a pointer will always evaluated as true in a boolean context.
drivers/video/backlight/lm3639_bl.c:403:14: warning: address of 'pchip->cdev_torch' will always evaluate to 'true' [-Wpointer-bool-conversion]if (&pchip->cdev_torch) ~~ ~~~~~~~^~~~~~~~~~ drivers/video/backlight/lm3639_bl.c:405:14: warning: address of 'pchip->cdev_flash' will always evaluate to 'true' [-Wpointer-bool-conversion] if (&pchip->cdev_flash) ~~ ~~~~~~~^~~~~~~~~~2 warnings generated.
These statements have been present since 2012, introduced by commit
0f59858d5119("backlight: add new lm3639 backlight driver"). Given that they have been called unconditionally since then presumably without any issues, removing the always true if statements to fix the warnings without any real world changes.Signed-off-by Nathan Chancellor <[email protected]>---
Alternatively, it's possible the address wasn't supposed to be taken or the dev in these structs should be checked instead. I don't have this hardware to make that call so I would appreciate some review and opinions on what was intended here.
Quoted 4 lines
Thanks!
drivers/video/backlight/lm3639_bl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog