Skip to content

Commit d27423b

Browse files
Shradha Guptaliuw
authored andcommitted
hv_balloon: Fix balloon_probe() and balloon_remove() error handling
Add missing cleanup in balloon_probe() if the call to balloon_connect_vsp() fails. Also correctly handle cleanup in balloon_remove() when dm_state is DM_INIT_ERROR because balloon_resume() failed. Signed-off-by: Shradha Gupta <shradhagupta@microsoft.com> Reviewed-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/20220516045058.GA7933@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 86c8fb4 commit d27423b

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

drivers/hv/hv_balloon.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev,
18421842

18431843
ret = balloon_connect_vsp(dev);
18441844
if (ret != 0)
1845-
return ret;
1845+
goto connect_error;
18461846

18471847
enable_page_reporting();
18481848
dm_device.state = DM_INITIALIZED;
@@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev,
18611861
dm_device.thread = NULL;
18621862
disable_page_reporting();
18631863
vmbus_close(dev->channel);
1864+
connect_error:
18641865
#ifdef CONFIG_MEMORY_HOTPLUG
18651866
unregister_memory_notifier(&hv_memory_nb);
18661867
restore_online_page_callback(&hv_online_page);
@@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev)
18821883
cancel_work_sync(&dm->ha_wrk.wrk);
18831884

18841885
kthread_stop(dm->thread);
1885-
disable_page_reporting();
1886-
vmbus_close(dev->channel);
1886+
1887+
/*
1888+
* This is to handle the case when balloon_resume()
1889+
* call has failed and some cleanup has been done as
1890+
* a part of the error handling.
1891+
*/
1892+
if (dm_device.state != DM_INIT_ERROR) {
1893+
disable_page_reporting();
1894+
vmbus_close(dev->channel);
18871895
#ifdef CONFIG_MEMORY_HOTPLUG
1888-
unregister_memory_notifier(&hv_memory_nb);
1889-
restore_online_page_callback(&hv_online_page);
1896+
unregister_memory_notifier(&hv_memory_nb);
1897+
restore_online_page_callback(&hv_online_page);
18901898
#endif
1899+
}
1900+
18911901
spin_lock_irqsave(&dm_device.ha_lock, flags);
18921902
list_for_each_entry_safe(has, tmp, &dm->ha_region_list, list) {
18931903
list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) {
@@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev)
19481958
vmbus_close(dev->channel);
19491959
out:
19501960
dm_device.state = DM_INIT_ERROR;
1961+
disable_page_reporting();
19511962
#ifdef CONFIG_MEMORY_HOTPLUG
19521963
unregister_memory_notifier(&hv_memory_nb);
19531964
restore_online_page_callback(&hv_online_page);

0 commit comments

Comments
 (0)