siox: Use bus_type functions for probe, remove and shutdown
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 25 Nov 2020 09:31:05 +0000 (10:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Dec 2020 15:17:15 +0000 (16:17 +0100)
The eventual goal is to get rid of the callbacks in struct
device_driver.

Tested-by: Thorsten Scherer <t.scherer@eckelmann.de>
Acked-by: Thorsten Scherer <t.scherer@eckelmann.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20201125093106.240643-2-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/siox/siox-core.c

index f8c08fb..b56cdcb 100644 (file)
@@ -512,41 +512,48 @@ static int siox_match(struct device *dev, struct device_driver *drv)
        return 1;
 }
 
-static struct bus_type siox_bus_type = {
-       .name = "siox",
-       .match = siox_match,
-};
-
-static int siox_driver_probe(struct device *dev)
+static int siox_probe(struct device *dev)
 {
        struct siox_driver *sdriver = to_siox_driver(dev->driver);
        struct siox_device *sdevice = to_siox_device(dev);
-       int ret;
 
-       ret = sdriver->probe(sdevice);
-       return ret;
+       return sdriver->probe(sdevice);
 }
 
-static int siox_driver_remove(struct device *dev)
+static int siox_remove(struct device *dev)
 {
        struct siox_driver *sdriver =
                container_of(dev->driver, struct siox_driver, driver);
        struct siox_device *sdevice = to_siox_device(dev);
-       int ret;
+       int ret = 0;
+
+       if (sdriver->remove)
+               ret = sdriver->remove(sdevice);
 
-       ret = sdriver->remove(sdevice);
        return ret;
 }
 
-static void siox_driver_shutdown(struct device *dev)
+static void siox_shutdown(struct device *dev)
 {
-       struct siox_driver *sdriver =
-               container_of(dev->driver, struct siox_driver, driver);
        struct siox_device *sdevice = to_siox_device(dev);
+       struct siox_driver *sdriver;
 
-       sdriver->shutdown(sdevice);
+       if (!dev->driver)
+               return;
+
+       sdriver = container_of(dev->driver, struct siox_driver, driver);
+       if (sdriver->shutdown)
+               sdriver->shutdown(sdevice);
 }
 
+static struct bus_type siox_bus_type = {
+       .name = "siox",
+       .match = siox_match,
+       .probe = siox_probe,
+       .remove = siox_remove,
+       .shutdown = siox_shutdown,
+};
+
 static ssize_t active_show(struct device *dev,
                           struct device_attribute *attr, char *buf)
 {
@@ -882,7 +889,8 @@ int __siox_driver_register(struct siox_driver *sdriver, struct module *owner)
        if (unlikely(!siox_is_registered))
                return -EPROBE_DEFER;
 
-       if (!sdriver->set_data && !sdriver->get_data) {
+       if (!sdriver->probe ||
+           (!sdriver->set_data && !sdriver->get_data)) {
                pr_err("Driver %s doesn't provide needed callbacks\n",
                       sdriver->driver.name);
                return -EINVAL;
@@ -891,13 +899,6 @@ int __siox_driver_register(struct siox_driver *sdriver, struct module *owner)
        sdriver->driver.owner = owner;
        sdriver->driver.bus = &siox_bus_type;
 
-       if (sdriver->probe)
-               sdriver->driver.probe = siox_driver_probe;
-       if (sdriver->remove)
-               sdriver->driver.remove = siox_driver_remove;
-       if (sdriver->shutdown)
-               sdriver->driver.shutdown = siox_driver_shutdown;
-
        ret = driver_register(&sdriver->driver);
        if (ret)
                pr_err("Failed to register siox driver %s (%d)\n",