From nobody Sun May 10 16:27:01 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 1843CC433EF for ; Fri, 29 Apr 2022 09:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238865AbiD2Jjy (ORCPT ); Fri, 29 Apr 2022 05:39:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbiD2Jjx (ORCPT ); Fri, 29 Apr 2022 05:39:53 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BC857EA3D; Fri, 29 Apr 2022 02:36:36 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1134) id B955C20E9BED; Fri, 29 Apr 2022 02:36:35 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B955C20E9BED Date: Fri, 29 Apr 2022 02:36:35 -0700 From: Shradha Gupta To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hv: hv_balloon: Fixed an issue in the earor handling code if probe failed Message-ID: <20220429093635.GA4945@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" If the balloon_probe() function fails, we do some cleanup and similar functions are called again when after this a balloon_remove() call is made. This fix makes sure that the cleanup is not called twice. Also made sure if dm_state is DM_INIT_ERROR, the clean up is already done properly. Signed-off-by: Shradha Gupta --- drivers/hv/hv_balloon.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index eee7402cfc02..7c62c1c3ffc7 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1841,8 +1841,13 @@ static int balloon_probe(struct hv_device *dev, hv_set_drvdata(dev, &dm_device); =20 ret =3D balloon_connect_vsp(dev); - if (ret !=3D 0) + if (ret !=3D 0) { +#ifdef CONFIG_MEMORY_HOTPLUG + unregister_memory_notifier(&hv_memory_nb); + restore_online_page_callback(&hv_online_page); +#endif return ret; + } =20 enable_page_reporting(); dm_device.state =3D DM_INITIALIZED; @@ -1882,12 +1887,14 @@ 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); + 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) { --=20 2.17.1