From patchwork Mon Jul 19 14:55:51 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: 480039 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4297363jao; Mon, 19 Jul 2021 09:43:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzUFkQChMJDcdakKFQFyy+KeND/tBugf2/VBAeaqFDJT6TnNqrEog6yDFQLTCr7Jrs6fTo X-Received: by 2002:aa7:d84f:: with SMTP id f15mr29642317eds.216.1626713030948; Mon, 19 Jul 2021 09:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626713030; cv=none; d=google.com; s=arc-20160816; b=bEX7klWj1Qf8zycazmAW922pOS3S9cxM4DpXFEmn5u5H/9OcTI8PwVZbESWTQjlSmV KIfFQK+lUuyoP1fAVtydAgCatr1hTZshC2SjoVClJbW4mHJpEOcr0ZDP996dDJGYYd3d BQ5ho0KnXy+6wYbXWlDlXkFhLdPoqZUMH9ZAM5QwHgqNcnZ0ZnPpi+psoFT49jBZLZBe +Zw/5kJSYdEkmkKSIHuHehD/tHcFjAHbohMlEGRy0nfShx2ujyZ7antfDhKH0Va3ytti 0Q8KFhBqkDvEqitqWdkk6HPEui9dbTK60Nq1E/RyhAkrBZNziPQIes6QCiRm8N1n8aMq 6YSw== 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=JhI0Kgm8yQyjgwoblT1TIm0MLrZlpwfIAHirDZA7EK4=; b=oL6+fjvhiGm5rDViHE+UgKblaYE3NpsmxIROQprdkawmHd3cfExKkQjBPFDuV7YaIW lrDf2XbiuOe5mng66fqUGl05LNyRjRubUsmnCZBswQQdfrlZIrBlAZ1exDkT0wGfh6u+ tQtVXG4/saVymMaGQYk1Bg1yPgYPAn/1R/6kxHSIJSsVptw7bY0O+wnspy3wUcnI/8LC a5w+wh5VKRe7PKwGCjkoMZ585iBS5OdRvXl2z0LWVY/wWrN5b/JMWA8zv5KqhfSrfDMR 3E6sL6dojVXJ/SoIp7+iO1obJk6MEC2kubAMg2PaeIkjM6XwQBrVLWYV124UAD9OK/ES IIGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qyzX5fn2; 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.43.50; Mon, 19 Jul 2021 09:43:50 -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=qyzX5fn2; 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 S1348568AbhGSPxb (ORCPT + 12 others); Mon, 19 Jul 2021 11:53:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:47918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350521AbhGSPvI (ORCPT ); Mon, 19 Jul 2021 11:51:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35CC361363; Mon, 19 Jul 2021 16:30:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626712205; bh=1m8a9wG0Vf4PcrJslbgMPBunyllvfzxWUshqR0E4KnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qyzX5fn2l8Y2V0CYd2SjNUZER8NtPpjoHtJVVawqKrXeFovL/G6LcigWP3Vh1UxDu TYXdLQfaySrkBZLbHfUflNKhmaNibO3LKQ7IMR5FpzEP5MehhJ92mQAvXEOm7Vlb+/ 71nzwR8JKKObbow3KB0by4EgIBW7eyTqursm0F4E= 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.12 289/292] cpufreq: CPPC: Fix potential memleak in cppc_cpufreq_cpu_init Date: Mon, 19 Jul 2021 16:55:51 +0200 Message-Id: <20210719144952.417634492@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.514164272@linuxfoundation.org> References: <20210719144942.514164272@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 8a482c434ea6..9ff81e260312 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); } /* @@ -340,7 +346,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; } /* @@ -355,10 +362,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; }