Skip to content

platform: fix reference leak on failed platform_device_register()

Vastargazing chrome-platform linux-arm-kernel linux-mtd linux-perf-users lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5misc: eeprom: digsy_mtc: fix reference leak on failed device registrationdrivers/misc/eeprom/digsy_mtc_eeprom.c+3 -10 replies
2/5platform/chrome: cros_ec_lpc: fix reference leak on failed device registrationdrivers/platform/chrome/cros_ec_lpc.c+1 -01 reply
3/5mtd: maps: physmap: fix reference leak on failed device registrationdrivers/mtd/maps/physmap-core.c+3 -11 reply
4/5perf: arm: pmu: fix reference leak on failed device registrationdrivers/perf/arm_pmu_acpi.c+3 -11 reply
5/5mfd: sm501: fix reference leak on failed device registrationdrivers/mfd/sm501.c+3 -17 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] platform: fix reference leak on failed platform_device_register()

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(-)
Signature · 1 line
2.51.0