Commit d27423bf authored by Shradha Gupta's avatar Shradha Gupta Committed by Wei Liu

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: default avatarShradha Gupta <shradhagupta@microsoft.com>
Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20220516045058.GA7933@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.netSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent 86c8fb4d
...@@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev, ...@@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev,
ret = balloon_connect_vsp(dev); ret = balloon_connect_vsp(dev);
if (ret != 0) if (ret != 0)
return ret; goto connect_error;
enable_page_reporting(); enable_page_reporting();
dm_device.state = DM_INITIALIZED; dm_device.state = DM_INITIALIZED;
...@@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev, ...@@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev,
dm_device.thread = NULL; dm_device.thread = NULL;
disable_page_reporting(); disable_page_reporting();
vmbus_close(dev->channel); vmbus_close(dev->channel);
connect_error:
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
unregister_memory_notifier(&hv_memory_nb); unregister_memory_notifier(&hv_memory_nb);
restore_online_page_callback(&hv_online_page); restore_online_page_callback(&hv_online_page);
...@@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev) ...@@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev)
cancel_work_sync(&dm->ha_wrk.wrk); cancel_work_sync(&dm->ha_wrk.wrk);
kthread_stop(dm->thread); kthread_stop(dm->thread);
disable_page_reporting();
vmbus_close(dev->channel); /*
* This is to handle the case when balloon_resume()
* call has failed and some cleanup has been done as
* a part of the error handling.
*/
if (dm_device.state != DM_INIT_ERROR) {
disable_page_reporting();
vmbus_close(dev->channel);
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
unregister_memory_notifier(&hv_memory_nb); unregister_memory_notifier(&hv_memory_nb);
restore_online_page_callback(&hv_online_page); restore_online_page_callback(&hv_online_page);
#endif #endif
}
spin_lock_irqsave(&dm_device.ha_lock, flags); spin_lock_irqsave(&dm_device.ha_lock, flags);
list_for_each_entry_safe(has, tmp, &dm->ha_region_list, list) { list_for_each_entry_safe(has, tmp, &dm->ha_region_list, list) {
list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) { list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) {
...@@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev) ...@@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev)
vmbus_close(dev->channel); vmbus_close(dev->channel);
out: out:
dm_device.state = DM_INIT_ERROR; dm_device.state = DM_INIT_ERROR;
disable_page_reporting();
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
unregister_memory_notifier(&hv_memory_nb); unregister_memory_notifier(&hv_memory_nb);
restore_online_page_callback(&hv_online_page); restore_online_page_callback(&hv_online_page);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment