mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Guangshuo Li <lgs201920130244@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Linus Walleij <linusw@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH] eeprom: digsy_mtc: fix reference leak on failed device registration
Date: Thu, 16 Apr 2026 00:52:02 +0800	[thread overview]
Message-ID: <20260415165203.3584869-1-lgs201920130244@gmail.com> (raw)

When platform_device_register() fails in digsy_mtc_eeprom_devices_init(),
the embedded struct device in digsy_mtc_eeprom has already been
initialized by device_initialize(), but the failure path only removes
the software node and does not drop the device reference for the current
platform device:

  digsy_mtc_eeprom_devices_init()
    -> platform_device_register(&digsy_mtc_eeprom)
       -> device_initialize(&digsy_mtc_eeprom.dev)
       -> setup_pdev_dma_masks(&digsy_mtc_eeprom)
       -> platform_device_add(&digsy_mtc_eeprom)

This leads to a reference leak when platform_device_register() fails.
Fix this by calling platform_device_put() after removing the software
node.

The issue was identified by a static analysis tool I developed and
confirmed by manual review.

Fixes: c8ed97d8c3984 ("eeprom: digsy_mtc: Convert to use GPIO descriptors")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@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..54fcbdc0412a 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) {
 		device_remove_software_node(&digsy_mtc_eeprom.dev);
+		platform_device_put(&digsy_mtc_eeprom);
+	}
 
 	return ret;
 }
-- 
2.43.0


             reply	other threads:[~2026-04-15 16:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 16:52 Guangshuo Li [this message]
2026-04-16  7:52 ` Andy Shevchenko
2026-04-24  8:21   ` Guangshuo Li
2026-04-24  8:36     ` Andy Shevchenko

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=20260415165203.3584869-1-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®