public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] platform: fix reference leak on failed platform_device_register()
@ 2026-05-04 10:08 Vastargazing
  2026-05-04 10:08 ` [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration Vastargazing
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Vastargazing @ 2026-05-04 10:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: Vastargazing

platform_device_register() calls device_initialize() before
platform_device_add(). If platform_device_add() fails, device_initialize()
has already set the struct device kref to 1, and the kref must be released
via platform_device_put(). The kernel-doc for platform_device_register()
states this explicitly:

  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.

This series fixes five drivers that call platform_device_register() and
return the error code without calling platform_device_put() on the failure
path. The pattern was identified by Coccinelle static analysis, confirmed
by manual inspection, and is analogous to the recently merged fix in
commit 4ff036f95238 ("ALSA: pcmtest: fix reference leak on failed device
registration").

Sites fixed:
  drivers/misc/eeprom/digsy_mtc_eeprom.c
  drivers/platform/chrome/cros_ec_lpc.c
  drivers/mtd/maps/physmap-core.c
  drivers/perf/arm_pmu_acpi.c
  drivers/mfd/sm501.c

Build tested on x86 defconfig:
  - digsy_mtc_eeprom.c: compiled cleanly
  - cros_ec_lpc.c:       compiled cleanly
  - sm501.c:             compiled cleanly
  - physmap-core.c:      pre-existing Werror in map.h header (unrelated)
  - arm_pmu_acpi.c:      ARM-only, no asm/cputype.h on x86

Vastargazing (5):
  misc: eeprom: digsy_mtc: fix reference leak on failed device
    registration
  platform/chrome: cros_ec_lpc: fix reference leak on failed device
    registration
  mtd: maps: physmap: fix reference leak on failed device registration
  perf: arm: pmu: fix reference leak on failed device registration
  mfd: sm501: fix reference leak on failed device registration

 drivers/mfd/sm501.c                    | 4 +++-
 drivers/misc/eeprom/digsy_mtc_eeprom.c | 4 +++-
 drivers/mtd/maps/physmap-core.c        | 4 +++-
 drivers/perf/arm_pmu_acpi.c            | 4 +++-
 drivers/platform/chrome/cros_ec_lpc.c  | 1 +
 5 files changed, 13 insertions(+), 4 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-05-05 10:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-05  2:40   ` Tzung-Bi Shih
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
2026-05-04 13:58   ` Miquel Raynal
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
2026-05-05  8:50   ` Sudeep Holla
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
2026-05-04 12:48   ` [PATCH v2] " Valery Borovsky
2026-05-04 13:52     ` Miquel Raynal
2026-05-05 10:36 ` [PATCH 1/5] perf/arm_pmu_acpi: fix reference leak in arm_pmu_acpi_probe error path Valery Borovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox