* [PATCH] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
@ 2026-02-02 7:54 Chen Ni
2026-02-02 9:54 ` Daniel Thompson
0 siblings, 1 reply; 6+ messages in thread
From: Chen Ni @ 2026-02-02 7:54 UTC (permalink / raw)
To: lee, danielt, jingoohan1, deller, linusw
Cc: dri-devel, linux-fbdev, linux-kernel, 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")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
drivers/video/backlight/sky81452-backlight.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
index 2749231f0385..e3e5306fab84 100644
--- a/drivers/video/backlight/sky81452-backlight.c
+++ b/drivers/video/backlight/sky81452-backlight.c
@@ -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) {
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
2026-02-02 7:54 [PATCH] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt() Chen Ni
@ 2026-02-02 9:54 ` Daniel Thompson
2026-02-03 2:16 ` [PATCH v2] " Chen Ni
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Thompson @ 2026-02-02 9:54 UTC (permalink / raw)
To: Chen Ni
Cc: lee, danielt, jingoohan1, deller, linusw, dri-devel, linux-fbdev,
linux-kernel
On Mon, Feb 02, 2026 at 03:54:10PM +0800, Chen Ni wrote:
> 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")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
> drivers/video/backlight/sky81452-backlight.c | 4 ++++
> 1 file changed, 4 insertions(+)
Thanks for the fix.
Small review comment below:
> diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
> index 2749231f0385..e3e5306fab84 100644
> --- a/drivers/video/backlight/sky81452-backlight.c
> +++ b/drivers/video/backlight/sky81452-backlight.c
> @@ -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.
>
> ret = of_property_count_u32_elems(np, "led-sources");
> if (ret < 0) {
Daniel.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
2026-02-02 9:54 ` Daniel Thompson
@ 2026-02-03 2:16 ` Chen Ni
2026-03-04 10:32 ` Daniel Thompson
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Chen Ni @ 2026-02-03 2:16 UTC (permalink / raw)
To: daniel
Cc: danielt, deller, dri-devel, jingoohan1, lee, linusw, linux-fbdev,
linux-kernel, 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")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
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(+)
diff --git a/drivers/video/backlight/sky81452-backlight.c b/drivers/video/backlight/sky81452-backlight.c
index 2749231f0385..b2679b24de14 100644
--- a/drivers/video/backlight/sky81452-backlight.c
+++ b/drivers/video/backlight/sky81452-backlight.c
@@ -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) {
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
2026-02-03 2:16 ` [PATCH v2] " Chen Ni
@ 2026-03-04 10:32 ` Daniel Thompson
2026-03-06 13:31 ` Linus Walleij
2026-03-06 14:21 ` (subset) " Lee Jones
2 siblings, 0 replies; 6+ messages in thread
From: Daniel Thompson @ 2026-03-04 10:32 UTC (permalink / raw)
To: Chen Ni
Cc: daniel, deller, dri-devel, jingoohan1, lee, linusw, linux-fbdev,
linux-kernel
On Tue, Feb 03, 2026 at 10:16:25AM +0800, Chen Ni wrote:
> 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")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
Daniel.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
2026-02-03 2:16 ` [PATCH v2] " Chen Ni
2026-03-04 10:32 ` Daniel Thompson
@ 2026-03-06 13:31 ` Linus Walleij
2026-03-06 14:21 ` (subset) " Lee Jones
2 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2026-03-06 13:31 UTC (permalink / raw)
To: Chen Ni
Cc: daniel, danielt, deller, dri-devel, jingoohan1, lee, linux-fbdev,
linux-kernel
On Tue, Feb 3, 2026 at 3:17 AM Chen Ni <nichen@iscas.ac.cn> wrote:
> 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")
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: (subset) [PATCH v2] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt()
2026-02-03 2:16 ` [PATCH v2] " Chen Ni
2026-03-04 10:32 ` Daniel Thompson
2026-03-06 13:31 ` Linus Walleij
@ 2026-03-06 14:21 ` Lee Jones
2 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2026-03-06 14:21 UTC (permalink / raw)
To: daniel, Chen Ni
Cc: danielt, deller, dri-devel, jingoohan1, lee, linusw, linux-fbdev,
linux-kernel
On Tue, 03 Feb 2026 10:16:25 +0800, Chen Ni wrote:
> 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 [李琼斯]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-06 14:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 7:54 [PATCH] backlight: sky81452-backlight: Check return value of devm_gpiod_get_optional() in sky81452_bl_parse_dt() Chen Ni
2026-02-02 9:54 ` Daniel Thompson
2026-02-03 2:16 ` [PATCH v2] " Chen Ni
2026-03-04 10:32 ` Daniel Thompson
2026-03-06 13:31 ` Linus Walleij
2026-03-06 14:21 ` (subset) " Lee Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox