Skip to content

Commit 241ee17

Browse files
wangdichengbroonie
authored andcommitted
ASoC: aw88395: Fix kernel panic caused by invalid GPIO error pointer
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. Also, since the GPIO is optional, remove the dev_err() log in aw88395_hw_reset() when the GPIO is missing to match the optional semantics. This also fixes a potential NULL pointer dereference as aw_pa is not initialized when aw88395_hw_reset() is called. Signed-off-by: wangdicheng <wangdicheng@kylinos.cn> Link: https://patch.msgid.link/20260428023408.46420-1-wangdich9700@163.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8ed3311 commit 241ee17

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

sound/soc/codecs/aw88395/aw88395.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,6 @@ static void aw88395_hw_reset(struct aw88395 *aw88395)
456456
usleep_range(AW88395_1000_US, AW88395_1000_US + 10);
457457
gpiod_set_value_cansleep(aw88395->reset_gpio, 1);
458458
usleep_range(AW88395_1000_US, AW88395_1000_US + 10);
459-
} else {
460-
dev_err(aw88395->aw_pa->dev, "%s failed", __func__);
461459
}
462460
}
463461

@@ -522,9 +520,10 @@ static int aw88395_i2c_probe(struct i2c_client *i2c)
522520
i2c_set_clientdata(i2c, aw88395);
523521

524522
aw88395->reset_gpio = devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW);
525-
if (IS_ERR(aw88395->reset_gpio))
526-
dev_info(&i2c->dev, "reset gpio not defined\n");
527-
523+
if (IS_ERR(aw88395->reset_gpio)) {
524+
return dev_err_probe(&i2c->dev, PTR_ERR(aw88395->reset_gpio),
525+
"failed to get reset gpio\n");
526+
}
528527
/* hardware reset */
529528
aw88395_hw_reset(aw88395);
530529

0 commit comments

Comments
 (0)