diff mbox series

backlight: mp3309c: fix signedness bug in mp3309c_parse_fwnode()

Message ID 74347f67-360d-4513-8939-595e3c4764fa@moroto.mountain (mailing list archive)
State New, archived
Headers show
Series backlight: mp3309c: fix signedness bug in mp3309c_parse_fwnode() | expand

Commit Message

Dan Carpenter March 16, 2024, 9:45 a.m. UTC
The "num_levels" variable is used to store error codes from
device_property_count_u32() so it needs to be signed.  This doesn't
cause an issue at runtime because devm_kcalloc() won't allocate negative
sizes.  However, it's still worth fixing.

Fixes: b54c828bdba9 ("backlight: mp3309c: Make use of device properties")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/video/backlight/mp3309c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko March 18, 2024, 10:20 a.m. UTC | #1
On Sat, Mar 16, 2024 at 12:45:27PM +0300, Dan Carpenter wrote:
> The "num_levels" variable is used to store error codes from
> device_property_count_u32() so it needs to be signed.  This doesn't
> cause an issue at runtime because devm_kcalloc() won't allocate negative
> sizes.  However, it's still worth fixing.

Agree.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Daniel Thompson March 18, 2024, 10:57 a.m. UTC | #2
On Sat, Mar 16, 2024 at 12:45:27PM +0300, Dan Carpenter wrote:
> The "num_levels" variable is used to store error codes from
> device_property_count_u32() so it needs to be signed.  This doesn't
> cause an issue at runtime because devm_kcalloc() won't allocate negative
> sizes.  However, it's still worth fixing.
>
> Fixes: b54c828bdba9 ("backlight: mp3309c: Make use of device properties")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.
Flavio Suligoi March 18, 2024, 11:18 a.m. UTC | #3
Hi Dan,

> The "num_levels" variable is used to store error codes from
> device_property_count_u32() so it needs to be signed.  This doesn't cause an
> issue at runtime because devm_kcalloc() won't allocate negative sizes.
> However, it's still worth fixing.
> 
> Fixes: b54c828bdba9 ("backlight: mp3309c: Make use of device properties")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

I've just tested on my board with the mp3309c chip, all is ok.
Thanks!

Tested-by: Flavio Suligoi <f.suligoi@asem.it>
Lee Jones March 21, 2024, 6:14 p.m. UTC | #4
On Sat, 16 Mar 2024 12:45:27 +0300, Dan Carpenter wrote:
> The "num_levels" variable is used to store error codes from
> device_property_count_u32() so it needs to be signed.  This doesn't
> cause an issue at runtime because devm_kcalloc() won't allocate negative
> sizes.  However, it's still worth fixing.
> 
> 

Applied, thanks!

[1/1] backlight: mp3309c: fix signedness bug in mp3309c_parse_fwnode()
      commit: 84a053e072c8aacff8074ac5d6f7a4e7ff745209

--
Lee Jones [李琼斯]
diff mbox series

Patch

diff --git a/drivers/video/backlight/mp3309c.c b/drivers/video/backlight/mp3309c.c
index c80a1481e742..4e98e60417d2 100644
--- a/drivers/video/backlight/mp3309c.c
+++ b/drivers/video/backlight/mp3309c.c
@@ -205,8 +205,9 @@  static int mp3309c_parse_fwnode(struct mp3309c_chip *chip,
 				struct mp3309c_platform_data *pdata)
 {
 	int ret, i;
-	unsigned int num_levels, tmp_value;
+	unsigned int tmp_value;
 	struct device *dev = chip->dev;
+	int num_levels;
 
 	if (!dev_fwnode(dev))
 		return dev_err_probe(dev, -ENODEV, "failed to get firmware node\n");