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: 74006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2852517wrt; Thu, 23 Mar 2023 04:27:30 -0700 (PDT) X-Google-Smtp-Source: AK7set93Xt/q8B4zNF6L44zKMsetF7EU4kymGh3Jrl0mnHEtnnTL//IDz8+g/xRRwxPiB1kFxNhk X-Received: by 2002:a05:6a20:1221:b0:d9:b59c:d09e with SMTP id v33-20020a056a20122100b000d9b59cd09emr2845996pzf.11.1679570850232; Thu, 23 Mar 2023 04:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679570850; cv=none; d=google.com; s=arc-20160816; b=LW5MgWq6U34OYphVclEWvFzFi6ozkOtsc1642mrXRTeDEaCAqxa5J0ZY/UxEvkhGL7 4SYEr2O5NsuPtApdUxjz4CK7aYMqBlVXQGNQl9vEfL5QFh2YXdUpuSGoPdcLTkU+ZVyl cEjnWaULnlxUNXROjIPZz1o+Ufwp6pWhJoq+PdX0aCpuRSM4l3nkXdkvGdBeZlmIIlLz j1Ivmer4Pa+GIPXuqkPOG98wQmwnfGMtb2eKnsCKUA6kGjg4XK2JVhUedtNCO3XcxN5l Blaj164OCCyfEy275w8254vFRXxv/ZX0mtDei9MBBay9En9PYg4lxbhk8vjueWj2KlFN kg5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=hofKIKZrcWEIKxsuY6is+jJOL7WfUkIDD9e2ocwx6b8=; b=HPQxUN9f6kWObFaS4Oqw4izZYQm2L5MjOkrV3vCuhfknqqfKtMVG7ODDtmV1JawnRr QrvzHlynuqdysrezEhGh4GqClWc7nFRBgDHqRy8cOaiQsTm+oYIKyprWGfvZVqeE98d8 uRTFGRKSyq4Nn4IB22rB8YMT2hdfhY5EBrCNPx/VOa+my90V2Ehb7LFeDjGAjl4Ut6L3 Qo36t9sqfLt+Ifv3NlFakeIfWihD/YnkouPd+PVB4DtDUG3jdG9PRUY8ZyyjBxg0Pt/J CuE+KYp1Y+S84yYV9mnbqHVMntlU4bBg5qxLpZzK/RQ/WSUnQ4x32UtoHBBpRpXdE+iL a5aQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a056a00174900b00627f3c6fc82si12185661pfc.60.2023.03.23.04.27.16; Thu, 23 Mar 2023 04:27:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbjCWLGW (ORCPT + 99 others); Thu, 23 Mar 2023 07:06:22 -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 X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761157683795530418?= X-GMAIL-MSGID: =?utf-8?q?1761157683795530418?= 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);