From mboxrd@z Thu Jan 1 00:00:00 1970 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 850C8C83F16 for ; Mon, 28 Aug 2023 07:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229684AbjH1HZv (ORCPT ); Mon, 28 Aug 2023 03:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjH1HZY (ORCPT ); Mon, 28 Aug 2023 03:25:24 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92539F1; Mon, 28 Aug 2023 00:25:21 -0700 (PDT) Received: from kwepemd100002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RZ26t47s2zNnHV; Mon, 28 Aug 2023 15:21:42 +0800 (CST) Received: from [10.67.110.108] (10.67.110.108) by kwepemd100002.china.huawei.com (7.221.188.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Mon, 28 Aug 2023 15:25:18 +0800 Message-ID: <0c50a3da-65e2-eb91-95ea-6a2ca825c16d@huawei.com> Date: Mon, 28 Aug 2023 15:25:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH] cpufreq: governor: Free dbs_data directly when gov->init() fails To: Viresh Kumar CC: , , References: <20230826012415.1126955-1-liaochang1@huawei.com> <20230828065625.ufp66goznd72rcyh@vireshk-i7> From: "Liao, Chang" In-Reply-To: <20230828065625.ufp66goznd72rcyh@vireshk-i7> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd100002.china.huawei.com (7.221.188.184) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Viresh. 在 2023/8/28 14:56, Viresh Kumar 写道: > On 26-08-23, 01:24, Liao Chang wrote: >> Due to the kobject embedded in the dbs_data doest not has a release() >> method yet, it needs to use kfree() to free dbs_data directly when >> governor fails to allocate the tunner field of dbs_data. >> >> Signed-off-by: Liao Chang >> --- >> drivers/cpufreq/cpufreq_governor.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c >> index 85da677c43d6..6e1ac864e87e 100644 >> --- a/drivers/cpufreq/cpufreq_governor.c >> +++ b/drivers/cpufreq/cpufreq_governor.c >> @@ -438,8 +438,10 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) >> gov_attr_set_init(&dbs_data->attr_set, &policy_dbs->list); >> >> ret = gov->init(dbs_data); >> - if (ret) >> + if (ret) { >> + kfree(dbs_data); >> goto free_policy_dbs_info; >> + } > > What about this instead ? > > diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c > index 85da677c43d6..af44ee6a6430 100644 > --- a/drivers/cpufreq/cpufreq_governor.c > +++ b/drivers/cpufreq/cpufreq_governor.c > @@ -439,7 +439,7 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) > > ret = gov->init(dbs_data); > if (ret) > - goto free_policy_dbs_info; > + goto free_dbs_data; > > /* > * The sampling interval should not be less than the transition latency > @@ -474,6 +474,8 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) > if (!have_governor_per_policy()) > gov->gdbs_data = NULL; > gov->exit(dbs_data); > + > +free_dbs_data: > kfree(dbs_data); Sure, less copy-and-paste code is better :) Do you mind I copy above code in next revision? Thanks. > > free_policy_dbs_info: > -- BR Liao, Chang