Re: [PATCH] arm_pmu: acpi: fix reference leak on failed device registration

sashiko-bot
2026-04-15T18:31:39Z

Sashiko AI review found 1 potential issue(s):
- [High] Calling platform_device_put() on statically allocated platform devices triggers a kernel WARN.
--

commit 3d6b3748275060c9fa53f46ef32bdbc93f8522c7
Author: Guangshuo Li <lgs201920130244@gmail.com>

arm_pmu: acpi: fix reference leak on failed device registration

This commit attempts to fix a reference leak when platform_device_register()
fails in arm_acpi_register_pmu_device() by calling platform_device_put()
on the failed path.

> diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c
> index e80f76d95e68b..5ce382661e344 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) {
> acpi_unregister_gsi(gsi);
> + platform_device_put(pdev);

Does this cause a kernel warning when called on statically allocated platform
devices?

The arm_acpi_register_pmu_device() function is called with statically
allocated platform devices:

arm_spe_acpi_register_device()
arm_acpi_register_pmu_device(&spe_dev, ...)

arm_trbe_acpi_register_device()
arm_acpi_register_pmu_device(&trbe_dev, ...)

Because these devices are statically allocated and not created via
platform_device_alloc(), they do not have a .dev.release callback
configured.

When platform_device_put() drops the reference count to 0, the driver core's
device_release() function will see the missing release callback and trigger
a warning splat.

On systems with panic_on_warn enabled, could this turn a benign device
registration failure into a kernel panic?

> + }
>
> return ret;
> }

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260415174159.3625777-1-lgs201920130244@gmail.com?part=1