From: Ruoyu Wang <ruoyuw560@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Russell King <rmk+kernel@arm.linux.org.uk>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Ruoyu Wang <ruoyuw560@gmail.com>
Subject: [PATCH] component: Release match data on add failure
Date: Fri, 14 Aug 2026 21:41:32 +0800 [thread overview]
Message-ID: <20260814134132.1387952-1-ruoyuw560@gmail.com> (raw)
component_match_add_release() accepts a release callback so callers can
transfer ownership of resources held by the match data. However,
__component_match_add() returns without invoking that callback when the
match is already an error pointer or when allocating the match or its
array fails.
This leaks resources acquired before the call. For example,
drm_of_component_match_add() takes a reference to its device node before
adding the match, and ERR_PTR-aware callers can return from probe with
that reference still held. Calls made after the first allocation failure
can leak further references.
Invoke the release callback whenever the match data cannot be added, and
document the failure-path ownership rule. Successful match lifetime
semantics remain unchanged.
This issue was found by a static analysis checker and confirmed by manual
source review.
Fixes: ce657b1cddf1 ("component: add support for releasing match data")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
drivers/base/component.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/base/component.c b/drivers/base/component.c
index 655d68deb590c..2b455d7499926 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -388,14 +388,14 @@ static void __component_match_add(struct device *parent,
struct component_match *match = *matchptr;
if (IS_ERR(match))
- return;
+ goto err_release;
if (!match) {
match = devres_alloc(devm_component_match_release,
sizeof(*match), GFP_KERNEL);
if (!match) {
*matchptr = ERR_PTR(-ENOMEM);
- return;
+ goto err_release;
}
devres_add(parent, match);
@@ -410,7 +410,7 @@ static void __component_match_add(struct device *parent,
ret = component_match_realloc(match, new_size);
if (ret) {
*matchptr = ERR_PTR(ret);
- return;
+ goto err_release;
}
}
@@ -420,6 +420,11 @@ static void __component_match_add(struct device *parent,
match->compare[match->num].data = compare_data;
match->compare[match->num].component = NULL;
match->num++;
+ return;
+
+err_release:
+ if (release)
+ release(parent, compare_data);
}
/**
@@ -438,7 +443,8 @@ static void __component_match_add(struct device *parent,
* The allocated match list in @matchptr is automatically released using devm
* actions, where upon @release will be called to free any references held by
* @compare_data, e.g. when @compare_data is a &device_node that must be
- * released with of_node_put().
+ * released with of_node_put(). @release is also called if the match cannot be
+ * added.
*
* See also component_match_add() and component_match_add_typed().
*/
--
2.51.0
next reply other threads:[~2026-08-14 13:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 13:41 Ruoyu Wang [this message]
2026-08-14 13:54 ` [PATCH] component: Release match data on add failure sashiko-bot
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=20260814134132.1387952-1-ruoyuw560@gmail.com \
--to=ruoyuw560@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rmk+kernel@arm.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.