* [PATCH v2 1/4] ASoC: codecs: pm4125: check component match allocation
2026-12-04 12:58 [PATCH v2 0/4] ASoC: codecs: handle component match allocation failures Zhiqi Zhang
@ 2026-12-04 12:58 ` Zhiqi Zhang
2026-12-04 13:21 ` sashiko-bot
2026-12-04 12:58 ` [PATCH v2 2/4] ASoC: codecs: wcd937x: " Zhiqi Zhang
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:58 UTC (permalink / raw)
To: Mark Brown
Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
linux-sound, linux-arm-msm, Zhiqi Zhang
component_match_add_release() reports allocation failures by storing an
ERR_PTR in the caller supplied match pointer. The PM4125 codec helper
ignores that state and can later pass the error pointer to
component_master_add_with_match(), which dereferences match->num.
The failed add also does not take ownership of the phandle reference
passed as compare data, so the current rx or tx node must be released by
the caller.
Check the match pointer after each add, drop the node reference that was
not transferred to the match entry, and return the allocation error.
Fixes: 8ad529484937 ("ASoC: codecs: add new pm4125 audio codec driver")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
AI assistance disclosure: I found the bug. Codex modified the code.
I reviewed the change.
sound/soc/codecs/pm4125.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sound/soc/codecs/pm4125.c b/sound/soc/codecs/pm4125.c
index 22fada77b2..f5b37ec038 100644
--- a/sound/soc/codecs/pm4125.c
+++ b/sound/soc/codecs/pm4125.c
@@ -1625,18 +1625,31 @@ static int pm4125_add_slave_components(struct pm4125_priv *pm4125, struct device
struct component_match **matchptr)
{
struct device_node *np = dev->of_node;
+ int ret;
pm4125->rxnode = of_parse_phandle(np, "qcom,rx-device", 0);
if (!pm4125->rxnode)
return dev_err_probe(dev, -ENODEV, "Couldn't parse phandle to qcom,rx-device\n");
component_match_add_release(dev, matchptr, component_release_of, component_compare_of,
pm4125->rxnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(pm4125->rxnode);
+ pm4125->rxnode = NULL;
+ return ret;
+ }
pm4125->txnode = of_parse_phandle(np, "qcom,tx-device", 0);
if (!pm4125->txnode)
return dev_err_probe(dev, -ENODEV, "Couldn't parse phandle to qcom,tx-device\n");
component_match_add_release(dev, matchptr, component_release_of, component_compare_of,
pm4125->txnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(pm4125->txnode);
+ pm4125->txnode = NULL;
+ return ret;
+ }
return 0;
}
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/4] ASoC: codecs: pm4125: check component match allocation
2026-12-04 12:58 ` [PATCH v2 1/4] ASoC: codecs: pm4125: check component match allocation Zhiqi Zhang
@ 2026-12-04 13:21 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 13:21 UTC (permalink / raw)
To: Zhiqi Zhang; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ASoC: pm4125: driver workaround conflicts with component core
error handling
--
commit 5670d13c3334f605590dbc9132ebd2c33509847a
Author: Zhiqi Zhang <zhiqizhangg@gmail.com>
ASoC: codecs: pm4125: check component match allocation
This commit checks *matchptr for error pointers after each
component_match_add_release() call in pm4125_add_slave_components() and
drops the corresponding rxnode or txnode reference on failure.
> diff --git a/sound/soc/codecs/pm4125.c b/sound/soc/codecs/pm4125.c
> index 22fada77b2740..f5b37ec038276 100644
> --- a/sound/soc/codecs/pm4125.c
> +++ b/sound/soc/codecs/pm4125.c
> @@ -1625,18 +1625,31 @@ static int pm4125_add_slave_components(struct pm4125_priv *pm4125, struct device
> struct component_match **matchptr)
> {
> struct device_node *np = dev->of_node;
> + int ret;
>
> pm4125->rxnode = of_parse_phandle(np, "qcom,rx-device", 0);
> if (!pm4125->rxnode)
> return dev_err_probe(dev, -ENODEV, "Couldn't parse phandle to qcom,rx-device\n");
> component_match_add_release(dev, matchptr, component_release_of, component_compare_of,
> pm4125->rxnode);
> + if (IS_ERR(*matchptr)) {
> + ret = PTR_ERR(*matchptr);
> + of_node_put(pm4125->rxnode);
> + pm4125->rxnode = NULL;
> + return ret;
> + }
[Severity: Low]
Should this be fixed in drivers/base/component.c instead of working around it
in pm4125_add_slave_components()?
Both issues originate in the component core: __component_match_add() returns
without calling release(parent, compare_data) on allocation failure, and
component_master_add_with_match() dereferences match->num without checking
IS_ERR(match).
Because component_match_add_release() returns void to let callers batch
additions, wrappers like drm_of_component_match_add() take an of_node_get()
and leave callers no way to drop it on error.
Manually calling of_node_put() here leaves those other callers unfixed and
will cause a double of_node_put() if __component_match_add() is later fixed
to invoke release() on error.
Calling release() on the error paths in __component_match_add() and returning
PTR_ERR(match) when IS_ERR(match) in component_master_add_with_match() would
handle both problems uniformly for all callers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204125837.81419-1-zhiqizhangg@gmail.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/4] ASoC: codecs: wcd937x: check component match allocation
2026-12-04 12:58 [PATCH v2 0/4] ASoC: codecs: handle component match allocation failures Zhiqi Zhang
2026-12-04 12:58 ` [PATCH v2 1/4] ASoC: codecs: pm4125: check component match allocation Zhiqi Zhang
@ 2026-12-04 12:58 ` Zhiqi Zhang
2026-12-04 12:58 ` [PATCH v2 3/4] ASoC: codecs: wcd938x: " Zhiqi Zhang
2026-12-04 12:58 ` [PATCH v2 4/4] ASoC: codecs: wcd939x: " Zhiqi Zhang
3 siblings, 0 replies; 7+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:58 UTC (permalink / raw)
To: Mark Brown
Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
linux-sound, linux-arm-msm, Zhiqi Zhang
component_match_add_release() reports allocation failures by storing an
ERR_PTR in the caller supplied match pointer. The wcd937x helper ignores
that state and can later pass the error pointer to
component_master_add_with_match(), which dereferences match->num.
The failed add also does not take ownership of the phandle reference
passed as compare data, so the current rx or tx node must be released by
the caller.
Check the match pointer after each add, drop the node reference that was
not transferred to the match entry, and return the allocation error.
Fixes: 9be3ec196da4 ("ASoC: codecs: wcd937x: add wcd937x codec driver")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
AI assistance disclosure: I found the bug. Codex modified the code.
I reviewed the change.
sound/soc/codecs/wcd937x.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sound/soc/codecs/wcd937x.c b/sound/soc/codecs/wcd937x.c
index b64fc16d50..aef8164301 100644
--- a/sound/soc/codecs/wcd937x.c
+++ b/sound/soc/codecs/wcd937x.c
@@ -2879,6 +2879,7 @@ static int wcd937x_add_slave_components(struct wcd937x_priv *wcd937x,
struct component_match **matchptr)
{
struct device_node *np = dev->of_node;
+ int ret;
wcd937x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0);
if (!wcd937x->rxnode) {
@@ -2888,6 +2889,12 @@ static int wcd937x_add_slave_components(struct wcd937x_priv *wcd937x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd937x->rxnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd937x->rxnode);
+ wcd937x->rxnode = NULL;
+ return ret;
+ }
wcd937x->txnode = of_parse_phandle(np, "qcom,tx-device", 0);
if (!wcd937x->txnode) {
@@ -2897,6 +2904,12 @@ static int wcd937x_add_slave_components(struct wcd937x_priv *wcd937x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd937x->txnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd937x->txnode);
+ wcd937x->txnode = NULL;
+ return ret;
+ }
return 0;
}
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 3/4] ASoC: codecs: wcd938x: check component match allocation
2026-12-04 12:58 [PATCH v2 0/4] ASoC: codecs: handle component match allocation failures Zhiqi Zhang
2026-12-04 12:58 ` [PATCH v2 1/4] ASoC: codecs: pm4125: check component match allocation Zhiqi Zhang
2026-12-04 12:58 ` [PATCH v2 2/4] ASoC: codecs: wcd937x: " Zhiqi Zhang
@ 2026-12-04 12:58 ` Zhiqi Zhang
2026-12-04 13:30 ` sashiko-bot
2026-12-04 12:58 ` [PATCH v2 4/4] ASoC: codecs: wcd939x: " Zhiqi Zhang
3 siblings, 1 reply; 7+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:58 UTC (permalink / raw)
To: Mark Brown
Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
linux-sound, linux-arm-msm, Zhiqi Zhang
component_match_add_release() reports allocation failures by storing an
ERR_PTR in the caller supplied match pointer. The wcd938x helper ignores
that state and can later pass the error pointer to
component_master_add_with_match(), which dereferences match->num.
The failed add also does not take ownership of the phandle reference
passed as compare data, so the current rx or tx node must be released by
the caller.
Check the match pointer after each add, drop the node reference that was
not transferred to the match entry, and return the allocation error.
The codec probe also selects the optional us/euro mux before adding the
SoundWire component matches. Route later probe failures through the mux
cleanup path so the selected state is released when match allocation or
aggregate registration fails.
Fixes: 8d78602aa87a ("ASoC: codecs: wcd938x: add basic driver")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
AI assistance disclosure: I found the bug. Codex modified the code.
I reviewed the change.
sound/soc/codecs/wcd938x.c | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c
index 1c4833584b..7810798ba2 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) {
@@ -3446,6 +3453,7 @@ static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x,
struct component_match **matchptr)
{
struct device_node *np;
+ int ret;
np = dev->of_node;
@@ -3457,6 +3465,12 @@ static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd938x->rxnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd938x->rxnode);
+ wcd938x->rxnode = NULL;
+ return ret;
+ }
wcd938x->txnode = of_parse_phandle(np, "qcom,tx-device", 0);
if (!wcd938x->txnode) {
@@ -3466,6 +3480,12 @@ static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd938x->txnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd938x->txnode);
+ wcd938x->txnode = NULL;
+ return ret;
+ }
return 0;
}
@@ -3491,13 +3511,13 @@ static int wcd938x_probe(struct platform_device *pdev)
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 +3527,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 +3544,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] 7+ messages in thread* Re: [PATCH v2 3/4] ASoC: codecs: wcd938x: check component match allocation
2026-12-04 12:58 ` [PATCH v2 3/4] ASoC: codecs: wcd938x: " Zhiqi Zhang
@ 2026-12-04 13:30 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 13:30 UTC (permalink / raw)
To: Zhiqi Zhang; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ASoC: wcd938x: missing Fixes tag for bundled us_euro_mux cleanup
fix
--
commit da3398842c3a0e9bb3ae370be1a207b0005ebbee
Author: Zhiqi Zhang <zhiqizhangg@gmail.com>
> ASoC: codecs: wcd938x: check component match allocation
>
> component_match_add_release() reports allocation failures by storing an
> ERR_PTR in the caller supplied match pointer. The wcd938x helper ignores
> that state and can later pass the error pointer to
> component_master_add_with_match(), which dereferences match->num.
>
> The failed add also does not take ownership of the phandle reference
> passed as compare data, so the current rx or tx node must be released by
> the caller.
>
> Check the match pointer after each add, drop the node reference that was
> not transferred to the match entry, and return the allocation error.
>
> The codec probe also selects the optional us/euro mux before adding the
> SoundWire component matches. Route later probe failures through the mux
> cleanup path so the selected state is released when match allocation or
> aggregate registration fails.
>
> Fixes: 8d78602aa87a ("ASoC: codecs: wcd938x: add basic driver")
> Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
[Severity: Low]
This patch bundles two separate fixes: the component_match_add_release()
check for 8d78602aa87a ("ASoC: codecs: wcd938x: add basic driver") and the
us_euro_mux probe-failure cleanup for eec611d26f84 ("ASoC: codecs: wcd938x:
add mux control support for hp audio mux").
Bundling the us_euro_mux cleanup will cause merge conflicts when backporting
the match-allocation fix to stable trees that predate us_euro_mux. Should
the mux cleanup be split into a separate patch, or at least include:
Fixes: eec611d26f84 ("ASoC: codecs: wcd938x: add mux control support for hp audio mux")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204125837.81419-1-zhiqizhangg@gmail.com?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 4/4] ASoC: codecs: wcd939x: check component match allocation
2026-12-04 12:58 [PATCH v2 0/4] ASoC: codecs: handle component match allocation failures Zhiqi Zhang
` (2 preceding siblings ...)
2026-12-04 12:58 ` [PATCH v2 3/4] ASoC: codecs: wcd938x: " Zhiqi Zhang
@ 2026-12-04 12:58 ` Zhiqi Zhang
3 siblings, 0 replies; 7+ messages in thread
From: Zhiqi Zhang @ 2026-12-04 12:58 UTC (permalink / raw)
To: Mark Brown
Cc: Srinivas Kandagatla, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
linux-sound, linux-arm-msm, Zhiqi Zhang
component_match_add_release() reports allocation failures by storing an
ERR_PTR in the caller supplied match pointer. The wcd939x helper ignores
that state and can later pass the error pointer to
component_master_add_with_match(), which dereferences match->num.
The failed add also does not take ownership of the phandle reference
passed as compare data, so the current rx or tx node must be released by
the caller.
Check the match pointer after each add, drop the node reference that was
not transferred to the match entry, and return the allocation error.
Fixes: 10f514bd172a ("ASoC: codecs: Add WCD939x Codec driver")
Signed-off-by: Zhiqi Zhang <zhiqizhangg@gmail.com>
---
AI assistance disclosure: I found the bug. Codex modified the code.
I reviewed the change.
sound/soc/codecs/wcd939x.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sound/soc/codecs/wcd939x.c b/sound/soc/codecs/wcd939x.c
index 6461501993..27c5eb4074 100644
--- a/sound/soc/codecs/wcd939x.c
+++ b/sound/soc/codecs/wcd939x.c
@@ -3512,6 +3512,7 @@ static int wcd939x_add_slave_components(struct wcd939x_priv *wcd939x,
struct component_match **matchptr)
{
struct device_node *np = dev->of_node;
+ int ret;
wcd939x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0);
if (!wcd939x->rxnode) {
@@ -3521,6 +3522,12 @@ static int wcd939x_add_slave_components(struct wcd939x_priv *wcd939x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd939x->rxnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd939x->rxnode);
+ wcd939x->rxnode = NULL;
+ return ret;
+ }
wcd939x->txnode = of_parse_phandle(np, "qcom,tx-device", 0);
if (!wcd939x->txnode) {
@@ -3530,6 +3537,12 @@ static int wcd939x_add_slave_components(struct wcd939x_priv *wcd939x,
component_match_add_release(dev, matchptr, component_release_of,
component_compare_of, wcd939x->txnode);
+ if (IS_ERR(*matchptr)) {
+ ret = PTR_ERR(*matchptr);
+ of_node_put(wcd939x->txnode);
+ wcd939x->txnode = NULL;
+ return ret;
+ }
return 0;
}
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 7+ messages in thread