Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Xen: consolidate and simplify struct xenbus_driver instantiation

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>

authored by

Jan Beulich and committed by
Konrad Rzeszutek Wilk
73db144b 2e163414

+44 -92
+3 -6
drivers/block/xen-blkback/xenbus.c
··· 787 787 }; 788 788 789 789 790 - static struct xenbus_driver xen_blkbk = { 791 - .name = "vbd", 792 - .owner = THIS_MODULE, 793 - .ids = xen_blkbk_ids, 790 + static DEFINE_XENBUS_DRIVER(xen_blkbk, , 794 791 .probe = xen_blkbk_probe, 795 792 .remove = xen_blkbk_remove, 796 793 .otherend_changed = frontend_changed 797 - }; 794 + ); 798 795 799 796 800 797 int xen_blkif_xenbus_init(void) 801 798 { 802 - return xenbus_register_backend(&xen_blkbk); 799 + return xenbus_register_backend(&xen_blkbk_driver); 803 800 }
+4 -7
drivers/block/xen-blkfront.c
··· 1437 1437 { "" } 1438 1438 }; 1439 1439 1440 - static struct xenbus_driver blkfront = { 1441 - .name = "vbd", 1442 - .owner = THIS_MODULE, 1443 - .ids = blkfront_ids, 1440 + static DEFINE_XENBUS_DRIVER(blkfront, , 1444 1441 .probe = blkfront_probe, 1445 1442 .remove = blkfront_remove, 1446 1443 .resume = blkfront_resume, 1447 1444 .otherend_changed = blkback_changed, 1448 1445 .is_ready = blkfront_is_ready, 1449 - }; 1446 + ); 1450 1447 1451 1448 static int __init xlblk_init(void) 1452 1449 { ··· 1458 1461 return -ENODEV; 1459 1462 } 1460 1463 1461 - ret = xenbus_register_frontend(&blkfront); 1464 + ret = xenbus_register_frontend(&blkfront_driver); 1462 1465 if (ret) { 1463 1466 unregister_blkdev(XENVBD_MAJOR, DEV_NAME); 1464 1467 return ret; ··· 1471 1474 1472 1475 static void __exit xlblk_exit(void) 1473 1476 { 1474 - return xenbus_unregister_driver(&blkfront); 1477 + return xenbus_unregister_driver(&blkfront_driver); 1475 1478 } 1476 1479 module_exit(xlblk_exit); 1477 1480
+2 -5
drivers/input/misc/xen-kbdfront.c
··· 361 361 { "" } 362 362 }; 363 363 364 - static struct xenbus_driver xenkbd_driver = { 365 - .name = "vkbd", 366 - .owner = THIS_MODULE, 367 - .ids = xenkbd_ids, 364 + static DEFINE_XENBUS_DRIVER(xenkbd, , 368 365 .probe = xenkbd_probe, 369 366 .remove = xenkbd_remove, 370 367 .resume = xenkbd_resume, 371 368 .otherend_changed = xenkbd_backend_changed, 372 - }; 369 + ); 373 370 374 371 static int __init xenkbd_init(void) 375 372 {
+3 -6
drivers/net/xen-netback/xenbus.c
··· 474 474 }; 475 475 476 476 477 - static struct xenbus_driver netback = { 478 - .name = "vif", 479 - .owner = THIS_MODULE, 480 - .ids = netback_ids, 477 + static DEFINE_XENBUS_DRIVER(netback, , 481 478 .probe = netback_probe, 482 479 .remove = netback_remove, 483 480 .uevent = netback_uevent, 484 481 .otherend_changed = frontend_changed, 485 - }; 482 + ); 486 483 487 484 int xenvif_xenbus_init(void) 488 485 { 489 - return xenbus_register_backend(&netback); 486 + return xenbus_register_backend(&netback_driver); 490 487 }
+3 -6
drivers/net/xen-netfront.c
··· 1910 1910 1911 1911 #endif /* CONFIG_SYSFS */ 1912 1912 1913 - static struct xenbus_device_id netfront_ids[] = { 1913 + static const struct xenbus_device_id netfront_ids[] = { 1914 1914 { "vif" }, 1915 1915 { "" } 1916 1916 }; ··· 1937 1937 return 0; 1938 1938 } 1939 1939 1940 - static struct xenbus_driver netfront_driver = { 1941 - .name = "vif", 1942 - .owner = THIS_MODULE, 1943 - .ids = netfront_ids, 1940 + static DEFINE_XENBUS_DRIVER(netfront, , 1944 1941 .probe = netfront_probe, 1945 1942 .remove = __devexit_p(xennet_remove), 1946 1943 .resume = netfront_resume, 1947 1944 .otherend_changed = netback_changed, 1948 - }; 1945 + ); 1949 1946 1950 1947 static int __init netif_init(void) 1951 1948 {
+4 -7
drivers/pci/xen-pcifront.c
··· 1126 1126 {""}, 1127 1127 }; 1128 1128 1129 - static struct xenbus_driver xenbus_pcifront_driver = { 1130 - .name = "pcifront", 1131 - .owner = THIS_MODULE, 1132 - .ids = xenpci_ids, 1129 + static DEFINE_XENBUS_DRIVER(xenpci, "pcifront", 1133 1130 .probe = pcifront_xenbus_probe, 1134 1131 .remove = pcifront_xenbus_remove, 1135 1132 .otherend_changed = pcifront_backend_changed, 1136 - }; 1133 + ); 1137 1134 1138 1135 static int __init pcifront_init(void) 1139 1136 { ··· 1139 1142 1140 1143 pci_frontend_registrar(1 /* enable */); 1141 1144 1142 - return xenbus_register_frontend(&xenbus_pcifront_driver); 1145 + return xenbus_register_frontend(&xenpci_driver); 1143 1146 } 1144 1147 1145 1148 static void __exit pcifront_cleanup(void) 1146 1149 { 1147 - xenbus_unregister_driver(&xenbus_pcifront_driver); 1150 + xenbus_unregister_driver(&xenpci_driver); 1148 1151 pci_frontend_registrar(0 /* disable */); 1149 1152 } 1150 1153 module_init(pcifront_init);
+3 -6
drivers/video/xen-fbfront.c
··· 671 671 } 672 672 } 673 673 674 - static struct xenbus_device_id xenfb_ids[] = { 674 + static const struct xenbus_device_id xenfb_ids[] = { 675 675 { "vfb" }, 676 676 { "" } 677 677 }; 678 678 679 - static struct xenbus_driver xenfb_driver = { 680 - .name = "vfb", 681 - .owner = THIS_MODULE, 682 - .ids = xenfb_ids, 679 + static DEFINE_XENBUS_DRIVER(xenfb, , 683 680 .probe = xenfb_probe, 684 681 .remove = xenfb_remove, 685 682 .resume = xenfb_resume, 686 683 .otherend_changed = xenfb_backend_changed, 687 - }; 684 + ); 688 685 689 686 static int __init xenfb_init(void) 690 687 {
+5 -8
drivers/xen/xen-pciback/xenbus.c
··· 707 707 return 0; 708 708 } 709 709 710 - static const struct xenbus_device_id xenpci_ids[] = { 710 + static const struct xenbus_device_id xen_pcibk_ids[] = { 711 711 {"pci"}, 712 712 {""}, 713 713 }; 714 714 715 - static struct xenbus_driver xenbus_xen_pcibk_driver = { 716 - .name = DRV_NAME, 717 - .owner = THIS_MODULE, 718 - .ids = xenpci_ids, 715 + static DEFINE_XENBUS_DRIVER(xen_pcibk, DRV_NAME, 719 716 .probe = xen_pcibk_xenbus_probe, 720 717 .remove = xen_pcibk_xenbus_remove, 721 718 .otherend_changed = xen_pcibk_frontend_changed, 722 - }; 719 + ); 723 720 724 721 const struct xen_pcibk_backend *__read_mostly xen_pcibk_backend; 725 722 ··· 732 735 if (passthrough) 733 736 xen_pcibk_backend = &xen_pcibk_passthrough_backend; 734 737 pr_info(DRV_NAME ": backend is %s\n", xen_pcibk_backend->name); 735 - return xenbus_register_backend(&xenbus_xen_pcibk_driver); 738 + return xenbus_register_backend(&xen_pcibk_driver); 736 739 } 737 740 738 741 void __exit xen_pcibk_xenbus_unregister(void) 739 742 { 740 743 destroy_workqueue(xen_pcibk_wq); 741 - xenbus_unregister_driver(&xenbus_xen_pcibk_driver); 744 + xenbus_unregister_driver(&xen_pcibk_driver); 742 745 }
+1 -6
drivers/xen/xenbus/xenbus_probe.c
··· 291 291 EXPORT_SYMBOL_GPL(xenbus_dev_shutdown); 292 292 293 293 int xenbus_register_driver_common(struct xenbus_driver *drv, 294 - struct xen_bus_type *bus, 295 - struct module *owner, 296 - const char *mod_name) 294 + struct xen_bus_type *bus) 297 295 { 298 - drv->driver.name = drv->name; 299 296 drv->driver.bus = &bus->bus; 300 - drv->driver.owner = owner; 301 - drv->driver.mod_name = mod_name; 302 297 303 298 return driver_register(&drv->driver); 304 299 }
+1 -3
drivers/xen/xenbus/xenbus_probe.h
··· 53 53 extern int xenbus_dev_probe(struct device *_dev); 54 54 extern int xenbus_dev_remove(struct device *_dev); 55 55 extern int xenbus_register_driver_common(struct xenbus_driver *drv, 56 - struct xen_bus_type *bus, 57 - struct module *owner, 58 - const char *mod_name); 56 + struct xen_bus_type *bus); 59 57 extern int xenbus_probe_node(struct xen_bus_type *bus, 60 58 const char *type, 61 59 const char *nodename);
+3 -5
drivers/xen/xenbus/xenbus_probe_backend.c
··· 232 232 } 233 233 EXPORT_SYMBOL_GPL(xenbus_dev_is_online); 234 234 235 - int __xenbus_register_backend(struct xenbus_driver *drv, 236 - struct module *owner, const char *mod_name) 235 + int xenbus_register_backend(struct xenbus_driver *drv) 237 236 { 238 237 drv->read_otherend_details = read_frontend_details; 239 238 240 - return xenbus_register_driver_common(drv, &xenbus_backend, 241 - owner, mod_name); 239 + return xenbus_register_driver_common(drv, &xenbus_backend); 242 240 } 243 - EXPORT_SYMBOL_GPL(__xenbus_register_backend); 241 + EXPORT_SYMBOL_GPL(xenbus_register_backend); 244 242 245 243 static int backend_probe_and_watch(struct notifier_block *notifier, 246 244 unsigned long event,
+3 -5
drivers/xen/xenbus/xenbus_probe_frontend.c
··· 230 230 print_device_status); 231 231 } 232 232 233 - int __xenbus_register_frontend(struct xenbus_driver *drv, 234 - struct module *owner, const char *mod_name) 233 + int xenbus_register_frontend(struct xenbus_driver *drv) 235 234 { 236 235 int ret; 237 236 238 237 drv->read_otherend_details = read_backend_details; 239 238 240 - ret = xenbus_register_driver_common(drv, &xenbus_frontend, 241 - owner, mod_name); 239 + ret = xenbus_register_driver_common(drv, &xenbus_frontend); 242 240 if (ret) 243 241 return ret; 244 242 ··· 245 247 246 248 return 0; 247 249 } 248 - EXPORT_SYMBOL_GPL(__xenbus_register_frontend); 250 + EXPORT_SYMBOL_GPL(xenbus_register_frontend); 249 251 250 252 static DECLARE_WAIT_QUEUE_HEAD(backend_state_wq); 251 253 static int backend_state;
+9 -22
include/xen/xenbus.h
··· 85 85 86 86 /* A xenbus driver. */ 87 87 struct xenbus_driver { 88 - char *name; 89 - struct module *owner; 90 88 const struct xenbus_device_id *ids; 91 89 int (*probe)(struct xenbus_device *dev, 92 90 const struct xenbus_device_id *id); ··· 99 101 int (*is_ready)(struct xenbus_device *dev); 100 102 }; 101 103 104 + #define DEFINE_XENBUS_DRIVER(var, drvname, methods...) \ 105 + struct xenbus_driver var ## _driver = { \ 106 + .driver.name = drvname + 0 ?: var ## _ids->devicetype, \ 107 + .driver.owner = THIS_MODULE, \ 108 + .ids = var ## _ids, ## methods \ 109 + } 110 + 102 111 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv) 103 112 { 104 113 return container_of(drv, struct xenbus_driver, driver); 105 114 } 106 115 107 - int __must_check __xenbus_register_frontend(struct xenbus_driver *drv, 108 - struct module *owner, 109 - const char *mod_name); 110 - 111 - static inline int __must_check 112 - xenbus_register_frontend(struct xenbus_driver *drv) 113 - { 114 - WARN_ON(drv->owner != THIS_MODULE); 115 - return __xenbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME); 116 - } 117 - 118 - int __must_check __xenbus_register_backend(struct xenbus_driver *drv, 119 - struct module *owner, 120 - const char *mod_name); 121 - static inline int __must_check 122 - xenbus_register_backend(struct xenbus_driver *drv) 123 - { 124 - WARN_ON(drv->owner != THIS_MODULE); 125 - return __xenbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME); 126 - } 116 + int __must_check xenbus_register_frontend(struct xenbus_driver *); 117 + int __must_check xenbus_register_backend(struct xenbus_driver *); 127 118 128 119 void xenbus_unregister_driver(struct xenbus_driver *drv); 129 120