* [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
@ 2026-05-04 10:08 ` Vastargazing
2026-05-04 10:08 ` [PATCH 2/5] platform/chrome: cros_ec_lpc: " Vastargazing
` (4 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
To: linux-kernel
Cc: Vastargazing, stable, Arnd Bergmann, Greg Kroah-Hartman,
Anatolij Gustschin, Andrew Morton
When platform_device_register() fails in digsy_mtc_eeprom_devices_init(),
the embedded struct device has already been initialized by
device_initialize() inside platform_device_register(). The failure path
cleans up the software node but returns the error without dropping the
device reference:
digsy_mtc_eeprom_devices_init()
-> platform_device_register(&digsy_mtc_eeprom)
-> device_initialize(&digsy_mtc_eeprom.dev) /* kref = 1 */
-> platform_device_add(&digsy_mtc_eeprom) /* fails */
<- returns error, kref still 1, reference leaked
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 before
removing the software node.
Fixes: 469dded18391 ("misc/eeprom: add eeprom access driver for digsy_mtc board")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/misc/eeprom/digsy_mtc_eeprom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index ee58f7ce5bfa..4ca3e567c49d 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -89,8 +89,10 @@ static int __init digsy_mtc_eeprom_devices_init(void)
return ret;
ret = platform_device_register(&digsy_mtc_eeprom);
- if (ret)
+ if (ret) {
+ platform_device_put(&digsy_mtc_eeprom);
device_remove_software_node(&digsy_mtc_eeprom.dev);
+ }
return ret;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 2/5] platform/chrome: cros_ec_lpc: fix reference leak on failed device registration
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
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-05 2:40 ` Tzung-Bi Shih
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
To: linux-kernel
Cc: Vastargazing, stable, Benson Leung, Tzung-Bi Shih, Guenter Roeck,
Gwendal Grignou, Thierry Escande, Enric Balletbo i Serra,
chrome-platform
When platform_device_register() fails in cros_ec_lpc_init(), the embedded
struct device has already been initialized by device_initialize() inside
platform_device_register(). The error path unregisters the driver but
returns without dropping the device reference:
cros_ec_lpc_init()
-> platform_device_register(&cros_ec_lpc_device)
-> device_initialize(&cros_ec_lpc_device.dev) /* kref = 1 */
-> platform_device_add(&cros_ec_lpc_device) /* fails */
<- platform_driver_unregister() called, but kref still 1
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() before unregistering the driver.
Fixes: 5f454bdf6353 ("platform/chrome: cros_ec_lpc: Register the driver if ACPI entry is missing.")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/platform/chrome/cros_ec_lpc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index 78cfff80cdea..cb3ff76d29e9 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -892,6 +892,7 @@ static int __init cros_ec_lpc_init(void)
ret = platform_device_register(&cros_ec_lpc_device);
if (ret) {
pr_err(DRV_NAME ": can't register device: %d\n", ret);
+ platform_device_put(&cros_ec_lpc_device);
platform_driver_unregister(&cros_ec_lpc_driver);
}
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 2/5] platform/chrome: cros_ec_lpc: fix reference leak on failed device registration
2026-05-04 10:08 ` [PATCH 2/5] platform/chrome: cros_ec_lpc: " Vastargazing
@ 2026-05-05 2:40 ` Tzung-Bi Shih
0 siblings, 0 replies; 14+ messages in thread
From: Tzung-Bi Shih @ 2026-05-05 2:40 UTC (permalink / raw)
To: Vastargazing
Cc: linux-kernel, stable, Benson Leung, Guenter Roeck,
Gwendal Grignou, Thierry Escande, Enric Balletbo i Serra,
chrome-platform
On Mon, May 04, 2026 at 01:08:44PM +0300, Vastargazing wrote:
> When platform_device_register() fails in cros_ec_lpc_init(), the embedded
> struct device has already been initialized by device_initialize() inside
> platform_device_register(). The error path unregisters the driver but
> returns without dropping the device reference:
>
> cros_ec_lpc_init()
> -> platform_device_register(&cros_ec_lpc_device)
> -> device_initialize(&cros_ec_lpc_device.dev) /* kref = 1 */
> -> platform_device_add(&cros_ec_lpc_device) /* fails */
> <- platform_driver_unregister() called, but kref still 1
>
> 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() before unregistering the driver.
>
> Fixes: 5f454bdf6353 ("platform/chrome: cros_ec_lpc: Register the driver if ACPI entry is missing.")
> Cc: stable@vger.kernel.org
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@gmail.com>
> ---
> drivers/platform/chrome/cros_ec_lpc.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
> index 78cfff80cdea..cb3ff76d29e9 100644
> --- a/drivers/platform/chrome/cros_ec_lpc.c
> +++ b/drivers/platform/chrome/cros_ec_lpc.c
> @@ -892,6 +892,7 @@ static int __init cros_ec_lpc_init(void)
> ret = platform_device_register(&cros_ec_lpc_device);
> if (ret) {
> pr_err(DRV_NAME ": can't register device: %d\n", ret);
> + platform_device_put(&cros_ec_lpc_device);
> platform_driver_unregister(&cros_ec_lpc_driver);
> }
> }
The patch is identical to [1]. See also [2].
[1] https://lore.kernel.org/chrome-platform/20260415175707.3640225-1-lgs201920130244@gmail.com/
[2] https://lore.kernel.org/chrome-platform/CANUHTR9_c=msO7mAax=Aj4U--GB=2ozserOvrTU8WueqdSMN8Q@mail.gmail.com/
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed device registration
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
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 ` [PATCH 2/5] platform/chrome: cros_ec_lpc: " 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
` (2 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
To: linux-kernel
Cc: Vastargazing, stable, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, David Woodhouse, Lennert Buytenhek,
linux-mtd
When platform_device_register() fails in physmap_init(), the embedded
struct device has already been initialized by device_initialize() inside
platform_device_register(). The error path unregisters the driver but
returns without dropping the device reference:
physmap_init()
-> platform_device_register(&physmap_flash)
-> device_initialize(&physmap_flash.dev) /* kref = 1 */
-> platform_device_add(&physmap_flash) /* fails */
<- platform_driver_unregister() called, but kref still 1
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() before unregistering the driver.
Fixes: 73566edf9b91 ("[MTD] Convert physmap to platform driver")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/mtd/maps/physmap-core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-core.c
index dcda7685fc99..45d79ca622c1 100644
--- a/drivers/mtd/maps/physmap-core.c
+++ b/drivers/mtd/maps/physmap-core.c
@@ -654,8 +654,10 @@ static int __init physmap_init(void)
#ifdef CONFIG_MTD_PHYSMAP_COMPAT
if (err == 0) {
err = platform_device_register(&physmap_flash);
- if (err)
+ if (err) {
+ platform_device_put(&physmap_flash);
platform_driver_unregister(&physmap_flash_driver);
+ }
}
#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 3/5] mtd: maps: physmap: fix reference leak on failed device registration
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
@ 2026-05-04 13:58 ` Miquel Raynal
0 siblings, 0 replies; 14+ messages in thread
From: Miquel Raynal @ 2026-05-04 13:58 UTC (permalink / raw)
To: Vastargazing
Cc: linux-kernel, stable, Richard Weinberger, Vignesh Raghavendra,
David Woodhouse, Lennert Buytenhek, linux-mtd
On 04/05/2026 at 13:08:45 +03, Vastargazing <vebohr@gmail.com> wrote:
> When platform_device_register() fails in physmap_init(), the embedded
> struct device has already been initialized by device_initialize() inside
> platform_device_register(). The error path unregisters the driver but
> returns without dropping the device reference:
>
> physmap_init()
> -> platform_device_register(&physmap_flash)
> -> device_initialize(&physmap_flash.dev) /* kref = 1 */
> -> platform_device_add(&physmap_flash) /* fails */
> <- platform_driver_unregister() called, but kref still 1
>
> 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() before unregistering the driver.
>
> Fixes: 73566edf9b91 ("[MTD] Convert physmap to platform driver")
> Cc: stable@vger.kernel.org
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@gmail.com>
Somehow b4 applied another patch from that series, I'm not sure why. I
just dropped it. Please resend this patch alone.
Also, your SoB line seems to be incorrect, we need a proper name, please
have a loot at the DCO.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/5] perf: arm: pmu: fix reference leak on failed device registration
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
` (2 preceding siblings ...)
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " 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-05 10:36 ` [PATCH 1/5] perf/arm_pmu_acpi: fix reference leak in arm_pmu_acpi_probe error path Valery Borovsky
5 siblings, 1 reply; 14+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
To: linux-kernel
Cc: Vastargazing, stable, Will Deacon, Mark Rutland, Jeremy Linton,
Sudeep Holla, Lorenzo Pieralisi, linux-arm-kernel,
linux-perf-users
When platform_device_register() fails in arm_acpi_register_pmu_device(),
the embedded struct device has already been initialized by
device_initialize() inside platform_device_register(). The error path
unregisters the GSI interrupt but returns without dropping the device
reference:
arm_acpi_register_pmu_device()
-> platform_device_register(pdev)
-> device_initialize(&pdev->dev) /* kref = 1 */
-> platform_device_add(pdev) /* fails */
<- acpi_unregister_gsi() called, but kref still 1
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 before
unregistering the GSI.
Fixes: d24a0c7099b3 ("arm_pmu: acpi: spe: Add initial MADT/SPE probing")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/perf/arm_pmu_acpi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
index e80f76d95e68..c2defbc32ad9 100644
--- a/drivers/perf/arm_pmu_acpi.c
+++ b/drivers/perf/arm_pmu_acpi.c
@@ -119,8 +119,10 @@ arm_acpi_register_pmu_device(struct platform_device *pdev, u8 len,
pdev->resource[0].start = irq;
ret = platform_device_register(pdev);
- if (ret)
+ if (ret) {
+ platform_device_put(pdev);
acpi_unregister_gsi(gsi);
+ }
return ret;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 4/5] perf: arm: pmu: fix reference leak on failed device registration
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
@ 2026-05-05 8:50 ` Sudeep Holla
0 siblings, 0 replies; 14+ messages in thread
From: Sudeep Holla @ 2026-05-05 8:50 UTC (permalink / raw)
To: Vastargazing
Cc: linux-kernel, stable, Will Deacon, Mark Rutland, Sudeep Holla,
Jeremy Linton, Lorenzo Pieralisi, linux-arm-kernel,
linux-perf-users
On Mon, May 04, 2026 at 01:08:46PM +0300, Vastargazing wrote:
> When platform_device_register() fails in arm_acpi_register_pmu_device(),
> the embedded struct device has already been initialized by
> device_initialize() inside platform_device_register(). The error path
> unregisters the GSI interrupt but returns without dropping the device
> reference:
>
> arm_acpi_register_pmu_device()
> -> platform_device_register(pdev)
> -> device_initialize(&pdev->dev) /* kref = 1 */
> -> platform_device_add(pdev) /* fails */
> <- acpi_unregister_gsi() called, but kref still 1
>
> 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 before
> unregistering the GSI.
>
> Fixes: d24a0c7099b3 ("arm_pmu: acpi: spe: Add initial MADT/SPE probing")
> Cc: stable@vger.kernel.org
> Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
> Signed-off-by: Vastargazing <vebohr@gmail.com>
> ---
> drivers/perf/arm_pmu_acpi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
> index e80f76d95e68..c2defbc32ad9 100644
> --- a/drivers/perf/arm_pmu_acpi.c
> +++ b/drivers/perf/arm_pmu_acpi.c
> @@ -119,8 +119,10 @@ arm_acpi_register_pmu_device(struct platform_device *pdev, u8 len,
>
> pdev->resource[0].start = irq;
> ret = platform_device_register(pdev);
> - if (ret)
> + if (ret) {
> + platform_device_put(pdev);
Both spe_dev and trbe_dev using this are statically allocated, what am I
missing here ? What will platform_device_put() do ?
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 5/5] mfd: sm501: fix reference leak on failed device registration
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
` (3 preceding siblings ...)
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
@ 2026-05-04 10:08 ` Vastargazing
2026-05-04 12:48 ` [PATCH v2] " Valery Borovsky
2026-05-05 10:36 ` [PATCH 1/5] perf/arm_pmu_acpi: fix reference leak in arm_pmu_acpi_probe error path Valery Borovsky
5 siblings, 1 reply; 14+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
To: linux-kernel
Cc: Vastargazing, stable, Lee Jones, Vincent Sanders, Andrew Morton,
Ben Dooks
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
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/mfd/sm501.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 0ee6d8940e69..8276456b142f 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -704,9 +704,11 @@ static int sm501_register_device(struct sm501_devdata *sm,
if (ret >= 0) {
dev_dbg(sm->dev, "registered %s\n", pdev->name);
list_add_tail(&smdev->list, &sm->devices);
- } else
+ } else {
dev_err(sm->dev, "error registering %s (%d)\n",
pdev->name, ret);
+ platform_device_put(pdev);
+ }
return ret;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v2] mfd: sm501: fix reference leak on failed device registration
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
@ 2026-05-04 12:48 ` Valery Borovsky
2026-05-04 13:52 ` Miquel Raynal
0 siblings, 1 reply; 14+ messages in thread
From: Valery Borovsky @ 2026-05-04 12:48 UTC (permalink / raw)
To: Lee Jones
Cc: Ben Dooks, Vincent Sanders, Andrew Morton, linux-kernel,
Valery Borovsky, stable
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(-)
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 0ee6d8940e69..8276456b142f 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -704,9 +704,11 @@ static int sm501_register_device(struct sm501_devdata *sm,
if (ret >= 0) {
dev_dbg(sm->dev, "registered %s\n", pdev->name);
list_add_tail(&smdev->list, &sm->devices);
- } else
+ } else {
dev_err(sm->dev, "error registering %s (%d)\n",
pdev->name, ret);
+ platform_device_put(pdev);
+ }
return ret;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v2] mfd: sm501: fix reference leak on failed device registration
2026-05-04 12:48 ` [PATCH v2] " Valery Borovsky
@ 2026-05-04 13:52 ` Miquel Raynal
2026-05-05 15:00 ` Lee Jones
0 siblings, 1 reply; 14+ messages in thread
From: Miquel Raynal @ 2026-05-04 13:52 UTC (permalink / raw)
To: Lee Jones, Valery Borovsky
Cc: Ben Dooks, Vincent Sanders, Andrew Morton, linux-kernel, stable
On Mon, 04 May 2026 15:48:41 +0300, 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
>
> [...]
Applied to mtd/next, thanks!
[1/1] mfd: sm501: fix reference leak on failed device registration
commit: faa9bba3fe2f37e7dcb26d4501d890fbfd7df160
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v2] mfd: sm501: fix reference leak on failed device registration
2026-05-04 13:52 ` Miquel Raynal
@ 2026-05-05 15:00 ` Lee Jones
2026-05-05 15:12 ` Miquel Raynal
0 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-05-05 15:00 UTC (permalink / raw)
To: Miquel Raynal
Cc: Valery Borovsky, Ben Dooks, Vincent Sanders, Andrew Morton,
linux-kernel, stable
On Mon, 04 May 2026, Miquel Raynal wrote:
> On Mon, 04 May 2026 15:48:41 +0300, 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
> >
> > [...]
>
> Applied to mtd/next, thanks!
I think you misread the subject line.
> [1/1] mfd: sm501: fix reference leak on failed device registration
> commit: faa9bba3fe2f37e7dcb26d4501d890fbfd7df160
>
> Patche(s) should be available on mtd/linux.git and will be
> part of the next PR (provided that no robot complains by then).
Please remove this from your tree. It should be handled via M[F]D.
Thanks.
--
Lee Jones
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2] mfd: sm501: fix reference leak on failed device registration
2026-05-05 15:00 ` Lee Jones
@ 2026-05-05 15:12 ` Miquel Raynal
0 siblings, 0 replies; 14+ messages in thread
From: Miquel Raynal @ 2026-05-05 15:12 UTC (permalink / raw)
To: Lee Jones
Cc: Valery Borovsky, Ben Dooks, Vincent Sanders, Andrew Morton,
linux-kernel, stable
Hi Lee,
On 05/05/2026 at 16:00:13 +01, Lee Jones <lee@kernel.org> wrote:
> On Mon, 04 May 2026, Miquel Raynal wrote:
>
>> On Mon, 04 May 2026 15:48:41 +0300, 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
>> >
>> > [...]
>>
>> Applied to mtd/next, thanks!
>
> I think you misread the subject line.
>
>> [1/1] mfd: sm501: fix reference leak on failed device registration
>> commit: faa9bba3fe2f37e7dcb26d4501d890fbfd7df160
>>
>> Patche(s) should be available on mtd/linux.git and will be
>> part of the next PR (provided that no robot complains by then).
>
> Please remove this from your tree. It should be handled via M[F]D.
Yes, it took a bit of time for me to receive my own answer so I replied
to the original patch immediately stating that I dropped it. For some
reason b4 applied this patch, whereas I was applying another m*t*d patch
from apparently the same series (?). Both the contribution and b4 behaviour
was strange.
Sorry for the noise.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] perf/arm_pmu_acpi: fix reference leak in arm_pmu_acpi_probe error path
2026-05-04 10:08 [PATCH 0/5] platform: fix reference leak on failed platform_device_register() Vastargazing
` (4 preceding siblings ...)
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
@ 2026-05-05 10:36 ` Valery Borovsky
5 siblings, 0 replies; 14+ messages in thread
From: Valery Borovsky @ 2026-05-05 10:36 UTC (permalink / raw)
To: Will Deacon
Cc: Mark Rutland, Arnd Bergmann, Greg Kroah-Hartman, Benson Leung,
Tzung-Bi Shih, Guenter Roeck, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Andy Shevchenko, Linus Walleij, Randy Dunlap,
linux-arm-kernel, linux-perf-users, linux-kernel, chrome-platform,
linux-mtd, Valery Borovsky
Yeah, you're right, my bad. The `arm_pmu_acpi.c` patch is definitely broken.
Since `spe_dev` and `trbe_dev` are statically allocated, they don't have a
`.dev.release` callback. If we hit `platform_device_put()` here, the refcount
drops to zero and triggers `device_release()`, which is going to scream about
the missing release function. At best, we get a messy WARN; at worst, it'll
panic the kernel if someone's running with `panic_on_warn`.
The kernel-doc note about `platform_device_put()` is really meant for dynamic
allocations where the release path actually frees memory. For static setups
like this, the original code is actually the right way to go.
Please drop patches 1/5 through 4/5 from the v1 series—they all suffer from
the same logic error. Patch 5/5 (mfd: sm501) is the only clean one, so I've
re-sent that as a standalone v2.
Sorry for the noise.
Valery Borovsky
^ permalink raw reply [flat|nested] 14+ messages in thread