x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump
authorTianyu Lan <Tianyu.Lan@microsoft.com>
Mon, 6 Apr 2020 15:53:27 +0000 (08:53 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Apr 2020 08:30:16 +0000 (10:30 +0200)
[ Upstream commit 7f11a2cc10a4ae3a70e2c73361f4a9a33503539b ]

If kmsg_dump_register() fails, hv_panic_page will not be used
anywhere.  So free and reset it.

Fixes: 81b18bce48af ("Drivers: HV: Send one page worth of kmsg dump over Hyper-V during panic")
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
Link: https://lore.kernel.org/r/20200406155331.2105-3-Tianyu.Lan@microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hv/vmbus_drv.c

index 5ff7c1708d0e7fa68c7560dafd37408764cf7ffd..dd6d18d918a4b363b2aa2e3a7ccb27ecdb236def 100644 (file)
@@ -1222,9 +1222,13 @@ static int vmbus_bus_init(void)
                        hv_panic_page = (void *)get_zeroed_page(GFP_KERNEL);
                        if (hv_panic_page) {
                                ret = kmsg_dump_register(&hv_kmsg_dumper);
-                               if (ret)
+                               if (ret) {
                                        pr_err("Hyper-V: kmsg dump register "
                                                "error 0x%x\n", ret);
+                                       free_page(
+                                           (unsigned long)hv_panic_page);
+                                       hv_panic_page = NULL;
+                               }
                        } else
                                pr_err("Hyper-V: panic message page memory "
                                        "allocation failed");
@@ -1252,7 +1256,6 @@ static int vmbus_bus_init(void)
        hv_remove_vmbus_irq();
 
        bus_unregister(&hv_bus);
-       free_page((unsigned long)hv_panic_page);
        unregister_sysctl_table(hv_ctl_table_hdr);
        hv_ctl_table_hdr = NULL;
        return ret;