block: rbd: switch to dynamic root device
Subsystems (2)
PATCH 1/1 block: rbd: switch to dynamic root device
Driver core expects devices to be dynamically allocated and will, for example, complain loudly when no release function has been provided.
Use root_device_register() to allocate and register the root device instead of open coding using a static device.
--- drivers/block/rbd.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/block/rbd.c +7 -16
@@ -580,14 +580,7 @@ static const struct bus_type rbd_bus_type = { .bus_groups = rbd_bus_groups, }; -static void rbd_root_dev_release (struct device *dev) -{ -} - -static struct device rbd_root_dev = { - .init_name ="rbd" , - .release = rbd_root_dev_release, -}; +static struct device *rbd_root_dev; static __printf(2, 3) void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)
@@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec) rbd_dev->dev.bus = &rbd_bus_type; rbd_dev->dev.type = &rbd_device_type; - rbd_dev->dev.parent = &rbd_root_dev; + rbd_dev->dev.parent = rbd_root_dev;device_initialize (&rbd_dev->dev);return rbd_dev;
@@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void) {int ret; - ret =device_register (&rbd_root_dev); -if (ret <0 ) { -put_device (&rbd_root_dev); -return ret; - } + rbd_root_dev =root_device_register ("rbd" ); +if (IS_ERR (rbd_root_dev)) +return PTR_ERR (rbd_root_dev); ret =bus_register (&rbd_bus_type);if (ret <0 ) -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev);return ret; }
@@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void) static void __exit rbd_sysfs_cleanup(void) {bus_unregister (&rbd_bus_type); -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev); }static int __init rbd_slab_init (void )
Signature · 1 line
2.53.0
Quoted 5 lines · Johan Hovold
Driver core expects devices to be dynamically allocated and will, for example, complain loudly when no release function has been provided.
Use
root_device_register()to allocate and register the root device instead of open coding using a static device.
I think the approach makes sense. Ilya, what do you think? Do we have any objection?
Quoted 42 lines
Signed-off-by Johan Hovold <[email protected]>--- drivers/block/rbd.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)drivers/block/rbd.c +2
-12@@ -580,14 +580,7 @@ static const struct bus_type rbd_bus_type = { .bus_groups = rbd_bus_groups, }; -static void rbd_root_dev_release (struct device *dev) -{ -} - -static struct device rbd_root_dev = { - .init_name ="rbd" , - .release = rbd_root_dev_release, -}; +static struct device *rbd_root_dev; static __printf(2, 3) void rbd_warn(struct rbd_device *rbd_dev, const char *fmt, ...)@@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec) rbd_dev->dev.bus = &rbd_bus_type; rbd_dev->dev.type = &rbd_device_type; - rbd_dev->dev.parent = &rbd_root_dev; + rbd_dev->dev.parent = rbd_root_dev;device_initialize (&rbd_dev->dev);return rbd_dev;@@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void) {int ret; - ret =device_register (&rbd_root_dev); -if (ret <0 ) { -put_device (&rbd_root_dev);
drivers/block/rbd.c static int __init rbd_sysfs_init(void) · line 7333
Quoted 10 lines
drivers/block/rbd.c +4
-3-return ret; - } + rbd_root_dev =root_device_register ("rbd" ); +if (IS_ERR (rbd_root_dev)) +return PTR_ERR (rbd_root_dev); ret =bus_register (&rbd_bus_type);if (ret <0 ) -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev);
I think we need to assign NULL here:
rbd_root_dev = NULL;
drivers/block/rbd.c static int __init rbd_sysfs_init(void) · line 7341
Quoted 9 lines
drivers/block/rbd.c +1
-1return ret; }@@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void) static void __exit rbd_sysfs_cleanup(void) {bus_unregister (&rbd_bus_type); -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev);
The same issue here:
rbd_root_dev = NULL;
Thanks,
Slava.
Quoted 3 lines
drivers/block/rbd.c +0
-0}static int __init rbd_slab_init (void )
Quoted 29 lines · Viacheslav Dubeyko
Quoted 28 lines · Johan Hovold
Driver core expects devices to be dynamically allocated and will, for example, complain loudly when no release function has been provided.
Use
root_device_register()to allocate and register the root device instead of open coding using a static device.drivers/block/rbd.c +4
-6@@ -5390,7 +5383,7 @@ static struct rbd_device *__rbd_dev_create(struct rbd_spec *spec) rbd_dev->dev.bus = &rbd_bus_type; rbd_dev->dev.type = &rbd_device_type; - rbd_dev->dev.parent = &rbd_root_dev; + rbd_dev->dev.parent = rbd_root_dev;device_initialize (&rbd_dev->dev);return rbd_dev;@@ -7331,15 +7324,13 @@ static int __init rbd_sysfs_init(void) {int ret; - ret =device_register (&rbd_root_dev); -if (ret <0 ) { -put_device (&rbd_root_dev); -return ret; - } + rbd_root_dev =root_device_register ("rbd" ); +if (IS_ERR (rbd_root_dev)) +return PTR_ERR (rbd_root_dev);
Quoted 8 lines
drivers/block/rbd.c static int __init rbd_sysfs_init(void) · line 7333
Quoted 4 lines
drivers/block/rbd.c +1
-1ret =bus_register (&rbd_bus_type);if (ret <0 ) -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev);I think we need to assign NULL here:
rbd_root_dev= NULL;
From what I can tell these devices are only created from the bus sysfs attribute so this pointer will not be accessed if bus registration fails and there is no need to clear it (or add a sanity check to __rbd_dev_create()).
Quoted 11 lines
drivers/block/rbd.c static int __init rbd_sysfs_init(void) · line 7341
Quoted 8 lines
drivers/block/rbd.c +1
-1return ret; }@@ -7347,7 +7338,7 @@ static int __init rbd_sysfs_init(void) static void __exit rbd_sysfs_cleanup(void) {bus_unregister (&rbd_bus_type); -device_unregister (&rbd_root_dev); +root_device_unregister (rbd_root_dev);The same issue here:
Quoted 1 line
rbd_root_dev= NULL;
So this is not needed either.
Johan