Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2893728iob; Mon, 16 May 2022 08:26:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyapzW9b6y7gSH4v29pPVNKWErUwA+0VHzEq/an4rFqhz701toldi58+vAymX6rmm7mp1TD X-Received: by 2002:a17:90a:2f84:b0:1dd:940:50e7 with SMTP id t4-20020a17090a2f8400b001dd094050e7mr30850148pjd.210.1652714816536; Mon, 16 May 2022 08:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652714816; cv=none; d=google.com; s=arc-20160816; b=itIYXBiy14bmofFdhCif2+EcYPJb4oQLcXQjkuQM5s/5tjO+cIjcTIuf9LmIGdwRp+ Xn6llipPuEOx8jG7jzAIclg7fObq5fluc51uKhuGMfytMcvAVMvs/DU/sNP1qkrWuo5b cGZ2LDEH8FU13ZLVKQaSc7KK3LtCgQy1j7GJSNxiglOk7VJDQAznghVMw/I6mTzel5WO 6QZn9DAdmGbpkabXIU/Rn0MAHEsActu8p1bXS43pWIWwIbxFIeUiUTrcDrsT9txw0KAp FRL0RKUJ8j7OhMQjtdqfse6TxcntI9lXhY40G0XRVjZeaaVhe0XQWVdLxa8T6R6iIffu CpJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:to:from:date:dkim-signature:dkim-filter; bh=lrrITM7rr3TGclWL1IT19w390DDG2D85hxVo5rqd300=; b=F2GCtQ4e2/mdlm0WZQ7AfJ18LbqSfi5bQ++qE3oBKrYFtgs+axHS5jC56jplOIbZRc XyDyIvhopebRpgD4Hys75BXZ7c0Ckl9YNNXFvL9eykT61Q8gGWMyS04zj0c/JNVZBZCW ilR0OW/j/Gc8eSvReIbRizKV9L0OwsmiqQ7x8sJHkuRv5+q23olmzpWFG2gqDS1bRcoF tsBrUG+sf+vTx2jM5+WuLQKGjVn/0L5/AEuNrFo93AN7ErbdvClWGqhvgLdXjxCkkr5k 1U90BcTA8exUcCu7bQuE5wXDijbYEK0BUzNrZhhNlGq6OX6DsbkkxYdxizB5qTrmi8k7 xgzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=qwx50P6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a17090a710300b001dc62080a06si16268657pjk.74.2022.05.16.08.26.41; Mon, 16 May 2022 08:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=qwx50P6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236508AbiEPEvJ (ORCPT + 99 others); Mon, 16 May 2022 00:51:09 -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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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, ret = balloon_connect_vsp(dev); if (ret != 0) - return ret; + goto connect_error; enable_page_reporting(); dm_device.state = DM_INITIALIZED; @@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev, dm_device.thread = 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); 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 - 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 = DM_INIT_ERROR; + disable_page_reporting(); #ifdef CONFIG_MEMORY_HOTPLUG unregister_memory_notifier(&hv_memory_nb); restore_online_page_callback(&hv_online_page); -- 2.17.1