Skip to contentSkip to conversation

backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()

PATCH Superseded Chen Ni 5 participants 6 messages Feb 2 – Mar 6

Subsystems (2)
lore
Share & tools
lore

Chen Ni

author
#0 lore raw

PATCH 1/1 backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes e1915eec54a6 ("backlight: sky81452: Convert to GPIO descriptors")
---
 drivers/video/backlight/sky81452-backlight.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/video/backlight/sky81452-backlight.c +4 -0
index 2749231f0385..e3e5306fab84 100644
@@ -202,6 +202,10 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
 	pdata->gpiod_enable = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->gpiod_enable)) {
+		dev_err(dev, "failed to get gpio\n");
+		return ERR_CAST(pdata->gpiod_enable);
+	}
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Quoted 5 lines
Fixes e1915eec54a6 ("backlight: sky81452: Convert to GPIO descriptors")
---
 drivers/video/backlight/sky81452-backlight.c | 4 ++++
 1 file changed, 4 insertions(+)

Thanks for the fix.

Small review comment below:

drivers/video/backlight/sky81452-backlight.c static struct sky81452_bl_platform_data *sky81452_bl_parse_dt( · line 208

Quoted 12 lines
drivers/video/backlight/sky81452-backlight.c +4 -0
index 2749231f0385..e3e5306fab84 100644
@@ -202,6 +202,10 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
 	pdata->gpiod_enable = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->gpiod_enable)) {
+		dev_err(dev, "failed to get gpio\n");
+		return ERR_CAST(pdata->gpiod_enable);
+	}

Using dev_err_cast_probe() would make this change more compact and give a better error message for the user.

drivers/video/backlight/sky81452-backlight.c static struct sky81452_bl_platform_data *sky81452_bl_parse_dt( · line 211

Quoted 3 lines
drivers/video/backlight/sky81452-backlight.c +0 -0
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {

Daniel.

author
#2 lore raw

PATCH v2 1/1 backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes e1915eec54a6 ("backlight: sky81452: Convert to GPIO descriptors")

---
Changes in v2:
- Use dev_err_cast_probe() to make the code more concise.

---
 drivers/video/backlight/sky81452-backlight.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/backlight/sky81452-backlight.c +3 -0
index 2749231f0385..b2679b24de14 100644
@@ -202,6 +202,9 @@ static struct sky81452_bl_platform_data *sky81452_bl_parse_dt(
 	pdata->dpwm_mode = of_property_read_bool(np, "skyworks,dpwm-mode");
 	pdata->phase_shift = of_property_read_bool(np, "skyworks,phase-shift");
 	pdata->gpiod_enable = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
+	if (IS_ERR(pdata->gpiod_enable))
+		return dev_err_cast_probe(dev, pdata->gpiod_enable,
+					  "failed to get gpio\n");
 
 	ret = of_property_count_u32_elems(np, "led-sources");
 	if (ret < 0) {
Signature · 1 line
2.25.1
maintainer Reviewed-by on v2 1/1
#3 lore raw
Quoted 10 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes e1915eec54a6 ("backlight: sky81452: Convert to GPIO descriptors")

Daniel.

Reviewed-by on v2 1/1
#4 lore raw
In reply to Chen Ni
Quoted 10 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes e1915eec54a6 ("backlight: sky81452: Convert to GPIO descriptors")

Yours,
Linus Walleij

maintainer Applied
#5 lore raw

Re: (subset) [PATCH v2] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()

In reply to Chen Ni
Quoted 9 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in sky81452_bl_parse_dt(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

[...]

Applied, thanks!

[1/1] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()

      commit: 797cc011ae02bda26f93d25a4442d7a1a77d84df

--
Lee Jones [李琼斯]