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: 13185516 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55CCBC6FD1C for ; Thu, 23 Mar 2023 11:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=D7MTPgl+1Zhx4KZzAKzzCWsSw0+62wZfZw+H6K+N26g=; b=Per6Ah89Ai2sHB FwwbgxIzwKY96GD60KNzML7iOTzFJVewOH1UdcT4nvp2xfMBKpNvZh2H0Wwaxm4jdWnoQJ8Qbg1Me UlYagPOSUBoc0e+FeGcoFM8Eh5QDtJ01DC4ojIWpM8XZ+CUwgMXDaqhuVMnBzGdyXBnEMAiA1rYgM OZA1o2OzYJFiFDdC5J3tPLm+gAKIrc0cNMrHT6UcTE5jpYobFJ3f62VyJo8B4L1JqXpOpomwwcxAI TfH4Z3utMQHgbJeiKG+PoCkERm5ay8g3gaLgvudhLe1ej1HsZBa6YVB+OcAz+ayyWI0PyWXH2gMks 12H9Pu/TsW+LIKLHee5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pfIlz-001fVo-2I; Thu, 23 Mar 2023 11:06:23 +0000 Received: from fudo.makrotopia.org ([2a07:2ec0:3002::71]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pfIlw-001fV6-1d; Thu, 23 Mar 2023 11:06:21 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230323_040620_558854_F0D4FC66 X-CRM114-Status: GOOD ( 10.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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);