[PATCH 2/6] ASoC: wm8903: Use devm_gpiochip_add_data() to add the GPIO chip
Arina Kharlamova via B4 Relay
devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Tue Dec 1 11:23:33 PST 2026
From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
wm8903_i2c_probe() adds the GPIO chip and can still fail after that,
when the interrupt cannot be requested or the component cannot be
registered. The error path only disables the regulators, so the chip
stays registered while devres frees the wm8903_priv structure that
contains it.
wm8903_init_gpio() also only logs a failure of gpiochip_add_data(), and
wm8903_i2c_remove() calls gpiochip_remove() regardless.
Add the chip with devm_gpiochip_add_data(). It is then removed on probe
failure and on unbind, before the regmap and the driver data are
released, and only if it was added.
Fixes: 0bf79ef2c303 ("ASoC: wm8903: init GPIOs during I2C probe not codec probe")
Fixes: 7cfe56172ac1 ("ASoC: wm8903: Expose GPIOs through gpiolib")
Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
sound/soc/codecs/wm8903.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index 065499f33d21..d47799209727 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -1891,23 +1891,14 @@ static void wm8903_init_gpio(struct wm8903_priv *wm8903)
else
wm8903->gpio_chip.base = -1;
- ret = gpiochip_add_data(&wm8903->gpio_chip, wm8903);
+ ret = devm_gpiochip_add_data(wm8903->dev, &wm8903->gpio_chip, wm8903);
if (ret != 0)
dev_err(wm8903->dev, "Failed to add GPIOs: %d\n", ret);
}
-
-static void wm8903_free_gpio(struct wm8903_priv *wm8903)
-{
- gpiochip_remove(&wm8903->gpio_chip);
-}
#else
static void wm8903_init_gpio(struct wm8903_priv *wm8903)
{
}
-
-static void wm8903_free_gpio(struct wm8903_priv *wm8903)
-{
-}
#endif
static const struct snd_soc_component_driver soc_component_dev_wm8903 = {
@@ -2221,7 +2212,6 @@ static void wm8903_i2c_remove(struct i2c_client *client)
wm8903->supplies);
if (client->irq)
free_irq(client->irq, wm8903);
- wm8903_free_gpio(wm8903);
}
static const struct of_device_id wm8903_of_match[] = {
--
Git-157)
More information about the Linux-rockchip
mailing list