From: Lee Jones <lee@kernel.org>
To: Valery Borovsky <vebohr@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v3] mfd: sm501: fix reference leak on failed device registration
Date: Thu, 14 May 2026 15:54:50 +0100 [thread overview]
Message-ID: <20260514145450.GN305027@google.com> (raw)
In-Reply-To: <20260506154040.672860-1-vebohr@gmail.com>
On Wed, 06 May 2026, Valery Borovsky wrote:
> When platform_device_register() fails in sm501_register_device(), the
> platform device allocated by sm501_create_subdev() has its struct device
> initialized by device_initialize() inside platform_device_register(). The
> error path logs the error but returns without dropping the device reference,
> leaking the memory allocated by sm501_create_subdev():
>
> sm501_register_device()
> -> platform_device_register(pdev)
> -> device_initialize(&pdev->dev) /* kref = 1 */
> -> platform_device_add(pdev) /* fails */
> <- dev_err() called, kref still 1, sm501_device_release never called
>
> The device's release callback (sm501_device_release) calls kfree() on the
> containing sm501_device structure. Without platform_device_put(), this
> memory is never freed.
>
> Per platform_device_register() kernel-doc:
>
> NOTE: _Never_ directly free @pdev after calling this function, even if
> it returned an error! Always use platform_device_put() to give up the
> reference initialised in this function instead.
>
> Fix this by calling platform_device_put() in the error branch, which
> triggers sm501_device_release() and frees the allocated memory.
>
> Fixes: b6d6454fdb66 ("[PATCH] mfd: SM501 core driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Valery Borovsky <vebohr@gmail.com>
> ---
> drivers/mfd/sm501.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
I don't see a message from me acknowledging this, but it is applied to my tree.
--
Lee Jones
next prev parent reply other threads:[~2026-05-14 14:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1777889235.git.vebohr@gmail.com>
2026-05-04 10:08 ` [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-04 10:08 ` [PATCH 2/5] platform/chrome: cros_ec_lpc: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-05 2:40 ` Tzung-Bi Shih
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-04 13:58 ` Miquel Raynal
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-05 8:50 ` Sudeep Holla
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-04 12:48 ` [PATCH v2] " Valery Borovsky
2026-05-04 13:52 ` Miquel Raynal
2026-05-05 15:00 ` Lee Jones
2026-05-05 15:12 ` Miquel Raynal
2026-05-06 15:40 ` [PATCH v3] " Valery Borovsky
2026-05-14 14:54 ` Lee Jones [this message]
2026-05-14 16:26 ` Valery Borovsky
2026-05-06 15:43 ` [PATCH 3/5] mtd: maps: physmap-core: " Valery Borovsky
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=20260514145450.GN305027@google.com \
--to=lee@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vebohr@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