From patchwork Mon Jul 19 14:54:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 480019 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4283100jao; Mon, 19 Jul 2021 09:25:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvu2tbo3sOotC/6nvVmFiPdUBIMWxoxQQGXhImQYUhbzmnoQjBOpdPP5Rby3g5iRrzrjK/ X-Received: by 2002:a17:906:ecb3:: with SMTP id qh19mr19943537ejb.113.1626711843784; Mon, 19 Jul 2021 09:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626711843; cv=none; d=google.com; s=arc-20160816; b=DurZZRDCX58L+hXaROWPbSGcg6J+Z+VM+D7A2pZQniRMqh2E0CnKHym0DDgoJY9qia wdnjaur3Ro36yl0cH2DaODtaG8uwZN+ViWTnP+7MKvrpf3OFZzMFaBtrjEiL/R0c0j0J vKaOzIl5ws2kiNFgUMzyodXqrzjqqXlYh+nLA7g49fZZ27b/xpYfkavgw2R1w2RsycbX KsqqlBqQU1AeCfjgBc3/fYtruUFSw1kGOf5lsq8fbjZYmHm2G1ZZcUWN7EZQQRecgI0F cwG+L4Cpz9xvXWGHRjwyZ/3yH7002w4bxuoqE91FnDeNdlnndIIYEuBOqSrE6e+w3s36 hS3A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TXoM0TUs46xoJU2xE2//eLp17egryRCMot4LfUx/hdg=; b=mkszrxC7uagIRwPJVQ6rI9yjYOXMAWV0EuJkcgHRh9umS1pn68D0Z2eQqynINaddwe 5t/KMFCYZVbHEIdr0JbLDnc6IiLgg721mvjP9m/CGhbEfOv6RG2l4cSV4zVsnw9CG1KE Dw85yCfUuQt1yHnWmNhYYzP4WNHUunrPE/55irkhNtyhb/zbNNdrwnrRTnDOKelYFoSc 9hdRkQ1BmPxoJn/VTgs7X2/z4ofuM679Mtwmw8owHC1AmhWTO9+5xtSewqiIffhC/yA9 FgUP/omo1E05G9oJbgNJBEAyIXn9wma619Gonx7eMZag6qlIp84Ps4QD2wbRmSnKFTsO ++sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BjFSAYdG; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id la14si22045543ejc.142.2021.07.19.09.24.03; Mon, 19 Jul 2021 09:24:03 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BjFSAYdG; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348330AbhGSPmU (ORCPT + 12 others); Mon, 19 Jul 2021 11:42:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:34260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234856AbhGSPgr (ORCPT ); Mon, 19 Jul 2021 11:36:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 54419606A5; Mon, 19 Jul 2021 16:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626711444; bh=fP0m3WY17hnKw1M+oJUapFVATVZnva9yK9aXl3RzQ+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BjFSAYdGvEpbWhczQwayI2ph03F2TNO53AEtlzKWEVOeHF7kRg98s/5yT3ZnGbqHp mDJ1/jTq4nDRbAc4gkqwN+PvFSD41J1xchGLyWlz8CKVKs4OqrWHnDrF6j2owcX+Tj pK0N96XlTxfMSCU6MWdhGQLkHw21aW3ZvVoLdJnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Guittot , Ionela Voinescu , Qian Cai , Viresh Kumar , Sasha Levin Subject: [PATCH 5.13 349/351] cpufreq: CPPC: Fix potential memleak in cppc_cpufreq_cpu_init Date: Mon, 19 Jul 2021 16:54:55 +0200 Message-Id: <20210719144956.621145339@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144944.537151528@linuxfoundation.org> References: <20210719144944.537151528@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Viresh Kumar [ Upstream commit fe2535a44904a77615a3af8e8fd7dafb98fb0e1b ] It's a classic example of memleak, we allocate something, we fail and never free the resources. Make sure we free all resources on policy ->init() failures. Fixes: a28b2bfc099c ("cppc_cpufreq: replace per-cpu data array with a list") Tested-by: Vincent Guittot Reviewed-by: Ionela Voinescu Tested-by: Qian Cai Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/cpufreq/cppc_cpufreq.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) -- 2.30.2 diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 2f769b1630c5..a27445f40d2c 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -182,6 +182,16 @@ static int cppc_verify_policy(struct cpufreq_policy_data *policy) return 0; } +static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy) +{ + struct cppc_cpudata *cpu_data = policy->driver_data; + + list_del(&cpu_data->node); + free_cpumask_var(cpu_data->shared_cpu_map); + kfree(cpu_data); + policy->driver_data = NULL; +} + static void cppc_cpufreq_stop_cpu(struct cpufreq_policy *policy) { struct cppc_cpudata *cpu_data = policy->driver_data; @@ -196,11 +206,7 @@ static void cppc_cpufreq_stop_cpu(struct cpufreq_policy *policy) pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", caps->lowest_perf, cpu, ret); - /* Remove CPU node from list and free driver data for policy */ - free_cpumask_var(cpu_data->shared_cpu_map); - list_del(&cpu_data->node); - kfree(policy->driver_data); - policy->driver_data = NULL; + cppc_cpufreq_put_cpu_data(policy); } /* @@ -330,7 +336,8 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) default: pr_debug("Unsupported CPU co-ord type: %d\n", policy->shared_type); - return -EFAULT; + ret = -EFAULT; + goto out; } /* @@ -345,10 +352,16 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) cpu_data->perf_ctrls.desired_perf = caps->highest_perf; ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) + if (ret) { pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", caps->highest_perf, cpu, ret); + goto out; + } + return 0; + +out: + cppc_cpufreq_put_cpu_data(policy); return ret; }