The driver core only calls a remove callback when the device was
successfully bound (aka probed) before. So dev->driver is never NULL and
the respective check can just be dropped.
Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/nubus/bus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
index d9d04f27f89b..17fad660032c 100644
--- a/drivers/nubus/bus.c
+++ b/drivers/nubus/bus.c
@@ -33,7 +33,7 @@ static void nubus_device_remove(struct device *dev)
{
struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
- if (dev->driver && ndrv->remove)
+ if (ndrv->remove)
ndrv->remove(to_nubus_board(dev));
}
--
2.30.2
On Fri, 30 Jul 2021, Uwe Kleine-König wrote:
> The driver core only calls a remove callback when the device was
> successfully bound (aka probed) before. So dev->driver is never NULL and
> the respective check can just be dropped.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
Acked-by: Finn Thain <[email protected]>
BTW, aside from nubus, zorro and superhyway you can find the same pattern
in many other busses. You may want to patch the following methods too.
acpi_device_remove
apr_device_remove
ccwgroup_remove
gio_device_remove
hid_device_remove
ibmebus_bus_device_remove
macio_device_remove
memstick_device_remove
ntb_remove
pci_device_remove
pnp_device_remove
ps3_system_bus_remove
rio_device_remove
slim_device_remove
soundbus_device_remove
ssb_device_remove
tifm_device_remove
vdpa_dev_remove
vmbus_remove
> ---
> drivers/nubus/bus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nubus/bus.c b/drivers/nubus/bus.c
> index d9d04f27f89b..17fad660032c 100644
> --- a/drivers/nubus/bus.c
> +++ b/drivers/nubus/bus.c
> @@ -33,7 +33,7 @@ static void nubus_device_remove(struct device *dev)
> {
> struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
>
> - if (dev->driver && ndrv->remove)
> + if (ndrv->remove)
> ndrv->remove(to_nubus_board(dev));
> }
>
>
Hello Finn,
On Sun, Aug 01, 2021 at 03:04:03PM +1000, Finn Thain wrote:
> On Fri, 30 Jul 2021, Uwe Kleine-K?nig wrote:
>
> > The driver core only calls a remove callback when the device was
> > successfully bound (aka probed) before. So dev->driver is never NULL and
> > the respective check can just be dropped.
> >
> > Signed-off-by: Uwe Kleine-K?nig <[email protected]>
>
> Acked-by: Finn Thain <[email protected]>
>
> BTW, aside from nubus, zorro and superhyway you can find the same pattern
> in many other busses. You may want to patch the following methods too.
>
> acpi_device_remove
> apr_device_remove
> ccwgroup_remove
> gio_device_remove
> hid_device_remove
> ibmebus_bus_device_remove
> macio_device_remove
> memstick_device_remove
> ntb_remove
> pci_device_remove
> pnp_device_remove
> ps3_system_bus_remove
> rio_device_remove
> slim_device_remove
> soundbus_device_remove
> ssb_device_remove
> tifm_device_remove
> vdpa_dev_remove
> vmbus_remove
Did you find these by hand? Or using a coccinelle match?
Anyhow, thanks for the list, I'll add it to my todo list but if you're
motivated don't consider these cleanups as my property. (Please Cc: me
though to prevent duplicated effort.)
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | https://www.pengutronix.de/ |
On Mon, 2 Aug 2021, Uwe Kleine-König wrote:
> >
> > BTW, aside from nubus, zorro and superhyway you can find the same
> > pattern in many other busses. You may want to patch the following
> > methods too.
> >
> > acpi_device_remove
> > apr_device_remove
> > ccwgroup_remove
> > gio_device_remove
> > hid_device_remove
> > ibmebus_bus_device_remove
> > macio_device_remove
> > memstick_device_remove
> > ntb_remove
> > pci_device_remove
> > pnp_device_remove
> > ps3_system_bus_remove
> > rio_device_remove
> > slim_device_remove
> > soundbus_device_remove
> > ssb_device_remove
> > tifm_device_remove
> > vdpa_dev_remove
> > vmbus_remove
>
> Did you find these by hand? Or using a coccinelle match?
>
I used grep and visual inspection.
> Anyhow, thanks for the list, I'll add it to my todo list but if you're
> motivated don't consider these cleanups as my property. (Please Cc: me
> though to prevent duplicated effort.)
>
I went looking for the other examples of this pattern because I wanted to
understand it better. Then I realized that I might as well make a list
since I was searching anyway.
When skimming that code, I took the impression that the dev->driver ==
NULL test probably comes from old code written before the 'remove'
functions became bus methods. See also commit 594c8281f905 ("[PATCH] Add
bus_type probe, remove, shutdown methods.")
Back when I wrote drivers/nubus/bus.c, apparently I copied-and-pasted the
old pattern from drivers/pci/pci-driver.c, even though that pattern was
already obsolete.
So I do see the value in this cleanup but I'm afraid I'm too busy to help
further. If you don't want to finish it perhaps you can get the janitors
to do so.