locomo: make locomo_bus_type constant and static
PATCH 1/1 locomo: make locomo_bus_type constant and static
Now that the driver core can properly handle constant struct bus_type, move the locomo_bus_type variable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.
It's also never used outside of arch/arm/common/locomo.c so make it static and don't export it as no one is using it.
--- arch/arm/common/locomo.c | 4 +++- arch/arm/include/asm/hardware/locomo.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/common/locomo.c +3 -1
@@ -68,6 +68,8 @@ struct locomo {#endif }; +static const struct bus_type locomo_bus_type; +struct locomo_dev_info {unsigned long offset;unsigned long length;
@@ -842,7 +844,7 @@ static void locomo_bus_remove(struct device *dev) drv->remove (ldev); } -struct bus_type locomo_bus_type = { +static const struct bus_type locomo_bus_type = { .name ="locomo-bus" , .match = locomo_match, .probe = locomo_bus_probe,
arch/arm/include/asm/hardware/locomo.h +0 -2
@@ -158,8 +158,6 @@#define LOCOMO_LPT_TOH (TOH ) ((TOH & 0x7) << 4)#define LOCOMO_LPT_TOL (TOL ) ((TOL & 0x7)) -extern struct bus_type locomo_bus_type; -#define LOCOMO_DEVID_KEYBOARD 0#define LOCOMO_DEVID_FRONTLIGHT 1#define LOCOMO_DEVID_BACKLIGHT 2
Signature · 1 line
2.43.0
Quoted 6 lines · Greg Kroah-Hartman
Now that the driver core can properly handle constant struct
bus_type, move thelocomo_bus_typevariable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.It's also never used outside of
arch/arm/common/locomo.cso make it static and don't export it as no one is using it.
Quoted 23 lines · Greg Kroah-Hartman
Now that the driver core can properly handle constant struct
bus_type, move thelocomo_bus_typevariable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.It's also never used outside of
arch/arm/common/locomo.cso make it static and don't export it as no one is using it.Cc Russell King <[email protected]>Cc Arnd Bergmann <[email protected]>Cc "Uwe Kleine-König" <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- arch/arm/common/locomo.c | 4 +++- arch/arm/include/asm/hardware/locomo.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-)arch/arm/common/locomo.c +0
-0
arch/arm/common/locomo.c struct locomo { · line 72
Quoted 5 lines
arch/arm/common/locomo.c +2
-0@@ -68,6 +68,8 @@ struct locomo {#endif }; +static const struct bus_type locomo_bus_type; +
If you move up locomo_bus_type together with its three callbacks before locomo_init_one_child, you don't need the extra declaration here.
That would be:
arch/arm/common/locomo.c +41 -43
@@ -68,8 +68,6 @@ struct locomo {#endif }; -static const struct bus_type locomo_bus_type; -struct locomo_dev_info {unsigned long offset;unsigned long length;
@@ -216,6 +214,47 @@ static void locomo_dev_release(struct device *_dev)kfree (dev); } +/* +* LoCoMo "Register Access Bus." +* +* We model this as a regular bus type, and hang devices directly +* off this. +*/ +static int locomo_match (struct device *_dev,struct device_driver *_drv) +{ +struct locomo_dev *dev =LOCOMO_DEV (_dev); +struct locomo_driver *drv =LOCOMO_DRV (_drv); + +return dev->devid == drv->devid; +} + +static int locomo_bus_probe (struct device *dev) +{ +struct locomo_dev *ldev =LOCOMO_DEV (dev); +struct locomo_driver *drv =LOCOMO_DRV (dev->driver); +int ret = -ENODEV ; + +if (drv->probe) + ret = drv->probe (ldev); +return ret; +} + +static void locomo_bus_remove (struct device *dev) +{ +struct locomo_dev *ldev =LOCOMO_DEV (dev); +struct locomo_driver *drv =LOCOMO_DRV (dev->driver); + +if (drv->remove) + drv->remove (ldev); +} + +static const struct bus_type locomo_bus_type = { + .name ="locomo-bus" , + .match = locomo_match, + .probe = locomo_bus_probe, + .remove = locomo_bus_remove, +}; +static int locomo_init_one_child (struct locomo *lchip,struct locomo_dev_info *info) {
@@ -810,47 +849,6 @@ void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf) }EXPORT_SYMBOL (locomo_frontlight_set); -/* -* LoCoMo "Register Access Bus." -* -* We model this as a regular bus type, and hang devices directly -* off this. -*/ -static int locomo_match (struct device *_dev,struct device_driver *_drv) -{ -struct locomo_dev *dev =LOCOMO_DEV (_dev); -struct locomo_driver *drv =LOCOMO_DRV (_drv); - -return dev->devid == drv->devid; -} - -static int locomo_bus_probe (struct device *dev) -{ -struct locomo_dev *ldev =LOCOMO_DEV (dev); -struct locomo_driver *drv =LOCOMO_DRV (dev->driver); -int ret = -ENODEV ; - -if (drv->probe) - ret = drv->probe (ldev); -return ret; -} - -static void locomo_bus_remove (struct device *dev) -{ -struct locomo_dev *ldev =LOCOMO_DEV (dev); -struct locomo_driver *drv =LOCOMO_DRV (dev->driver); - -if (drv->remove) - drv->remove (ldev); -} - -static const struct bus_type locomo_bus_type = { - .name ="locomo-bus" , - .match = locomo_match, - .probe = locomo_bus_probe, - .remove = locomo_bus_remove, -}; -int locomo_driver_register (struct locomo_driver *driver) { driver->drv.bus = &locomo_bus_type;
Feel free to squash this into your patch for a v2 if you like it.
Or is that better done as a separate change on top of yours?
Otherwise looks fine to me.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 27 lines · Uwe Kleine-König
Quoted 26 lines · Greg Kroah-Hartman
Now that the driver core can properly handle constant struct
bus_type, move thelocomo_bus_typevariable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.It's also never used outside of
arch/arm/common/locomo.cso make it static and don't export it as no one is using it.Cc Russell King <[email protected]>Cc Arnd Bergmann <[email protected]>Cc "Uwe Kleine-König" <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- arch/arm/common/locomo.c | 4 +++- arch/arm/include/asm/hardware/locomo.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-)arch/arm/common/locomo.c +0
-0@@ -68,6 +68,8 @@ struct locomo {#endif };
Quoted 5 lines
arch/arm/common/locomo.c struct locomo { · line 72
Quoted 2 lines
arch/arm/common/locomo.c +2
-0+static const struct bus_type locomo_bus_type; +If you move up
locomo_bus_typetogether with its three callbacks beforelocomo_init_one_child, you don't need the extra declaration here.
I was trying to go for "least intrusive and most obvious change possible" here, given that this file hasn't been touched in over a decade by anyone else for anything other than api changes. And even then, it was just a tiny fix, this is a very old driver, what's the odds that it's even used anymore?
thanks,
greg k-h