From: Vastargazing <vebohr@gmail.com>
To: vebohr@gmail.com
Cc: stable@vger.kernel.org
Subject: [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration
Date: Mon, 4 May 2026 13:08:16 +0300 [thread overview]
Message-ID: <a6778ce2d2e906e6f8a7c811e5faf4a8c56aff11.1777889235.git.vebohr@gmail.com> (raw)
In-Reply-To: <cover.1777889235.git.vebohr@gmail.com>
When platform_device_register() fails in digsy_mtc_eeprom_devices_init(),
the embedded struct device has already been initialized by
device_initialize() inside platform_device_register(). The failure path
cleans up the software node but returns the error without dropping the
device reference:
digsy_mtc_eeprom_devices_init()
-> platform_device_register(&digsy_mtc_eeprom)
-> device_initialize(&digsy_mtc_eeprom.dev) /* kref = 1 */
-> platform_device_add(&digsy_mtc_eeprom) /* fails */
<- returns error, kref still 1, reference leaked
Per platform_device_register() kernel-doc:
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.
Fix this by calling platform_device_put() in the error branch before
removing the software node.
Fixes: 469dded18391 ("misc/eeprom: add eeprom access driver for digsy_mtc board")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/misc/eeprom/digsy_mtc_eeprom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index ee58f7ce5bfa..4ca3e567c49d 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -89,8 +89,10 @@ static int __init digsy_mtc_eeprom_devices_init(void)
return ret;
ret = platform_device_register(&digsy_mtc_eeprom);
- if (ret)
+ if (ret) {
+ platform_device_put(&digsy_mtc_eeprom);
device_remove_software_node(&digsy_mtc_eeprom.dev);
+ }
return ret;
}
--
2.51.0
WARNING: multiple messages have this Message-ID (diff)
From: Vastargazing <vebohr@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Vastargazing <vebohr@gmail.com>,
stable@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Anatolij Gustschin <agust@denx.de>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 1/5] misc: eeprom: digsy_mtc: fix reference leak on failed device registration
Date: Mon, 4 May 2026 13:08:43 +0300 [thread overview]
Message-ID: <a6778ce2d2e906e6f8a7c811e5faf4a8c56aff11.1777889235.git.vebohr@gmail.com> (raw)
Message-ID: <20260504100843.W81H1e2262D_DzGBRcPBNrchzSNmdPqNKg9ihCj9kVE@z> (raw)
In-Reply-To: <cover.1777889235.git.vebohr@gmail.com>
When platform_device_register() fails in digsy_mtc_eeprom_devices_init(),
the embedded struct device has already been initialized by
device_initialize() inside platform_device_register(). The failure path
cleans up the software node but returns the error without dropping the
device reference:
digsy_mtc_eeprom_devices_init()
-> platform_device_register(&digsy_mtc_eeprom)
-> device_initialize(&digsy_mtc_eeprom.dev) /* kref = 1 */
-> platform_device_add(&digsy_mtc_eeprom) /* fails */
<- returns error, kref still 1, reference leaked
Per platform_device_register() kernel-doc:
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.
Fix this by calling platform_device_put() in the error branch before
removing the software node.
Fixes: 469dded18391 ("misc/eeprom: add eeprom access driver for digsy_mtc board")
Cc: stable@vger.kernel.org
Assisted-by: GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Vastargazing <vebohr@gmail.com>
---
drivers/misc/eeprom/digsy_mtc_eeprom.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c
index ee58f7ce5bfa..4ca3e567c49d 100644
--- a/drivers/misc/eeprom/digsy_mtc_eeprom.c
+++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c
@@ -89,8 +89,10 @@ static int __init digsy_mtc_eeprom_devices_init(void)
return ret;
ret = platform_device_register(&digsy_mtc_eeprom);
- if (ret)
+ if (ret) {
+ platform_device_put(&digsy_mtc_eeprom);
device_remove_software_node(&digsy_mtc_eeprom.dev);
+ }
return ret;
}
--
2.51.0
next parent reply other threads:[~2026-05-04 10:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1777889235.git.vebohr@gmail.com>
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-04 10:08 ` Vastargazing
2026-05-05 2:40 ` Tzung-Bi Shih
2026-05-04 10:08 ` [PATCH 3/5] mtd: maps: physmap: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-04 13:58 ` Miquel Raynal
2026-05-04 10:08 ` [PATCH 4/5] perf: arm: pmu: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-05 8:50 ` Sudeep Holla
2026-05-04 10:08 ` [PATCH 5/5] mfd: sm501: " Vastargazing
2026-05-04 10:08 ` Vastargazing
2026-05-04 12:48 ` [PATCH v2] " Valery Borovsky
2026-05-04 13:52 ` Miquel Raynal
2026-05-05 15:00 ` Lee Jones
2026-05-05 15:12 ` Miquel Raynal
2026-05-06 15:40 ` [PATCH v3] " Valery Borovsky
2026-05-06 15:43 ` [PATCH 3/5] mtd: maps: physmap-core: " Valery Borovsky
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=a6778ce2d2e906e6f8a7c811e5faf4a8c56aff11.1777889235.git.vebohr@gmail.com \
--to=vebohr@gmail.com \
--cc=stable@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