drivers/macintosh/adb.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
When platform_device_register() fails in adbdev_init(), the embedded
struct device in adb_pfdev has already been initialized by
device_initialize(), but the failure path does not drop the device
reference for the current platform device:
adbdev_init()
platform_device_register(&adb_pfdev)
device_initialize(&adb_pfdev.dev)
setup_pdev_dma_masks(&adb_pfdev)
return platform_device_add(&adb_pfdev)
As documented in platform_device_register(), the caller must use
platform_device_put() to give up the reference initialized in this
function when registration fails.
This leads to a reference leak when platform_device_register() fails.
Fix this by checking the return value and calling platform_device_put().
The issue was identified by a static analysis tool I developed and
confirmed by manual review.
Fixes: c9f6d3d5c6d4f ("[POWERPC] adb: Replace sleep notifier with platform driver suspend/resume hooks")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
drivers/macintosh/adb.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index fe150125e099..eff06f78aa80 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -883,6 +883,8 @@ adb_dummy_probe(struct platform_device *dev)
static void __init
adbdev_init(void)
{
+ int err;
+
if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
pr_err("adb: unable to get major %d\n", ADB_MAJOR);
return;
@@ -893,6 +895,9 @@ adbdev_init(void)
device_create(&adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
- platform_device_register(&adb_pfdev);
+ err = platform_device_register(&adb_pfdev);
+ if (err)
+ platform_device_put(&adb_pfdev);
+
platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
}
--
2.43.0
Hi,
Please disregard this patch.
On Wed, 15 Apr 2026 at 22:37, Guangshuo Li <lgs201920130244@gmail.com> wrote:
>
> When platform_device_register() fails in adbdev_init(), the embedded
> struct device in adb_pfdev has already been initialized by
> device_initialize(), but the failure path does not drop the device
> reference for the current platform device:
>
> adbdev_init()
> platform_device_register(&adb_pfdev)
> device_initialize(&adb_pfdev.dev)
> setup_pdev_dma_masks(&adb_pfdev)
> return platform_device_add(&adb_pfdev)
>
> As documented in platform_device_register(), the caller must use
> platform_device_put() to give up the reference initialized in this
> function when registration fails.
>
> This leads to a reference leak when platform_device_register() fails.
> Fix this by checking the return value and calling platform_device_put().
>
> The issue was identified by a static analysis tool I developed and
> confirmed by manual review.
>
> Fixes: c9f6d3d5c6d4f ("[POWERPC] adb: Replace sleep notifier with platform driver suspend/resume hooks")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/macintosh/adb.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
> index fe150125e099..eff06f78aa80 100644
> --- a/drivers/macintosh/adb.c
> +++ b/drivers/macintosh/adb.c
> @@ -883,6 +883,8 @@ adb_dummy_probe(struct platform_device *dev)
> static void __init
> adbdev_init(void)
> {
> + int err;
> +
> if (register_chrdev(ADB_MAJOR, "adb", &adb_fops)) {
> pr_err("adb: unable to get major %d\n", ADB_MAJOR);
> return;
> @@ -893,6 +895,9 @@ adbdev_init(void)
>
> device_create(&adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
>
> - platform_device_register(&adb_pfdev);
> + err = platform_device_register(&adb_pfdev);
> + if (err)
> + platform_device_put(&adb_pfdev);
> +
> platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
> }
> --
> 2.43.0
>
After re-checking it, adb_pfdev is a static platform_device and it does
not provide a dev.release callback. Therefore calling
platform_device_put() on the platform_device_register() failure path is
not appropriate here and can trigger the missing release callback
warning.
This falls into the same static platform_device pattern pointed out in
the other reviews, so I will drop this patch.
Sorry for the noise.
Best regards,
Guangshuo Li
© 2016 - 2026 Red Hat, Inc.