]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Xen: consolidate and simplify struct xenbus_driver instantiation
authorJan Beulich <JBeulich@suse.com>
Thu, 22 Dec 2011 09:08:13 +0000 (09:08 +0000)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Thu, 2 Feb 2012 19:22:11 +0000 (14:22 -0500)
The 'name', 'owner', and 'mod_name' members are redundant with the
identically named fields in the 'driver' sub-structure. Rather than
switching each instance to specify these fields explicitly, introduce
a macro to simplify this.

Eliminate further redundancy by allowing the drvname argument to
DEFINE_XENBUS_DRIVER() to be blank (in which case the first entry from
the ID table will be used for .driver.name).

Also eliminate the questionable xenbus_register_{back,front}end()
wrappers - their sole remaining purpose was the checking of the
'owner' field, proper setting of which shouldn't be an issue anymore
when the macro gets used.

v2: Restore DRV_NAME for the driver name in xen-pciback.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
13 files changed:
drivers/block/xen-blkback/xenbus.c
drivers/block/xen-blkfront.c
drivers/input/misc/xen-kbdfront.c
drivers/net/xen-netback/xenbus.c
drivers/net/xen-netfront.c
drivers/pci/xen-pcifront.c
drivers/video/xen-fbfront.c
drivers/xen/xen-pciback/xenbus.c
drivers/xen/xenbus/xenbus_probe.c
drivers/xen/xenbus/xenbus_probe.h
drivers/xen/xenbus/xenbus_probe_backend.c
drivers/xen/xenbus/xenbus_probe_frontend.c
include/xen/xenbus.h

index 5b62f519cde579fa712ebcc04438350bb6c19a5f..8be3d31fc32738c968f6a401bf2d26ab23933ac5 100644 (file)
@@ -799,17 +799,14 @@ static const struct xenbus_device_id xen_blkbk_ids[] = {
 };
 
 
-static struct xenbus_driver xen_blkbk = {
-       .name = "vbd",
-       .owner = THIS_MODULE,
-       .ids = xen_blkbk_ids,
+static DEFINE_XENBUS_DRIVER(xen_blkbk, ,
        .probe = xen_blkbk_probe,
        .remove = xen_blkbk_remove,
        .otherend_changed = frontend_changed
-};
+);
 
 
 int xen_blkif_xenbus_init(void)
 {
-       return xenbus_register_backend(&xen_blkbk);
+       return xenbus_register_backend(&xen_blkbk_driver);
 }
index f3c45ba1304e505b0508246468b2a178be014f1e..f7fa094490a6a1ba55a5773f44b5e16752822288 100644 (file)
@@ -1460,16 +1460,13 @@ static const struct xenbus_device_id blkfront_ids[] = {
        { "" }
 };
 
-static struct xenbus_driver blkfront = {
-       .name = "vbd",
-       .owner = THIS_MODULE,
-       .ids = blkfront_ids,
+static DEFINE_XENBUS_DRIVER(blkfront, ,
        .probe = blkfront_probe,
        .remove = blkfront_remove,
        .resume = blkfront_resume,
        .otherend_changed = blkback_changed,
        .is_ready = blkfront_is_ready,
-};
+);
 
 static int __init xlblk_init(void)
 {
@@ -1484,7 +1481,7 @@ static int __init xlblk_init(void)
                return -ENODEV;
        }
 
-       ret = xenbus_register_frontend(&blkfront);
+       ret = xenbus_register_frontend(&blkfront_driver);
        if (ret) {
                unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
                return ret;
@@ -1497,7 +1494,7 @@ module_init(xlblk_init);
 
 static void __exit xlblk_exit(void)
 {
-       return xenbus_unregister_driver(&blkfront);
+       return xenbus_unregister_driver(&blkfront_driver);
 }
 module_exit(xlblk_exit);
 
index 62bae99424e6e436defda3723654816c44be2609..b620f0fe00e9304da4bf9a525e1c7402bb96028f 100644 (file)
@@ -361,15 +361,12 @@ static const struct xenbus_device_id xenkbd_ids[] = {
        { "" }
 };
 
-static struct xenbus_driver xenkbd_driver = {
-       .name = "vkbd",
-       .owner = THIS_MODULE,
-       .ids = xenkbd_ids,
+static DEFINE_XENBUS_DRIVER(xenkbd, ,
        .probe = xenkbd_probe,
        .remove = xenkbd_remove,
        .resume = xenkbd_resume,
        .otherend_changed = xenkbd_backend_changed,
-};
+);
 
 static int __init xenkbd_init(void)
 {
index 1ce729d6af75b34f1a0177e5ee6af2ee4b29dfb3..410018c4c52818f0b3a697d64e4300a505825f91 100644 (file)
@@ -474,17 +474,14 @@ static const struct xenbus_device_id netback_ids[] = {
 };
 
 
-static struct xenbus_driver netback = {
-       .name = "vif",
-       .owner = THIS_MODULE,
-       .ids = netback_ids,
+static DEFINE_XENBUS_DRIVER(netback, ,
        .probe = netback_probe,
        .remove = netback_remove,
        .uevent = netback_uevent,
        .otherend_changed = frontend_changed,
-};
+);
 
 int xenvif_xenbus_init(void)
 {
-       return xenbus_register_backend(&netback);
+       return xenbus_register_backend(&netback_driver);
 }
index d29365a232a1e2a9a0a55b1b258eea8d550a8d7e..ff49e9bdd7c40693e3bac3ef570cff3e7831cf85 100644 (file)
@@ -1849,7 +1849,7 @@ static void xennet_sysfs_delif(struct net_device *netdev)
 
 #endif /* CONFIG_SYSFS */
 
-static struct xenbus_device_id netfront_ids[] = {
+static const struct xenbus_device_id netfront_ids[] = {
        { "vif" },
        { "" }
 };
@@ -1874,15 +1874,12 @@ static int __devexit xennet_remove(struct xenbus_device *dev)
        return 0;
 }
 
-static struct xenbus_driver netfront_driver = {
-       .name = "vif",
-       .owner = THIS_MODULE,
-       .ids = netfront_ids,
+static DEFINE_XENBUS_DRIVER(netfront, ,
        .probe = netfront_probe,
        .remove = __devexit_p(xennet_remove),
        .resume = netfront_resume,
        .otherend_changed = netback_changed,
-};
+);
 
 static int __init netif_init(void)
 {
index 492b7d807fe8f7a17eafcbe7aa3b9bbeb4fbd89d..462d433eb9b39fa325d6d379cf2595b1f7c79495 100644 (file)
@@ -1127,14 +1127,11 @@ static const struct xenbus_device_id xenpci_ids[] = {
        {""},
 };
 
-static struct xenbus_driver xenbus_pcifront_driver = {
-       .name                   = "pcifront",
-       .owner                  = THIS_MODULE,
-       .ids                    = xenpci_ids,
+static DEFINE_XENBUS_DRIVER(xenpci, "pcifront",
        .probe                  = pcifront_xenbus_probe,
        .remove                 = pcifront_xenbus_remove,
        .otherend_changed       = pcifront_backend_changed,
-};
+);
 
 static int __init pcifront_init(void)
 {
@@ -1143,12 +1140,12 @@ static int __init pcifront_init(void)
 
        pci_frontend_registrar(1 /* enable */);
 
-       return xenbus_register_frontend(&xenbus_pcifront_driver);
+       return xenbus_register_frontend(&xenpci_driver);
 }
 
 static void __exit pcifront_cleanup(void)
 {
-       xenbus_unregister_driver(&xenbus_pcifront_driver);
+       xenbus_unregister_driver(&xenpci_driver);
        pci_frontend_registrar(0 /* disable */);
 }
 module_init(pcifront_init);
index beac52fc1c0eea6c1cadf337983c3b2b5c78614d..cb4529c40d742b93ebe7479b3688e43d4e249233 100644 (file)
@@ -671,20 +671,17 @@ InitWait:
        }
 }
 
-static struct xenbus_device_id xenfb_ids[] = {
+static const struct xenbus_device_id xenfb_ids[] = {
        { "vfb" },
        { "" }
 };
 
-static struct xenbus_driver xenfb_driver = {
-       .name = "vfb",
-       .owner = THIS_MODULE,
-       .ids = xenfb_ids,
+static DEFINE_XENBUS_DRIVER(xenfb, ,
        .probe = xenfb_probe,
        .remove = xenfb_remove,
        .resume = xenfb_resume,
        .otherend_changed = xenfb_backend_changed,
-};
+);
 
 static int __init xenfb_init(void)
 {
index 474d52ec3374f5025f51bda1190257a5132af771..87c5dc3368d0e2d111f8c3773a6c784f386acca5 100644 (file)
@@ -705,19 +705,16 @@ static int xen_pcibk_xenbus_remove(struct xenbus_device *dev)
        return 0;
 }
 
-static const struct xenbus_device_id xenpci_ids[] = {
+static const struct xenbus_device_id xen_pcibk_ids[] = {
        {"pci"},
        {""},
 };
 
-static struct xenbus_driver xenbus_xen_pcibk_driver = {
-       .name                   = DRV_NAME,
-       .owner                  = THIS_MODULE,
-       .ids                    = xenpci_ids,
+static DEFINE_XENBUS_DRIVER(xen_pcibk, DRV_NAME,
        .probe                  = xen_pcibk_xenbus_probe,
        .remove                 = xen_pcibk_xenbus_remove,
        .otherend_changed       = xen_pcibk_frontend_changed,
-};
+);
 
 const struct xen_pcibk_backend *__read_mostly xen_pcibk_backend;
 
@@ -733,11 +730,11 @@ int __init xen_pcibk_xenbus_register(void)
        if (passthrough)
                xen_pcibk_backend = &xen_pcibk_passthrough_backend;
        pr_info(DRV_NAME ": backend is %s\n", xen_pcibk_backend->name);
-       return xenbus_register_backend(&xenbus_xen_pcibk_driver);
+       return xenbus_register_backend(&xen_pcibk_driver);
 }
 
 void __exit xen_pcibk_xenbus_unregister(void)
 {
        destroy_workqueue(xen_pcibk_wq);
-       xenbus_unregister_driver(&xenbus_xen_pcibk_driver);
+       xenbus_unregister_driver(&xen_pcibk_driver);
 }
index 9e92fdbc07c5fe6252801ee5901a3f806780b7f4..7e30a98e97eefcb46d4b3c03d20849e75414bffd 100644 (file)
@@ -290,14 +290,9 @@ void xenbus_dev_shutdown(struct device *_dev)
 EXPORT_SYMBOL_GPL(xenbus_dev_shutdown);
 
 int xenbus_register_driver_common(struct xenbus_driver *drv,
-                                 struct xen_bus_type *bus,
-                                 struct module *owner,
-                                 const char *mod_name)
+                                 struct xen_bus_type *bus)
 {
-       drv->driver.name = drv->name;
        drv->driver.bus = &bus->bus;
-       drv->driver.owner = owner;
-       drv->driver.mod_name = mod_name;
 
        return driver_register(&drv->driver);
 }
index 795a981854822b745dd7cce50f1dba3ba37266ff..4e1fd39708a4c852584175b703146d7a000060d7 100644 (file)
@@ -51,9 +51,7 @@ extern int xenbus_match(struct device *_dev, struct device_driver *_drv);
 extern int xenbus_dev_probe(struct device *_dev);
 extern int xenbus_dev_remove(struct device *_dev);
 extern int xenbus_register_driver_common(struct xenbus_driver *drv,
-                                        struct xen_bus_type *bus,
-                                        struct module *owner,
-                                        const char *mod_name);
+                                        struct xen_bus_type *bus);
 extern int xenbus_probe_node(struct xen_bus_type *bus,
                             const char *type,
                             const char *nodename);
index c8db5008ce5fcf5d30a748c32571ea4f833d1083..cdfcce62feeff0a162dc1e95991075bb33dea562 100644 (file)
@@ -232,15 +232,13 @@ int xenbus_dev_is_online(struct xenbus_device *dev)
 }
 EXPORT_SYMBOL_GPL(xenbus_dev_is_online);
 
-int __xenbus_register_backend(struct xenbus_driver *drv,
-                             struct module *owner, const char *mod_name)
+int xenbus_register_backend(struct xenbus_driver *drv)
 {
        drv->read_otherend_details = read_frontend_details;
 
-       return xenbus_register_driver_common(drv, &xenbus_backend,
-                                            owner, mod_name);
+       return xenbus_register_driver_common(drv, &xenbus_backend);
 }
-EXPORT_SYMBOL_GPL(__xenbus_register_backend);
+EXPORT_SYMBOL_GPL(xenbus_register_backend);
 
 static int backend_probe_and_watch(struct notifier_block *notifier,
                                   unsigned long event,
index b521ce43d32555171d70842a41f1e8b4bf017c16..78456dcd50fa0320fe5db6e7a4aa9f2cdda9a00e 100644 (file)
@@ -233,15 +233,13 @@ static void wait_for_devices(struct xenbus_driver *xendrv)
                         print_device_status);
 }
 
-int __xenbus_register_frontend(struct xenbus_driver *drv,
-                              struct module *owner, const char *mod_name)
+int xenbus_register_frontend(struct xenbus_driver *drv)
 {
        int ret;
 
        drv->read_otherend_details = read_backend_details;
 
-       ret = xenbus_register_driver_common(drv, &xenbus_frontend,
-                                           owner, mod_name);
+       ret = xenbus_register_driver_common(drv, &xenbus_frontend);
        if (ret)
                return ret;
 
@@ -250,7 +248,7 @@ int __xenbus_register_frontend(struct xenbus_driver *drv,
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(__xenbus_register_frontend);
+EXPORT_SYMBOL_GPL(xenbus_register_frontend);
 
 static DECLARE_WAIT_QUEUE_HEAD(backend_state_wq);
 static int backend_state;
index 5467369e088982508f9c50169a897434485dbff8..412dc5a4b8e18eccea3591e6e237ed29fdd9f6c4 100644 (file)
@@ -84,8 +84,6 @@ struct xenbus_device_id
 
 /* A xenbus driver. */
 struct xenbus_driver {
-       char *name;
-       struct module *owner;
        const struct xenbus_device_id *ids;
        int (*probe)(struct xenbus_device *dev,
                     const struct xenbus_device_id *id);
@@ -100,31 +98,20 @@ struct xenbus_driver {
        int (*is_ready)(struct xenbus_device *dev);
 };
 
-static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
-{
-       return container_of(drv, struct xenbus_driver, driver);
+#define DEFINE_XENBUS_DRIVER(var, drvname, methods...)         \
+struct xenbus_driver var ## _driver = {                                \
+       .driver.name = drvname + 0 ?: var ## _ids->devicetype,  \
+       .driver.owner = THIS_MODULE,                            \
+       .ids = var ## _ids, ## methods                          \
 }
 
-int __must_check __xenbus_register_frontend(struct xenbus_driver *drv,
-                                           struct module *owner,
-                                           const char *mod_name);
-
-static inline int __must_check
-xenbus_register_frontend(struct xenbus_driver *drv)
+static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
 {
-       WARN_ON(drv->owner != THIS_MODULE);
-       return __xenbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME);
+       return container_of(drv, struct xenbus_driver, driver);
 }
 
-int __must_check __xenbus_register_backend(struct xenbus_driver *drv,
-                                          struct module *owner,
-                                          const char *mod_name);
-static inline int __must_check
-xenbus_register_backend(struct xenbus_driver *drv)
-{
-       WARN_ON(drv->owner != THIS_MODULE);
-       return __xenbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME);
-}
+int __must_check xenbus_register_frontend(struct xenbus_driver *);
+int __must_check xenbus_register_backend(struct xenbus_driver *);
 
 void xenbus_unregister_driver(struct xenbus_driver *drv);