dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/2] component: release match data on add failure
       [not found] ` <20261206024833.37825-2-zhiqizhangg@gmail.com>
@ 2026-12-06  3:01   ` sashiko-bot
  0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-12-06  3:01 UTC (permalink / raw)
  To: Zhiqi Zhang; +Cc: dri-devel, linux-sound

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] component: double of_node_put() in ASoC codecs on match add
  failure
--

commit 0683b7fafbae8a82c09ea4152d6cf8bee316a38f
Author: Zhiqi Zhang <zhiqizhangg@gmail.com>

component: release match data on add failure

This commit invokes the match release callback in __component_match_add()
when allocation fails or *matchptr already holds an ERR_PTR, and returns
that error from component_master_add_with_match().

> diff --git a/drivers/base/component.c b/drivers/base/component.c
> index 655d68deb590c..6b84ce958140d 100644
> --- a/drivers/base/component.c
> +++ b/drivers/base/component.c

[ ... ]

> @@ -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;
>  		}

[Severity: Medium]
Can this cause a double of_node_put() in existing callers that drop their
device_node reference when *matchptr becomes an ERR_PTR?

Previously, __component_match_add() left compare_data to the caller on
allocation failure.  Three ASoC codec drivers rely on that and still drop
their rxnode/txnode reference on IS_ERR(*matchptr): pm4125.c, wcd937x.c,
and wcd939x.c.

sound/soc/codecs/pm4125.c:pm4125_add_slave_components() {
    ...
	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;
	}
    ...
}

When devres_alloc() or component_match_realloc() fails,
__component_match_add() now drops the single of_parse_phandle() reference
via component_release_of(), and the driver then calls of_node_put() again,
causing a refcount underflow and use-after-free under CONFIG_OF_DYNAMIC.

Updating those three callers (pm4125_add_slave_components(),
wcd937x_add_slave_components(), and wcd939x_add_slave_components()) along
with the component_match_add_release() kernel-doc would avoid this
regression.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206024833.37825-1-zhiqizhangg@gmail.com?part=1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-06  3:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261206024833.37825-1-zhiqizhangg@gmail.com>
     [not found] ` <20261206024833.37825-2-zhiqizhangg@gmail.com>
2026-12-06  3:01   ` [PATCH v3 1/2] component: release match data on add failure sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox