* [PATCH] ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer
@ 2026-04-27 2:29 wangdich9700
2026-04-27 23:24 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: wangdich9700 @ 2026-04-27 2:29 UTC (permalink / raw)
To: broonie, tiwai, wangdich9700; +Cc: linux-sound, linux-kernel, wangdicheng
From: wangdicheng <wangdicheng@kylinos.cn>
In aw88395_i2c_probe(), if `devm_gpiod_get_optional()` fails, it returns
an ERR_PTR() error pointer. The current code only prints a message and
continues execution, leaving `aw88395->reset_gpio` as an invalid pointer.
Later, in `aw88395_hw_reset()`, this invalid pointer is passed to
`gpiod_set_value_cansleep()`, which dereferences it and causes a kernel
panic.
For optional GPIOs, `devm_gpiod_get_optional()` returns NULL if the GPIO
is not defined in the DT, which is safe. If it returns an ERR_PTR, it
means a real error occurred (e.g., -EPROBE_DEFER) and the probe must be
aborted. Fix this by returning the error code when IS_ERR() is true.
Signed-off-by: wangdicheng <wangdicheng@kylinos.cn>
---
sound/soc/codecs/aw88395/aw88395.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/aw88395/aw88395.c b/sound/soc/codecs/aw88395/aw88395.c
index 3602b5b9f7d7..e60cd7e239cc 100644
--- a/sound/soc/codecs/aw88395/aw88395.c
+++ b/sound/soc/codecs/aw88395/aw88395.c
@@ -523,7 +523,7 @@ static int aw88395_i2c_probe(struct i2c_client *i2c)
aw88395->reset_gpio = devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(aw88395->reset_gpio))
- dev_info(&i2c->dev, "reset gpio not defined\n");
+ return PTR_ERR(aw88395->reset_gpio);
/* hardware reset */
aw88395_hw_reset(aw88395);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer
2026-04-27 2:29 [PATCH] ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer wangdich9700
@ 2026-04-27 23:24 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-04-27 23:24 UTC (permalink / raw)
To: wangdich9700; +Cc: tiwai, linux-sound, linux-kernel, wangdicheng
[-- Attachment #1: Type: text/plain, Size: 980 bytes --]
On Mon, Apr 27, 2026 at 10:29:46AM +0800, wangdich9700@163.com wrote:
> From: wangdicheng <wangdicheng@kylinos.cn>
>
> In aw88395_i2c_probe(), if `devm_gpiod_get_optional()` fails, it returns
> an ERR_PTR() error pointer. The current code only prints a message and
> continues execution, leaving `aw88395->reset_gpio` as an invalid pointer.
>
> Later, in `aw88395_hw_reset()`, this invalid pointer is passed to
> `gpiod_set_value_cansleep()`, which dereferences it and causes a kernel
> panic.
>
> For optional GPIOs, `devm_gpiod_get_optional()` returns NULL if the GPIO
> is not defined in the DT, which is safe. If it returns an ERR_PTR, it
> means a real error occurred (e.g., -EPROBE_DEFER) and the probe must be
> aborted. Fix this by returning the error code when IS_ERR() is true.
This looks OK in so far as it goes but there's other bugs in the driver,
at least printing a dev_err() if the GPIO is missing which doesn't
exactly sound optonal to me.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-27 23:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-27 2:29 [PATCH] ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer wangdich9700
2026-04-27 23:24 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox