From: sashiko-bot@kernel.org
To: "Ma Ke" <make_ruc2021@163.com>
Cc: sparclinux@vger.kernel.org
Subject: Re: [RESEND PATCH v2] sparc: Fix leaked platform_device references from of_find_device_by_node()
Date: Wed, 02 Dec 2026 08:53:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-245235@kernel.org> (raw)
In-Reply-To: <20261202084556.1829535-1-make_ruc2021@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sparc: platform_device ref leak on out-of-bounds index in OF
helpers
--
commit 0bdd0e6adc60c51f4dd86a3e1f30c5aaeddff7ad
Author: Ma Ke <make_ruc2021@163.com>
sparc: Fix leaked platform_device references from of_find_device_by_node()
This commit adds platform_device_put() calls to irq_of_parse_and_map(),
of_address_to_resource(), of_iomap(), and of_propagate_archdata() to drop
the reference acquired by of_find_device_by_node().
> diff --git a/arch/sparc/kernel/of_device_common.c b/arch/sparc/kernel/of_device_common.c
> index e717a56efc5d3..818bff54c2ecc 100644
> --- a/arch/sparc/kernel/of_device_common.c
> +++ b/arch/sparc/kernel/of_device_common.c
> @@ -16,11 +16,15 @@
> unsigned int irq_of_parse_and_map(struct device_node *node, int index)
> {
> struct platform_device *op = of_find_device_by_node(node);
> + unsigned int irq;
>
> if (!op || index >= op->archdata.num_irqs)
> return 0;
>
> - return op->archdata.irqs[index];
> + irq = op->archdata.irqs[index];
> + platform_device_put(op);
> +
> + return irq;
> }
> EXPORT_SYMBOL(irq_of_parse_and_map);
>
> @@ -33,6 +37,8 @@ int of_address_to_resource(struct device_node *node, int index,
> return -EINVAL;
>
> memcpy(r, &op->archdata.resource[index], sizeof(*r));
> + platform_device_put(op);
> +
> return 0;
> }
> EXPORT_SYMBOL_GPL(of_address_to_resource);
> @@ -41,13 +47,16 @@ void __iomem *of_iomap(struct device_node *node, int index)
> {
> struct platform_device *op = of_find_device_by_node(node);
> struct resource *r;
> + void __iomem *ret;
>
> if (!op || index >= op->num_resources)
> return NULL;
>
> r = &op->archdata.resource[index];
> + ret = of_ioremap(r, 0, resource_size(r), (char *) r->name);
> + platform_device_put(op);
>
> - return of_ioremap(r, 0, resource_size(r), (char *) r->name);
> + return ret;
> }
[Severity: Medium]
Do irq_of_parse_and_map(), of_address_to_resource(), and of_iomap() still
leak op when op is non-NULL and index is out of bounds?
Callers such as of_device_alloc() probe resources by incrementing index
until of_address_to_resource() returns -EINVAL, hitting the early return
with a valid op on every call.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202084556.1829535-1-make_ruc2021@163.com?part=1
prev parent reply other threads:[~2026-12-02 8:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:45 [RESEND PATCH v2] sparc: Fix leaked platform_device references from of_find_device_by_node() Ma Ke
2026-12-02 8:53 ` sashiko-bot [this message]
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-245235@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=make_ruc2021@163.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sparclinux@vger.kernel.org \
/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.