* [PATCH v2 0/3] powerpc: switch to dynamic root devices
@ 2026-04-24 16:02 Johan Hovold
2026-04-24 16:02 ` [PATCH v2 1/3] powerpc/ps3: switch to dynamic system bus root device Johan Hovold
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Johan Hovold @ 2026-04-24 16:02 UTC (permalink / raw)
To: Geoff Levand, Madhavan Srinivasan, Michael Ellerman
Cc: Nicholas Piggin, Christophe Leroy, Greg Kroah-Hartman,
linuxppc-dev, linux-kernel, Johan Hovold
This series replaces static root devices with dynamically allocated
ones. Included is also a related printk cleanup.
Johan
Changes in v2:
- only set ibmebus root pointer on successful registration
- add sanity check when registering ibmebus devices to avoid
use-after-free if ibmebus_register_driver() is called after the bus
failed to register (Sashiko flagged this path which I had missed)
Johan Hovold (3):
powerpc/ps3: switch to dynamic system bus root device
powerpc/pseries: switch to dynamic ibmebus root device
powerpc/pseries: clean up ibmebus printks
arch/powerpc/platforms/ps3/system-bus.c | 10 ++---
arch/powerpc/platforms/pseries/ibmebus.c | 57 ++++++++++++------------
2 files changed, 33 insertions(+), 34 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] powerpc/ps3: switch to dynamic system bus root device
2026-04-24 16:02 [PATCH v2 0/3] powerpc: switch to dynamic root devices Johan Hovold
@ 2026-04-24 16:02 ` Johan Hovold
2026-04-24 16:02 ` [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus " Johan Hovold
2026-04-24 16:02 ` [PATCH v2 3/3] powerpc/pseries: clean up ibmebus printks Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-04-24 16:02 UTC (permalink / raw)
To: Geoff Levand, Madhavan Srinivasan, Michael Ellerman
Cc: Nicholas Piggin, Christophe Leroy, Greg Kroah-Hartman,
linuxppc-dev, linux-kernel, Johan Hovold
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.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
arch/powerpc/platforms/ps3/system-bus.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
index 0537a678a32f..4ead6ccea259 100644
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -20,9 +20,7 @@
#include "platform.h"
-static struct device ps3_system_bus = {
- .init_name = "ps3_system",
-};
+static struct device *ps3_system_bus;
/* FIXME: need device usage counters! */
static struct {
@@ -486,8 +484,8 @@ static int __init ps3_system_bus_init(void)
mutex_init(&usage_hack.mutex);
- result = device_register(&ps3_system_bus);
- BUG_ON(result);
+ ps3_system_bus = root_device_register("ps3_system");
+ BUG_ON(IS_ERR(ps3_system_bus));
result = bus_register(&ps3_system_bus_type);
BUG_ON(result);
@@ -744,7 +742,7 @@ int ps3_system_bus_device_register(struct ps3_system_bus_device *dev)
static unsigned int dev_lpm_count;
if (!dev->core.parent)
- dev->core.parent = &ps3_system_bus;
+ dev->core.parent = ps3_system_bus;
dev->core.bus = &ps3_system_bus_type;
dev->core.release = ps3_system_bus_release_device;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus root device
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
2026-04-24 16:02 ` [PATCH v2 3/3] powerpc/pseries: clean up ibmebus printks Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-04-24 16:02 UTC (permalink / raw)
To: Geoff Levand, Madhavan Srinivasan, Michael Ellerman
Cc: Nicholas Piggin, Christophe Leroy, Greg Kroah-Hartman,
linuxppc-dev, linux-kernel, Johan Hovold
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] powerpc/pseries: clean up ibmebus printks
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 ` [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus " Johan Hovold
@ 2026-04-24 16:02 ` Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2026-04-24 16:02 UTC (permalink / raw)
To: Geoff Levand, Madhavan Srinivasan, Michael Ellerman
Cc: Nicholas Piggin, Christophe Leroy, Greg Kroah-Hartman,
linuxppc-dev, linux-kernel, Johan Hovold
Clean up the imbebus printks by switching to pr_warn() and pr_err(),
adding a missing newline and making the error messages a bit more
uniform.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
arch/powerpc/platforms/pseries/ibmebus.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/ibmebus.c b/arch/powerpc/platforms/pseries/ibmebus.c
index f2064e0b975d..24c3ec76b0c1 100644
--- a/arch/powerpc/platforms/pseries/ibmebus.c
+++ b/arch/powerpc/platforms/pseries/ibmebus.c
@@ -206,8 +206,7 @@ static int ibmebus_create_devices(const struct of_device_id *matches)
ret = ibmebus_create_device(child);
if (ret) {
- printk(KERN_ERR "%s: failed to create device (%i)",
- __func__, ret);
+ pr_err("%s: failed to create device: %d\n", __func__, ret);
of_node_put(child);
break;
}
@@ -285,8 +284,7 @@ static ssize_t probe_store(const struct bus_type *bus, const char *buf, size_t c
ibmebus_match_path);
if (dev) {
put_device(dev);
- printk(KERN_WARNING "%s: %s has already been probed\n",
- __func__, path);
+ pr_warn("%s: %s has already been probed\n", __func__, path);
rc = -EEXIST;
goto out;
}
@@ -295,8 +293,7 @@ static ssize_t probe_store(const struct bus_type *bus, const char *buf, size_t c
rc = ibmebus_create_device(dn);
of_node_put(dn);
} else {
- printk(KERN_WARNING "%s: no such device node: %s\n",
- __func__, path);
+ pr_warn("%s: no such device node: %s\n", __func__, path);
rc = -ENODEV;
}
@@ -325,8 +322,7 @@ static ssize_t remove_store(const struct bus_type *bus, const char *buf, size_t
kfree(path);
return count;
} else {
- printk(KERN_WARNING "%s: %s not on the bus\n",
- __func__, path);
+ pr_warn("%s: %s not on the bus\n", __func__, path);
kfree(path);
return -ENODEV;
@@ -451,20 +447,18 @@ static int __init ibmebus_bus_init(void)
struct device *root;
int err;
- printk(KERN_INFO "IBM eBus Device Driver\n");
+ pr_info("IBM eBus Device Driver\n");
err = bus_register(&ibmebus_bus_type);
if (err) {
- printk(KERN_ERR "%s: failed to register IBM eBus.\n",
- __func__);
+ pr_err("%s: failed to register IBM eBus\n", __func__);
return err;
}
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);
+ pr_err("%s: failed to register root device: %d\n", __func__, err);
goto err_deregister_bus;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-24 16:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus " Johan Hovold
2026-04-24 16:02 ` [PATCH v2 3/3] powerpc/pseries: clean up ibmebus printks Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox