Staging: hv: util: Deal with driver register failures
authorK. Y. Srinivasan <kys@microsoft.com>
Wed, 31 Aug 2011 21:35:54 +0000 (14:35 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 6 Sep 2011 18:53:50 +0000 (11:53 -0700)
Properly deal with vmbus_driver_register() failures.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/hv_util.c

index e29a2a23eda548653a867c921f17ab051dc7f097..603921771b94b6591c49628dacc6721e2b577549 100644 (file)
@@ -277,6 +277,7 @@ static  struct hv_driver util_drv = {
 
 static int __init init_hyperv_utils(void)
 {
+       int ret;
        pr_info("Registering HyperV Utility Driver\n");
 
        if (hv_kvp_init())
@@ -289,12 +290,15 @@ static int __init init_hyperv_utils(void)
 
        if (!shut_txf_buf || !time_txf_buf || !hbeat_txf_buf) {
                pr_info("Unable to allocate memory for receive buffer\n");
-               kfree(shut_txf_buf);
-               kfree(time_txf_buf);
-               kfree(hbeat_txf_buf);
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto err;
        }
 
+       ret = vmbus_driver_register(&util_drv);
+
+       if (ret != 0)
+               goto err;
+
        hv_cb_utils[HV_SHUTDOWN_MSG].callback = &shutdown_onchannelcallback;
 
        hv_cb_utils[HV_TIMESYNC_MSG].callback = &timesync_onchannelcallback;
@@ -303,7 +307,14 @@ static int __init init_hyperv_utils(void)
 
        hv_cb_utils[HV_KVP_MSG].callback = &hv_kvp_onchannelcallback;
 
-       return vmbus_driver_register(&util_drv);
+       return 0;
+
+err:
+       kfree(shut_txf_buf);
+       kfree(time_txf_buf);
+       kfree(hbeat_txf_buf);
+
+       return ret;
 }
 
 static void exit_hyperv_utils(void)