Skip to contentSkip to conversation

leds: leds-wm831x-status: init chip_pdata before access

PATCH In review Shuah Khan 2 participants 4 messages Nov 22, 2022

Subsystems (2)
lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

PATCH 1/1 leds: leds-wm831x-status: init chip_pdata before access

wm831x_status_probe() accesses status from chip_pdata before initializing it. Fix it.

---
 drivers/leds/leds-wm831x-status.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/leds/leds-wm831x-status.c +4 -3
index c48b80574f02..5060c83f3b25 100644
@@ -212,7 +212,7 @@ static int wm831x_status_probe(struct platform_device *pdev)
 	struct wm831x_status_pdata pdata;
 	struct wm831x_status *drvdata;
 	struct resource *res;
-	int id = pdev->id % ARRAY_SIZE(chip_pdata->status);
+	int id;
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
@@ -229,9 +229,10 @@ static int wm831x_status_probe(struct platform_device *pdev)
 	drvdata->wm831x = wm831x;
 	drvdata->reg = res->start;
 
-	if (dev_get_platdata(wm831x->dev))
+	if (dev_get_platdata(wm831x->dev)) {
 		chip_pdata = dev_get_platdata(wm831x->dev);
-	else
+		id = pdev->id % ARRAY_SIZE(chip_pdata->status);
+	} else
 		chip_pdata = NULL;
 
 	memset(&pdata, 0, sizeof(pdata));
Signature · 1 line
2.34.1
#1 lore raw

Hi!

Quoted 4 lines

wm831x_status_probe() accesses status from chip_pdata before initializing it. Fix it.

Does it? ARRAY_SIZE() will be compile-time constant, no?

What is the bug? Did you test the code?

Best regards,
Pavel

Quoted 23 lines

+++ b/drivers/leds/leds-wm831x-status.c

drivers/leds/leds-wm831x-status.c +4 -3
@@ -212,7 +212,7 @@ static int wm831x_status_probe(struct platform_device *pdev)
 	struct wm831x_status_pdata pdata;
 	struct wm831x_status *drvdata;
 	struct resource *res;
-	int id = pdev->id % ARRAY_SIZE(chip_pdata->status);
+	int id;
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
@@ -229,9 +229,10 @@ static int wm831x_status_probe(struct platform_device *pdev)
 	drvdata->wm831x = wm831x;
 	drvdata->reg = res->start;
 
-	if (dev_get_platdata(wm831x->dev))
+	if (dev_get_platdata(wm831x->dev)) {
 		chip_pdata = dev_get_platdata(wm831x->dev);
-	else
+		id = pdev->id % ARRAY_SIZE(chip_pdata->status);
+	} else
 		chip_pdata = NULL;
 
 	memset(&pdata, 0, sizeof(pdata));
Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
author
#2 lore raw
Quoted 11 lines · Pavel Machek

Hi!

Quoted 4 lines

wm831x_status_probe() accesses status from chip_pdata before initializing it. Fix it.

Does it? ARRAY_SIZE() will be compile-time constant, no?

What is the bug? Did you test the code?

Is ARRAY_SIZE() safe when accessing the status chip_pdata->status? I wasn't sure. If so, this change isn't necessary.

thanks,
-- Shuah

#3 lore raw
Quoted 8 lines · Shuah Khan
Quoted 7 lines · Pavel Machek

Hi!

Quoted 4 lines

wm831x_status_probe() accesses status from chip_pdata before initializing it. Fix it.

Quoted 7 lines
Quoted 4 lines

Does it? ARRAY_SIZE() will be compile-time constant, no?

What is the bug? Did you test the code?

Is ARRAY_SIZE() safe when accessing the status chip_pdata->status? I wasn't sure. If so, this change isn't necessary.

I think so. Feel free to quite C standard to prove me wrong :-).

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.