* [PATCH v3 1/2] component: release match data on add failure
2026-12-06 2:48 [PATCH v3 0/2] component: fix match add failure handling Zhiqi Zhang
@ 2026-12-06 2:48 ` Zhiqi Zhang
2026-12-06 3:01 ` sashiko-bot
2026-12-06 2:48 ` [PATCH v3 2/2] ASoC: codecs: wcd938x: deselect mux on probe failures Zhiqi Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Zhiqi Zhang @ 2026-12-06 2:48 UTC (permalink / raw)
To: Greg Kroah-Hartman, rafael, Mark Brown, Srinivas Kandagatla
Cc: Danilo Krummrich, Johan Hovold, Liam Girdwood, Jaroslav Kysela,
Takashi Iwai, dri-devel, driver-core, linux-sound, linux-arm-msm,
Zhiqi Zhang, stable
component_match_add_release() transfers ownership of compare_data to the
component core so the release callback can drop it when the match list is
destroyed.
If __component_match_add() fails to allocate the match list or grow its
match array, no entry is recorded and the release callback is never run.
Later add calls after matchptr already holds an ERR_PTR have the same
problem, because callers batch matches through void helpers and have no
return value to act on.
The stored ERR_PTR can also be passed to component_master_add_with_match(),
which dereferences match->num before returning an error.
Release the compare data on add failure and make
component_master_add_with_match() return the stored error when it receives
an ERR_PTR match list.
Fixes: ce657b1cddf1 ("component: add support for releasing match data")
Cc: stable@vger.kernel.org
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
drivers/base/component.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/base/component.c b/drivers/base/component.c
index 655d68deb5..6b84ce9581 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -356,6 +356,14 @@ static void devm_component_match_release(struct device *parent, void *res)
kfree(match->compare);
}
+static void component_match_release(struct device *parent,
+ void (*release)(struct device *, void *),
+ void *compare_data)
+{
+ if (release)
+ release(parent, compare_data);
+}
+
static int component_match_realloc(struct component_match *match, size_t num)
{
struct component_match_array *new;
@@ -387,13 +395,16 @@ static void __component_match_add(struct device *parent,
{
struct component_match *match = *matchptr;
- if (IS_ERR(match))
+ if (IS_ERR(match)) {
+ component_match_release(parent, release, compare_data);
return;
+ }
if (!match) {
match = devres_alloc(devm_component_match_release,
sizeof(*match), GFP_KERNEL);
if (!match) {
+ component_match_release(parent, release, compare_data);
*matchptr = ERR_PTR(-ENOMEM);
return;
}
@@ -409,6 +420,7 @@ static void __component_match_add(struct device *parent,
ret = component_match_realloc(match, new_size);
if (ret) {
+ component_match_release(parent, release, compare_data);
*matchptr = ERR_PTR(ret);
return;
}
@@ -516,6 +528,9 @@ int component_master_add_with_match(struct device *parent,
struct aggregate_device *adev;
int ret;
+ if (IS_ERR(match))
+ return PTR_ERR(match);
+
/* Reallocate the match array for its true size */
ret = component_match_realloc(match, match->num);
if (ret)
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v3 2/2] ASoC: codecs: wcd938x: deselect mux on probe failures
2026-12-06 2:48 [PATCH v3 0/2] component: fix match add failure handling Zhiqi Zhang
2026-12-06 2:48 ` [PATCH v3 1/2] component: release match data on add failure Zhiqi Zhang
@ 2026-12-06 2:48 ` Zhiqi Zhang
1 sibling, 0 replies; 4+ messages in thread
From: Zhiqi Zhang @ 2026-12-06 2:48 UTC (permalink / raw)
To: Greg Kroah-Hartman, rafael, Mark Brown, Srinivas Kandagatla
Cc: Danilo Krummrich, Johan Hovold, Liam Girdwood, Jaroslav Kysela,
Takashi Iwai, dri-devel, driver-core, linux-sound, linux-arm-msm,
Zhiqi Zhang, stable
wcd938x_populate_dt_data() selects the optional us/euro mux and records
mux_setup_done. If a later probe step fails, wcd938x_probe() returns
without deselecting the mux.
Route probe failures through a common mux cleanup helper once the private
data is available. Use the same helper for jack reconfiguration and driver
remove so mux_setup_done stays consistent in all deselect paths.
Fixes: eec611d26f84 ("ASoC: codecs: wcd938x: add mux control support for hp audio mux")
Cc: stable@vger.kernel.org
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
sound/soc/codecs/wcd938x.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index 1c4833584b..0ceec20d26 100644
--- a/sound/soc/codecs/wcd938x.c
+++ b/sound/soc/codecs/wcd938x.c
@@ -3167,6 +3167,14 @@ static const struct snd_soc_component_driver soc_codec_dev_wcd938x = {
.endianness = 1,
};
+static void wcd938x_mux_deselect(struct wcd938x_priv *wcd938x)
+{
+ if (wcd938x->us_euro_mux && wcd938x->mux_setup_done) {
+ mux_control_deselect(wcd938x->us_euro_mux);
+ wcd938x->mux_setup_done = false;
+ }
+}
+
static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component)
{
struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
@@ -3174,8 +3182,7 @@ static bool wcd938x_swap_gnd_mic(struct snd_soc_component *component)
int ret;
if (wcd938x->us_euro_mux) {
- if (wcd938x->mux_setup_done)
- mux_control_deselect(wcd938x->us_euro_mux);
+ wcd938x_mux_deselect(wcd938x);
ret = mux_control_try_select(wcd938x->us_euro_mux, !wcd938x->mux_state);
if (ret) {
@@ -3487,17 +3494,17 @@ static int wcd938x_probe(struct platform_device *pdev)
ret = wcd938x_populate_dt_data(wcd938x, dev);
if (ret)
- return ret;
+ goto err_mux_deselect;
ret = wcd938x_add_slave_components(wcd938x, dev, &match);
if (ret)
- return ret;
+ goto err_mux_deselect;
wcd938x_reset(wcd938x);
ret = component_master_add_with_match(dev, &wcd938x_comp_ops, match);
if (ret)
- return ret;
+ goto err_mux_deselect;
pm_runtime_set_autosuspend_delay(dev, 1000);
pm_runtime_use_autosuspend(dev);
@@ -3507,6 +3514,10 @@ static int wcd938x_probe(struct platform_device *pdev)
pm_runtime_idle(dev);
return 0;
+
+err_mux_deselect:
+ wcd938x_mux_deselect(wcd938x);
+ return ret;
}
static void wcd938x_remove(struct platform_device *pdev)
@@ -3520,8 +3531,7 @@ static void wcd938x_remove(struct platform_device *pdev)
pm_runtime_set_suspended(dev);
pm_runtime_dont_use_autosuspend(dev);
- if (wcd938x->us_euro_mux && wcd938x->mux_setup_done)
- mux_control_deselect(wcd938x->us_euro_mux);
+ wcd938x_mux_deselect(wcd938x);
}
#if defined(CONFIG_OF)
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 4+ messages in thread