Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2131289rwe; Fri, 2 Sep 2022 08:59:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5APQYrSUHcoKL+R4IWQRJjTcWFOkJ0Ed5Isq+p28UgvaaLP9p72max1Jlff11KgIq4PLRU X-Received: by 2002:a17:907:762f:b0:73d:e08c:233f with SMTP id jy15-20020a170907762f00b0073de08c233fmr25370076ejc.589.1662134339991; Fri, 02 Sep 2022 08:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662134339; cv=none; d=google.com; s=arc-20160816; b=JznP9i1DTen8kzG2lDjnn9wYAUKR4zbpaBQxlN308ei6ksWxvXvbXwdtA3tevptdnt d4NHPnR22fAw9DAYNCPhyNlf/Fh9bYgVcBLrBv5p5lWsqtNH7PYiywjtoyQgM9/51/LL M8G0oSiMwJRLG8sTE/tc6qbqh7pMlZsq+Vrc1dWcfcH3iR69QYdYm1jcs2wPSd4zHVCO xNlrY55Y0c6KqC+fKI/mfb+Yw8+xZGnpY3x33bdgon2vS87XUvz+T8qyh+T+8PsKMR/r C3XldTtV0eYNbCE4ZNUoDgMIgHktDbo0BUVWGXeS7NqMrSTnX7vZMJNoMpv/dD8PMNBE macA== 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=5AkXgjh/wBWUnoAASKOd196ZsuLVKnaMJlzbOvUZ+Ao=; b=HenyOqM5Mac7gxkJLxTKrx2fDE3l18jsvWrbV1Y7wKGsa/5VyllP8lGqfq8tzrXMDb 8x8rKLDv1Ct9hWyrxtBFFOnzk0bbM3ZscMNk3SQnOQDU7DHhzBa251nYsMuLt+Ax3qne aLZc54fNqBkubhna028XmliNAUHgUFrubCqjLwAbfOg6AmRhSvaZkXSpxBrd+/6YkQYq u5/gLS35/AsGLd4Z3gbPKVQqgQZ8k4yXzC4ZLsmX+dMjI+ZJoUUSU07LrPkRBCjI4VhY CN2xi28+E0yOtkfGBUX4xZtVA/yCQt65EwL7BqXP0G8urI08eRqFz/POZs9LFHvDM+VF yttQ== 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 n9-20020a170906700900b00726b8d2fbc6si1788965ejj.504.2022.09.02.08.58.34; Fri, 02 Sep 2022 08:58:59 -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; 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 S237570AbiIBPz2 (ORCPT + 99 others); Fri, 2 Sep 2022 11:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237482AbiIBPy1 (ORCPT ); Fri, 2 Sep 2022 11:54:27 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C02F810FFF for ; Fri, 2 Sep 2022 08:49:05 -0700 (PDT) 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 310F61576; Fri, 2 Sep 2022 08:49:11 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A09D53F766; Fri, 2 Sep 2022 08:49:02 -0700 (PDT) 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, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, Jamie Iles , Cristian Marussi , Xin Hao , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com Subject: [PATCH v6 04/21] x86/resctrl: Group struct rdt_hw_domain cleanup Date: Fri, 2 Sep 2022 15:48:12 +0000 Message-Id: <20220902154829.30399-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220902154829.30399-1-james.morse@arm.com> References: <20220902154829.30399-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_NONE,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. Reviewed-by: Jamie Iles Tested-by: Xin Hao Reviewed-by: Shaopeng Tan Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Reviewed-by: Reinette Chatre 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