From: Krzysztof Kozlowski <krzk@kernel.org>
To: Weigang He <geoffreyhe2@gmail.com>,
Santosh Shilimkar <ssantosh@kernel.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] memory: emif: fix device tree node reference leak
Date: Sat, 17 Jan 2026 18:51:47 +0100 [thread overview]
Message-ID: <a06549ab-e6cc-4bc4-b161-f6fcb92721df@kernel.org> (raw)
In-Reply-To: <20260115064237.492714-1-geoffreyhe2@gmail.com>
On 15/01/2026 07:42, Weigang He wrote:
> The EMIF driver acquires a device tree node reference via
> of_parse_phandle() but never releases it with of_node_put(),
> causing a reference count leak.
>
> This affects:
> 1. Error paths in of_get_memory_device_details() - if allocation
> or validation fails after of_parse_phandle() succeeds, the
> reference is leaked
> 2. Normal driver removal - emif_remove() never releases the
> reference stored in emif->np_ddr
>
> Fix by adding an err_put_node label to properly release the node
> reference on error paths, and adding of_node_put() in emif_remove()
> to release the reference during normal driver unload.
>
> Fixes: e6b42eb6a66c ("memory: emif: add device tree support to emif driver")
Missing Cc stable.
> Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
> ---
> drivers/memory/emif.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c
> index 2fadad0666b1f..e4f7547efbff4 100644
> --- a/drivers/memory/emif.c
> +++ b/drivers/memory/emif.c
> @@ -922,7 +922,7 @@ static struct emif_data *of_get_memory_device_details(
> if (!emif || !pd || !dev_info) {
> dev_err(dev, "%s: Out of memory!!\n",
> __func__);
> - goto error;
> + goto err_put_node;
> }
>
> emif->plat_data = pd;
> @@ -946,7 +946,7 @@ static struct emif_data *of_get_memory_device_details(
> pd->device_info->io_width, pd->phy_type, pd->ip_rev,
> emif->dev)) {
> dev_err(dev, "%s: invalid device data!!\n", __func__);
> - goto error;
> + goto err_put_node;
> }
> /*
> * For EMIF instances other than EMIF1 see if the devices connected
> @@ -970,6 +970,8 @@ static struct emif_data *of_get_memory_device_details(
> emif->plat_data->min_tck = of_get_min_tck(np_ddr, emif->dev);
> goto out;
>
> +err_put_node:
> + of_node_put(np_ddr);
> error:
This is unused now. You do not need new label, just use existing one.
Best regards,
Krzysztof
prev parent reply other threads:[~2026-01-17 17:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 6:42 Weigang He
2026-01-17 17:51 ` Krzysztof Kozlowski [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=a06549ab-e6cc-4bc4-b161-f6fcb92721df@kernel.org \
--to=krzk@kernel.org \
--cc=geoffreyhe2@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ssantosh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®