Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp688402pxb; Thu, 17 Feb 2022 12:28:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpm1dvz2a0nUv8bm+bS5a9O2fBtfCigBpIxefhDfJ9sYbS+myi38uQ2J8ERRLw5T2Zrw/M X-Received: by 2002:a17:906:f6d9:b0:6ce:e7d:5f3a with SMTP id jo25-20020a170906f6d900b006ce0e7d5f3amr3684917ejb.20.1645129725597; Thu, 17 Feb 2022 12:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645129725; cv=none; d=google.com; s=arc-20160816; b=L6pX6D4R9RtzD9dPF5UgSsl7kj11/fx097aFHMi0N4AOuyAzqKaht+dj6GwAPOg2Bh nRPB6s/RITKhspypvZKwHNnvWjE3QIFOP5PlGgcYSLt5j01JEncv1Kf2yngCO05itJ41 NSoExLfVK+tzo1nyjUj0GlAaKFbmkYC0HFJtaSVe0s+jWn/7SIuL945M4GfoXx7CX6LW rJNWeHB1kA8yLbzCZ6cASTCm3tjOf9/zcDMi5Qfiuglf88dQUZpkDHDS0yYbuhcdPCGx Yqlrpto72kP6dP7sAZwDxT+w4HQYEGjT1yWaHWVOFyE8wBqL7LM1DHCFD8wzhPzXj7n5 Vc+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pzEbanhMm0OnzJoAa33AeRNSbvHiwa5BXeb3mKsMLKo=; b=DcWdq9264AIgh2BFA7yLOUT3eGboRWpB80rkNYshD5TNwspnCfwB7L2lTDmsmizcJR gsZHT8pa9x5dcaUm7WAoDmtj8tH0MX6jo7xd1bXOq88zDrMaE0D8tS25hkZKS/M/AxJz Mc68vKJe50PjuLOLQ9Sht1Rop0W5UyFAP+R8AsfcXLGXCQEFyJrrSBMsLWPgjlShTcxN kmVS87e3wpd1G/PVHkprwRJSfXJQul/T5oDym9jGGOmdCYLUlHzYKbt+kvZ9Pc7X+7aJ pSMv0v3L4IHKBJ9pp3et8zldxbE/PYLkzF4eggAPJ5fCzBLaAiBxDXFFPGKNRktQMzx3 8WIQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d23si4249596edr.137.2022.02.17.12.28.21; Thu, 17 Feb 2022 12:28:45 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244231AbiBQSX2 (ORCPT + 99 others); Thu, 17 Feb 2022 13:23:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244225AbiBQSXY (ORCPT ); Thu, 17 Feb 2022 13:23:24 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7E053134E for ; Thu, 17 Feb 2022 10:23:06 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A5E20152B; Thu, 17 Feb 2022 10:23:06 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 765F43F718; Thu, 17 Feb 2022 10:23:04 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, Jamie Iles , D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com Subject: [PATCH v3 04/21] x86/resctrl: Group struct rdt_hw_domain cleanup Date: Thu, 17 Feb 2022 18:20:53 +0000 Message-Id: <20220217182110.7176-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220217182110.7176-1-james.morse@arm.com> References: <20220217182110.7176-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 domain_add_cpu() and domain_remove_cpu() need to kfree() the child arrays that were allocated by domain_setup_ctrlval(). As this memory is moved around, and new arrays are created, adjusting the error handling cleanup code becomes noisier. To simplify this, move all the kfree() calls into a domain_free() helper. This depends on struct rdt_hw_domain being kzalloc()d, allowing it to unconditionally kfree() all the child arrays. Signed-off-by: James Morse --- Changes since v2: * Made domain_free() static. Changes since v1: * This patch is new --- arch/x86/kernel/cpu/resctrl/core.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 25f30148478b..e37889f7a1a5 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -414,6 +414,13 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm) } } +static void domain_free(struct rdt_hw_domain *hw_dom) +{ + kfree(hw_dom->ctrl_val); + kfree(hw_dom->mbps_val); + kfree(hw_dom); +} + static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d) { struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); @@ -488,7 +495,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) rdt_domain_reconfigure_cdp(r); if (r->alloc_capable && domain_setup_ctrlval(r, d)) { - kfree(hw_dom); + domain_free(hw_dom); return; } @@ -497,9 +504,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) err = resctrl_online_domain(r, d); if (err) { list_del(&d->list); - kfree(hw_dom->ctrl_val); - kfree(hw_dom->mbps_val); - kfree(hw_dom); + domain_free(hw_dom); } } @@ -547,12 +552,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) if (d->plr) d->plr->d = NULL; - kfree(hw_dom->ctrl_val); - kfree(hw_dom->mbps_val); bitmap_free(d->rmid_busy_llc); kfree(d->mbm_total); kfree(d->mbm_local); - kfree(hw_dom); + domain_free(hw_dom); return; } -- 2.30.2