From: Johan Hovold <johan@kernel.org>
To: Geoff Levand <geoff@infradead.org>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>,
Christophe Leroy <chleroy@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Johan Hovold <johan@kernel.org>
Subject: [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus root device
Date: Fri, 24 Apr 2026 18:02:58 +0200 [thread overview]
Message-ID: <20260424160259.2672722-3-johan@kernel.org> (raw)
In-Reply-To: <20260424160259.2672722-1-johan@kernel.org>
Driver core expects devices to be dynamically allocated and will, for
example, complain loudly if a device that lacks a release function is
ever freed.
Use root_device_register() to allocate and register the root device
instead of open coding using a static device.
Also add the missing sanity check when registering ibmebus devices to
avoid use-after-free if the bus failed to register (which would
previously have triggered a bunch of use-after-free warnings).
Signed-off-by: Johan Hovold <johan@kernel.org>
---
arch/powerpc/platforms/pseries/ibmebus.c | 39 ++++++++++++++----------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/ibmebus.c b/arch/powerpc/platforms/pseries/ibmebus.c
index cad2deb7e70d..f2064e0b975d 100644
--- a/arch/powerpc/platforms/pseries/ibmebus.c
+++ b/arch/powerpc/platforms/pseries/ibmebus.c
@@ -51,9 +51,7 @@
#include <asm/ibmebus.h>
#include <asm/machdep.h>
-static struct device ibmebus_bus_device = { /* fake "parent" device */
- .init_name = "ibmebus",
-};
+static struct device *ibmebus_bus_device; /* fake "parent" device */
const struct bus_type ibmebus_bus_type;
@@ -171,7 +169,10 @@ static int ibmebus_create_device(struct device_node *dn)
struct platform_device *dev;
int ret;
- dev = of_device_alloc(dn, NULL, &ibmebus_bus_device);
+ if (!ibmebus_bus_device)
+ return -ENOENT;
+
+ dev = of_device_alloc(dn, NULL, ibmebus_bus_device);
if (!dev)
return -ENOMEM;
@@ -447,6 +448,7 @@ EXPORT_SYMBOL(ibmebus_bus_type);
static int __init ibmebus_bus_init(void)
{
+ struct device *root;
int err;
printk(KERN_INFO "IBM eBus Device Driver\n");
@@ -458,23 +460,28 @@ static int __init ibmebus_bus_init(void)
return err;
}
- err = device_register(&ibmebus_bus_device);
- if (err) {
- printk(KERN_WARNING "%s: device_register returned %i\n",
+ root = root_device_register("ibmebus");
+ if (IS_ERR(root)) {
+ err = PTR_ERR(root);
+ printk(KERN_WARNING "%s: root_device_register returned %i\n",
__func__, err);
- put_device(&ibmebus_bus_device);
- bus_unregister(&ibmebus_bus_type);
-
- return err;
+ goto err_deregister_bus;
}
+ ibmebus_bus_device = root;
+
err = ibmebus_create_devices(ibmebus_matches);
- if (err) {
- device_unregister(&ibmebus_bus_device);
- bus_unregister(&ibmebus_bus_type);
- return err;
- }
+ if (err)
+ goto err_deregister_root;
return 0;
+
+err_deregister_root:
+ ibmebus_bus_device = NULL;
+ root_device_unregister(root);
+err_deregister_bus:
+ bus_unregister(&ibmebus_bus_type);
+
+ return err;
}
machine_postcore_initcall(pseries, ibmebus_bus_init);
--
2.53.0
next prev parent reply other threads:[~2026-04-24 16:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 16:02 [PATCH v2 0/3] powerpc: switch to dynamic root devices Johan Hovold
2026-04-24 16:02 ` [PATCH v2 1/3] powerpc/ps3: switch to dynamic system bus root device Johan Hovold
2026-04-24 16:02 ` Johan Hovold [this message]
2026-04-24 16:02 ` [PATCH v2 3/3] powerpc/pseries: clean up ibmebus printks Johan Hovold
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=20260424160259.2672722-3-johan@kernel.org \
--to=johan@kernel.org \
--cc=chleroy@kernel.org \
--cc=geoff@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
/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