mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: Alexander Aring <alex.aring@gmail.com>,
	Stefan Schmidt <stefan@datenfreihafen.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] ieee802154: fakelb: release platform device if driver registration fails
Date: Tue,  3 Nov 2026 10:28:54 +0000	[thread overview]
Message-ID: <20261103102854.1340581-1-vulab@iscas.ac.cn> (raw)

fakelb_init_module() registers a platform device and then registers the
platform driver, returning the result of the latter directly. If driver
registration fails, module initialization fails and the module exit
function is never run, so the platform device is never unregistered and
leaks.

Check the result of platform_driver_register() and unregister the device
on failure. Also check the device registration result, which can be an
ERR_PTR, before using the stored pointer.

Fixes: e1e49b641387 ("drivers/ieee802154: IEEE 802.15.4 loopback driver")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/net/ieee802154/fakelb.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ieee802154/fakelb.c b/drivers/net/ieee802154/fakelb.c
index e11d8eda85ea..35863c3aff44 100644
--- a/drivers/net/ieee802154/fakelb.c
+++ b/drivers/net/ieee802154/fakelb.c
@@ -243,12 +243,20 @@ static struct platform_driver ieee802154fake_driver = {
 
 static __init int fakelb_init_module(void)
 {
+	int rc;
+
 	ieee802154fake_dev = platform_device_register_simple(
 			     "ieee802154fakelb", -1, NULL, 0);
+	if (IS_ERR(ieee802154fake_dev))
+		return PTR_ERR(ieee802154fake_dev);
 
 	pr_warn("fakelb driver is marked as deprecated, please use mac802154_hwsim!\n");
 
-	return platform_driver_register(&ieee802154fake_driver);
+	rc = platform_driver_register(&ieee802154fake_driver);
+	if (rc)
+		platform_device_unregister(ieee802154fake_dev);
+
+	return rc;
 }
 
 static __exit void fake_remove_module(void)
-- 
2.34.1


             reply	other threads:[~2026-11-03 10:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 10:28 Wentao Liang [this message]
2026-11-03 10:33 ` netdev-bot+sinfo

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=20261103102854.1340581-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=alex.aring@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=stefan@datenfreihafen.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®