From patchwork Thu Mar 23 11:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 666442 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 9BE6EC6FD1D for ; Thu, 23 Mar 2023 11:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbjCWLGV (ORCPT ); Thu, 23 Mar 2023 07:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbjCWLGV (ORCPT ); Thu, 23 Mar 2023 07:06:21 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B4CB10AA5; Thu, 23 Mar 2023 04:06:19 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pfIlm-0002bz-3B; Thu, 23 Mar 2023 12:06:11 +0100 Date: Thu, 23 Mar 2023 11:04:23 +0000 From: Daniel Golle To: linux-pm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Viresh Kumar , Matthias Brugger , AngeloGioacchino Del Regno Cc: Sam Shih , John Crispin Subject: [PATCH] cpufreq: mediatek: guard error paths to avoid kernel panic Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Guard pointer access in error path of mtk_cpu_dvfs_info_init() to make sure info->proc_reg and info->sram_reg are valid pointers before accessing them, which would result in kernel panic e.g. in case of them being set to -EPROBE_DEFER. Fixes: 4b9ceb757bbb ("cpufreq: mediatek: Enable clocks and regulators") Reported-by: Sam Shih Suggested-by: Sam Shih Signed-off-by: Daniel Golle --- drivers/cpufreq/mediatek-cpufreq.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c index 4466d0c91a6a..980a31ddd0f2 100644 --- a/drivers/cpufreq/mediatek-cpufreq.c +++ b/drivers/cpufreq/mediatek-cpufreq.c @@ -579,10 +579,12 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu) dev_pm_opp_of_cpumask_remove_table(&info->cpus); out_free_resources: - if (regulator_is_enabled(info->proc_reg)) - regulator_disable(info->proc_reg); - if (info->sram_reg && regulator_is_enabled(info->sram_reg)) - regulator_disable(info->sram_reg); + if (!IS_ERR(info->proc_reg)) + if (regulator_is_enabled(info->proc_reg)) + regulator_disable(info->proc_reg); + if (!IS_ERR(info->sram_reg)) + if (info->sram_reg && regulator_is_enabled(info->sram_reg)) + regulator_disable(info->sram_reg); if (!IS_ERR(info->proc_reg)) regulator_put(info->proc_reg);