Re: [PATCH] ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer

From: Mark Brown

Date: Mon Apr 27 2026 - 19:25:11 EST


On Mon, Apr 27, 2026 at 10:29:46AM +0800, wangdich9700@xxxxxxx wrote:
> From: wangdicheng <wangdicheng@xxxxxxxxxx>
>
> 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: signature.asc
Description: PGP signature