public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vastargazing <vebohr@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Vastargazing <vebohr@gmail.com>
Subject: [PATCH 0/5] platform: fix reference leak on failed platform_device_register()
Date: Mon,  4 May 2026 13:08:42 +0300	[thread overview]
Message-ID: <cover.1777889235.git.vebohr@gmail.com> (raw)

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


             reply	other threads:[~2026-05-04 10:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-04 10:08 Vastargazing [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1777889235.git.vebohr@gmail.com \
    --to=vebohr@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox