mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: tomeu@tomeuvizoso.net
Cc: heiko@sntech.de, ogabbay@kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Wentao Liang <vulab@iscas.ac.cn>,
	stable@vger.kernel.org
Subject: [PATCH] accel/rocket: Unregister the platform device if driver registration fails
Date: Tue,  3 Nov 2026 06:23:19 +0000	[thread overview]
Message-ID: <20261103062319.1013449-1-vulab@iscas.ac.cn> (raw)

rocket_register() registers the facade platform device before registering
the platform driver. If platform_driver_register() fails, module
initialization returns an error without unregistering the device. The
module exit function is not called after a failed initialization, so the
platform device and its resources remain registered.

Unregister the platform device when driver registration fails.

Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/accel/rocket/rocket_drv.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index 5d7805c41dc3..4ea65d6eec81 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -285,11 +285,17 @@ static struct platform_driver rocket_driver = {
 
 static int __init rocket_register(void)
 {
+	int ret;
+
 	drm_dev = platform_device_register_simple("rknn", -1, NULL, 0);
 	if (IS_ERR(drm_dev))
 		return PTR_ERR(drm_dev);
 
-	return platform_driver_register(&rocket_driver);
+	ret = platform_driver_register(&rocket_driver);
+	if (ret)
+		platform_device_unregister(drm_dev);
+
+	return ret;
 }
 
 static void __exit rocket_unregister(void)
-- 
2.34.1


             reply	other threads:[~2026-11-03  6:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  6:23 Wentao Liang [this message]
2026-11-03  7:11 ` Krzysztof Kozlowski

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=20261103062319.1013449-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=heiko@sntech.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tomeu@tomeuvizoso.net \
    /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®