From: sashiko-bot@kernel.org
To: "Zhiqi Zhang" <zhiqizhangg@gmail.com>
Cc: dri-devel@lists.freedesktop.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH v3 1/2] component: release match data on add failure
Date: Sun, 06 Dec 2026 03:01:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-252099@kernel.org> (raw)
In-Reply-To: <20261206024833.37825-2-zhiqizhangg@gmail.com>
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
parent reply other threads:[~2026-12-06 3:01 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20261206024833.37825-2-zhiqizhangg@gmail.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-252099@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhiqizhangg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox