From nobody Fri May 8 00:11:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D480C433EF for ; Mon, 16 May 2022 04:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237662AbiEPEvK (ORCPT ); Mon, 16 May 2022 00:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237840AbiEPEvA (ORCPT ); Mon, 16 May 2022 00:51:00 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70C611C93D; Sun, 15 May 2022 21:50:58 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1134) id 1B53020F3CF5; Sun, 15 May 2022 21:50:58 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1B53020F3CF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1652676658; bh=lrrITM7rr3TGclWL1IT19w390DDG2D85hxVo5rqd300=; h=Date:From:To:Subject:From; b=qwx50P6RJSjqupR9BDSVZwp6ZGUCQMENtgcghUjXff9ZSoNQcDmquWwrieLuoytmp JH20Dq3UARMAc02EtKdeZWsSRBkoWJvps3kjOuIAGkKtPrLejss5487fWzASrsvCfX jAq2iw0fqiA0C3LtmJ4W9gwWD9ZJXX4ivqcYnqR8= Date: Sun, 15 May 2022 21:50:58 -0700 From: Shradha Gupta To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui Subject: [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling Message-ID: <20220516045058.GA7933@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Michael Kelley --- Changes in v2: * Use a goto instead of inline code to handle the cleanup in balloon_probe() * Add a comment in balloon_remove() explaining the cleanup scenario * Add missing disable of page reporting when resume from hibernation fails --- drivers/hv/hv_balloon.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index eee7402cfc02..98fcfb516bbc 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev, =20 ret =3D balloon_connect_vsp(dev); if (ret !=3D 0) - return ret; + goto connect_error; =20 enable_page_reporting(); dm_device.state =3D DM_INITIALIZED; @@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev, dm_device.thread =3D NULL; disable_page_reporting(); vmbus_close(dev->channel); +connect_error: #ifdef CONFIG_MEMORY_HOTPLUG unregister_memory_notifier(&hv_memory_nb); restore_online_page_callback(&hv_online_page); @@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev) cancel_work_sync(&dm->ha_wrk.wrk); =20 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 !=3D DM_INIT_ERROR) { + disable_page_reporting(); + vmbus_close(dev->channel); #ifdef CONFIG_MEMORY_HOTPLUG - unregister_memory_notifier(&hv_memory_nb); - restore_online_page_callback(&hv_online_page); + unregister_memory_notifier(&hv_memory_nb); + restore_online_page_callback(&hv_online_page); #endif + } + 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(gap, tmp_gap, &has->gap_list, list) { @@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev) vmbus_close(dev->channel); out: dm_device.state =3D DM_INIT_ERROR; + disable_page_reporting(); #ifdef CONFIG_MEMORY_HOTPLUG unregister_memory_notifier(&hv_memory_nb); restore_online_page_callback(&hv_online_page); --=20 2.17.1