aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2011-08-25 18:07:32 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-08-25 18:07:32 -0400
commit768fa21919b7f30b77f0b3ba94939f5556d111d5 (patch)
treef1f1a8f6f7b49d69f6b52dbcf4a540b4db0ab9f1 /drivers
parentc411a5981d6f53ed2502ad06a2ee70d67ed13f12 (diff)
Staging: hv: fix up driver registering mess
Individual drivers should never be touching the 'struct device' field, so if that is a requirement to pass to the vmbus core, you know something is wrong. This patch fixes that all up, and resolves the problem where the module reference counting was not happening properly for the individual drivers as well. Overall, it reduces the lines of code the individual drivers have to have, which tells you that this is the correct thing to do. Also, somehow the _GPL marking for the functions got removed on an older patch. As the name of the function was changing, properly change the _GPL marking as well at the same time. Cc: K. Y. Srinivasan <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Hank Janssen <hjanssen@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/hv/blkvsc_drv.c17
-rw-r--r--drivers/staging/hv/hv_mouse.c21
-rw-r--r--drivers/staging/hv/hv_util.c9
-rw-r--r--drivers/staging/hv/hyperv.h8
-rw-r--r--drivers/staging/hv/hyperv_net.h1
-rw-r--r--drivers/staging/hv/netvsc.c14
-rw-r--r--drivers/staging/hv/netvsc_drv.c19
-rw-r--r--drivers/staging/hv/storvsc_drv.c24
-rw-r--r--drivers/staging/hv/vmbus_drv.c43
9 files changed, 46 insertions, 110 deletions
diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index d170f24a07f..07dc9ed6ec5 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -109,7 +109,6 @@ struct block_device_context {
109 int users; 109 int users;
110}; 110};
111 111
112static const char *drv_name = "blkvsc";
113 112
114/* 113/*
115 * There is a circular dependency involving blkvsc_request_completion() 114 * There is a circular dependency involving blkvsc_request_completion()
@@ -805,6 +804,7 @@ MODULE_DEVICE_TABLE(vmbus, id_table);
805 804
806/* The one and only one */ 805/* The one and only one */
807static struct hv_driver blkvsc_drv = { 806static struct hv_driver blkvsc_drv = {
807 .name = "blkvsc",
808 .id_table = id_table, 808 .id_table = id_table,
809 .probe = blkvsc_probe, 809 .probe = blkvsc_probe,
810 .remove = blkvsc_remove, 810 .remove = blkvsc_remove,
@@ -824,24 +824,13 @@ static const struct block_device_operations block_ops = {
824 */ 824 */
825static int blkvsc_drv_init(void) 825static int blkvsc_drv_init(void)
826{ 826{
827 struct hv_driver *drv = &blkvsc_drv;
828 int ret;
829
830 BUILD_BUG_ON(sizeof(sector_t) != 8); 827 BUILD_BUG_ON(sizeof(sector_t) != 8);
831 828 return vmbus_driver_register(&blkvsc_drv);
832 drv->driver.name = drv_name;
833
834 /* The driver belongs to vmbus */
835 ret = vmbus_child_driver_register(&drv->driver);
836
837 return ret;
838} 829}
839 830
840
841static void blkvsc_drv_exit(void) 831static void blkvsc_drv_exit(void)
842{ 832{
843 833 vmbus_driver_unregister(&blkvsc_drv);
844 vmbus_child_driver_unregister(&blkvsc_drv.driver);
845} 834}
846 835
847/* 836/*
diff --git a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
index ebd17150d6c..572717317e7 100644
--- a/drivers/staging/hv/hv_mouse.c
+++ b/drivers/staging/hv/hv_mouse.c
@@ -176,8 +176,6 @@ struct mousevsc_dev {
176}; 176};
177 177
178 178
179static const char *driver_name = "mousevsc";
180
181static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info); 179static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info *info);
182static void inputreport_callback(struct hv_device *dev, void *packet, u32 len); 180static void inputreport_callback(struct hv_device *dev, void *packet, u32 len);
183static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len); 181static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len);
@@ -921,33 +919,20 @@ static const struct hv_vmbus_device_id id_table[] = {
921/* MODULE_DEVICE_TABLE(vmbus, id_table); */ 919/* MODULE_DEVICE_TABLE(vmbus, id_table); */
922 920
923static struct hv_driver mousevsc_drv = { 921static struct hv_driver mousevsc_drv = {
922 .name = "mousevsc",
924 .id_table = id_table, 923 .id_table = id_table,
925 .probe = mousevsc_probe, 924 .probe = mousevsc_probe,
926 .remove = mousevsc_remove, 925 .remove = mousevsc_remove,
927}; 926};
928 927
929static void mousevsc_drv_exit(void)
930{
931 vmbus_child_driver_unregister(&mousevsc_drv.driver);
932}
933
934static int __init mousevsc_init(void) 928static int __init mousevsc_init(void)
935{ 929{
936 struct hv_driver *drv = &mousevsc_drv; 930 return vmbus_driver_register(&mousevsc_drv);
937
938 DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing.");
939
940 drv->driver.name = driver_name;
941
942 /* The driver belongs to vmbus */
943 vmbus_child_driver_register(&drv->driver);
944
945 return 0;
946} 931}
947 932
948static void __exit mousevsc_exit(void) 933static void __exit mousevsc_exit(void)
949{ 934{
950 mousevsc_drv_exit(); 935 vmbus_driver_unregister(&mousevsc_drv);
951} 936}
952 937
953/* 938/*
diff --git a/drivers/staging/hv/hv_util.c b/drivers/staging/hv/hv_util.c
index b0d89deec76..f2f456f5e44 100644
--- a/drivers/staging/hv/hv_util.c
+++ b/drivers/staging/hv/hv_util.c
@@ -34,8 +34,6 @@ static u8 *shut_txf_buf;
34static u8 *time_txf_buf; 34static u8 *time_txf_buf;
35static u8 *hbeat_txf_buf; 35static u8 *hbeat_txf_buf;
36 36
37static const char *driver_name = "hv_util";
38
39static void shutdown_onchannelcallback(void *context) 37static void shutdown_onchannelcallback(void *context)
40{ 38{
41 struct vmbus_channel *channel = context; 39 struct vmbus_channel *channel = context;
@@ -244,6 +242,7 @@ MODULE_DEVICE_TABLE(vmbus, id_table);
244 242
245/* The one and only one */ 243/* The one and only one */
246static struct hv_driver util_drv = { 244static struct hv_driver util_drv = {
245 .name = "hv_util",
247 .id_table = id_table, 246 .id_table = id_table,
248 .probe = util_probe, 247 .probe = util_probe,
249 .remove = util_remove, 248 .remove = util_remove,
@@ -277,9 +276,7 @@ static int __init init_hyperv_utils(void)
277 276
278 hv_cb_utils[HV_KVP_MSG].callback = &hv_kvp_onchannelcallback; 277 hv_cb_utils[HV_KVP_MSG].callback = &hv_kvp_onchannelcallback;
279 278
280 util_drv.driver.name = driver_name; 279 return vmbus_driver_register(&util_drv);
281
282 return vmbus_child_driver_register(&util_drv.driver);
283} 280}
284 281
285static void exit_hyperv_utils(void) 282static void exit_hyperv_utils(void)
@@ -311,7 +308,7 @@ static void exit_hyperv_utils(void)
311 kfree(shut_txf_buf); 308 kfree(shut_txf_buf);
312 kfree(time_txf_buf); 309 kfree(time_txf_buf);
313 kfree(hbeat_txf_buf); 310 kfree(hbeat_txf_buf);
314 vmbus_child_driver_unregister(&util_drv.driver); 311 vmbus_driver_unregister(&util_drv);
315} 312}
316 313
317module_init(init_hyperv_utils); 314module_init(init_hyperv_utils);
diff --git a/drivers/staging/hv/hyperv.h b/drivers/staging/hv/hyperv.h
index d96de668eb1..c24981198b1 100644
--- a/drivers/staging/hv/hyperv.h
+++ b/drivers/staging/hv/hyperv.h
@@ -845,8 +845,12 @@ static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
845 845
846 846
847/* Vmbus interface */ 847/* Vmbus interface */
848int vmbus_child_driver_register(struct device_driver *drv); 848#define vmbus_driver_register(driver) \
849void vmbus_child_driver_unregister(struct device_driver *drv); 849 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
850int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
851 struct module *owner,
852 const char *mod_name);
853void vmbus_driver_unregister(struct hv_driver *hv_driver);
850 854
851/** 855/**
852 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device 856 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
diff --git a/drivers/staging/hv/hyperv_net.h b/drivers/staging/hv/hyperv_net.h
index 27f987b48df..5782fea9a17 100644
--- a/drivers/staging/hv/hyperv_net.h
+++ b/drivers/staging/hv/hyperv_net.h
@@ -96,7 +96,6 @@ void netvsc_linkstatus_callback(struct hv_device *device_obj,
96 unsigned int status); 96 unsigned int status);
97int netvsc_recv_callback(struct hv_device *device_obj, 97int netvsc_recv_callback(struct hv_device *device_obj,
98 struct hv_netvsc_packet *packet); 98 struct hv_netvsc_packet *packet);
99int netvsc_initialize(struct hv_driver *drv);
100int rndis_filter_open(struct hv_device *dev); 99int rndis_filter_open(struct hv_device *dev);
101int rndis_filter_close(struct hv_device *dev); 100int rndis_filter_close(struct hv_device *dev);
102int rndis_filter_device_add(struct hv_device *dev, 101int rndis_filter_device_add(struct hv_device *dev,
diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
index 6f4541bcef8..cb02eed741f 100644
--- a/drivers/staging/hv/netvsc.c
+++ b/drivers/staging/hv/netvsc.c
@@ -32,9 +32,6 @@
32#include "hyperv_net.h" 32#include "hyperv_net.h"
33 33
34 34
35/* Globals */
36static const char *driver_name = "netvsc";
37
38static struct netvsc_device *alloc_net_device(struct hv_device *device) 35static struct netvsc_device *alloc_net_device(struct hv_device *device)
39{ 36{
40 struct netvsc_device *net_device; 37 struct netvsc_device *net_device;
@@ -992,14 +989,3 @@ cleanup:
992 989
993 return ret; 990 return ret;
994} 991}
995
996/*
997 * netvsc_initialize - Main entry point
998 */
999int netvsc_initialize(struct hv_driver *drv)
1000{
1001
1002 drv->name = driver_name;
1003
1004 return 0;
1005}
diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c
index 2d2955c1925..ad1ef038ff7 100644
--- a/drivers/staging/hv/netvsc_drv.c
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -422,6 +422,7 @@ MODULE_DEVICE_TABLE(vmbus, id_table);
422 422
423/* The one and only one */ 423/* The one and only one */
424static struct hv_driver netvsc_drv = { 424static struct hv_driver netvsc_drv = {
425 .name = "netvsc",
425 .id_table = id_table, 426 .id_table = id_table,
426 .probe = netvsc_probe, 427 .probe = netvsc_probe,
427 .remove = netvsc_remove, 428 .remove = netvsc_remove,
@@ -429,26 +430,12 @@ static struct hv_driver netvsc_drv = {
429 430
430static void __exit netvsc_drv_exit(void) 431static void __exit netvsc_drv_exit(void)
431{ 432{
432 vmbus_child_driver_unregister(&netvsc_drv.driver); 433 vmbus_driver_unregister(&netvsc_drv);
433} 434}
434 435
435
436static int __init netvsc_drv_init(void) 436static int __init netvsc_drv_init(void)
437{ 437{
438 struct hv_driver *drv = &netvsc_drv; 438 return vmbus_driver_register(&netvsc_drv);
439 int ret;
440
441 pr_info("initializing....");
442
443 /* Callback to client driver to complete the initialization */
444 netvsc_initialize(drv);
445
446 drv->driver.name = drv->name;
447
448 /* The driver belongs to vmbus */
449 ret = vmbus_child_driver_register(&drv->driver);
450
451 return ret;
452} 439}
453 440
454MODULE_LICENSE("GPL"); 441MODULE_LICENSE("GPL");
diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index 6f67e9bfebd..0297418e8a6 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -41,8 +41,6 @@ static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE;
41module_param(storvsc_ringbuffer_size, int, S_IRUGO); 41module_param(storvsc_ringbuffer_size, int, S_IRUGO);
42MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)"); 42MODULE_PARM_DESC(storvsc_ringbuffer_size, "Ring buffer size (bytes)");
43 43
44static const char *driver_name = "storvsc";
45
46struct hv_host_device { 44struct hv_host_device {
47 struct hv_device *dev; 45 struct hv_device *dev;
48 struct kmem_cache *request_pool; 46 struct kmem_cache *request_pool;
@@ -718,6 +716,7 @@ static int storvsc_probe(struct hv_device *device)
718/* The one and only one */ 716/* The one and only one */
719 717
720static struct hv_driver storvsc_drv = { 718static struct hv_driver storvsc_drv = {
719 .name = "storvsc",
721 .id_table = id_table, 720 .id_table = id_table,
722 .probe = storvsc_probe, 721 .probe = storvsc_probe,
723 .remove = storvsc_remove, 722 .remove = storvsc_remove,
@@ -725,8 +724,6 @@ static struct hv_driver storvsc_drv = {
725 724
726static int __init storvsc_drv_init(void) 725static int __init storvsc_drv_init(void)
727{ 726{
728 int ret;
729 struct hv_driver *drv = &storvsc_drv;
730 u32 max_outstanding_req_per_channel; 727 u32 max_outstanding_req_per_channel;
731 728
732 /* 729 /*
@@ -735,29 +732,22 @@ static int __init storvsc_drv_init(void)
735 * the ring buffer indices) by the max request size (which is 732 * the ring buffer indices) by the max request size (which is
736 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) 733 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
737 */ 734 */
738
739 max_outstanding_req_per_channel = 735 max_outstanding_req_per_channel =
740 ((storvsc_ringbuffer_size - PAGE_SIZE) / 736 ((storvsc_ringbuffer_size - PAGE_SIZE) /
741 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + 737 ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
742 sizeof(struct vstor_packet) + sizeof(u64), 738 sizeof(struct vstor_packet) + sizeof(u64),
743 sizeof(u64))); 739 sizeof(u64)));
744 740
745 if (max_outstanding_req_per_channel < 741 if (max_outstanding_req_per_channel <
746 STORVSC_MAX_IO_REQUESTS) 742 STORVSC_MAX_IO_REQUESTS)
747 return -1; 743 return -1;
748 744
749 drv->driver.name = driver_name; 745 return vmbus_driver_register(&storvsc_drv);
750
751
752 /* The driver belongs to vmbus */
753 ret = vmbus_child_driver_register(&drv->driver);
754
755 return ret;
756} 746}
757 747
758static void __exit storvsc_drv_exit(void) 748static void __exit storvsc_drv_exit(void)
759{ 749{
760 vmbus_child_driver_unregister(&storvsc_drv.driver); 750 vmbus_driver_unregister(&storvsc_drv);
761} 751}
762 752
763MODULE_LICENSE("GPL"); 753MODULE_LICENSE("GPL");
diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
index 0114b04d224..26f49010e1f 100644
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -552,51 +552,50 @@ static int vmbus_bus_init(int irq)
552} 552}
553 553
554/** 554/**
555 * vmbus_child_driver_register() - Register a vmbus's child driver 555 * __vmbus_child_driver_register - Register a vmbus's driver
556 * @drv: Pointer to driver structure you want to register 556 * @drv: Pointer to driver structure you want to register
557 * 557 * @owner: owner module of the drv
558 * @mod_name: module name string
558 * 559 *
559 * Registers the given driver with Linux through the 'driver_register()' call 560 * Registers the given driver with Linux through the 'driver_register()' call
560 * And sets up the hyper-v vmbus handling for this driver. 561 * and sets up the hyper-v vmbus handling for this driver.
561 * It will return the state of the 'driver_register()' call. 562 * It will return the state of the 'driver_register()' call.
562 * 563 *
563 * Mainly used by Hyper-V drivers.
564 */ 564 */
565int vmbus_child_driver_register(struct device_driver *drv) 565int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, const char *mod_name)
566{ 566{
567 int ret; 567 int ret;
568 568
569 pr_info("child driver registering - name %s\n", drv->name); 569 pr_info("registering driver %s\n", hv_driver->name);
570 570
571 /* The child driver on this vmbus */ 571 hv_driver->driver.name = hv_driver->name;
572 drv->bus = &hv_bus; 572 hv_driver->driver.owner = owner;
573 hv_driver->driver.mod_name = mod_name;
574 hv_driver->driver.bus = &hv_bus;
573 575
574 ret = driver_register(drv); 576 ret = driver_register(&hv_driver->driver);
575 577
576 vmbus_request_offers(); 578 vmbus_request_offers();
577 579
578 return ret; 580 return ret;
579} 581}
580EXPORT_SYMBOL(vmbus_child_driver_register); 582EXPORT_SYMBOL_GPL(__vmbus_driver_register);
581 583
582/** 584/**
583 * vmbus_child_driver_unregister() - Unregister a vmbus's child driver 585 * vmbus_driver_unregister() - Unregister a vmbus's driver
584 * @drv: Pointer to driver structure you want to un-register 586 * @drv: Pointer to driver structure you want to un-register
585 *
586 *
587 * Un-register the given driver with Linux through the 'driver_unregister()'
588 * call. And ungegisters the driver from the Hyper-V vmbus handler.
589 * 587 *
590 * Mainly used by Hyper-V drivers. 588 * Un-register the given driver that was previous registered with a call to
589 * vmbus_driver_register()
591 */ 590 */
592void vmbus_child_driver_unregister(struct device_driver *drv) 591void vmbus_driver_unregister(struct hv_driver *hv_driver)
593{ 592{
594 pr_info("child driver unregistering - name %s\n", drv->name); 593 pr_info("unregistering driver %s\n", hv_driver->name);
595 594
596 driver_unregister(drv); 595 driver_unregister(&hv_driver->driver);
597 596
598} 597}
599EXPORT_SYMBOL(vmbus_child_driver_unregister); 598EXPORT_SYMBOL_GPL(vmbus_driver_unregister);
600 599
601/* 600/*
602 * vmbus_child_device_create - Creates and registers a new child device 601 * vmbus_child_device_create - Creates and registers a new child device