Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2176976rwi; Tue, 1 Nov 2022 04:57:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7+/bxZAaqL8BJxDlB5NESf8svCTjg6MCa06UR7zfUwj6Rce1c5aYkhxLTpTcHhLp3PUFfe X-Received: by 2002:aa7:cb09:0:b0:461:e6b6:4bad with SMTP id s9-20020aa7cb09000000b00461e6b64badmr19049090edt.27.1667303841969; Tue, 01 Nov 2022 04:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667303841; cv=none; d=google.com; s=arc-20160816; b=0XQsQBQqnOX2A9UDtedP+8V3ymWpwINUmcMYL0PTBcQlV4nKTJ/3RXbTvmVUfg0c4E PeLpu22AjxeF7Zkrof5a1DfNfzPo1kDLQDYP6y0RoYZiMPG9sr99378dUb66jH6A9Mls +/jB3R0QejxbpCzQGTr6PVdZlCjhr71aF6l2tRvpvbj47EglLhic9on70pphavpaXgEF VVjvcOPRGinzi6pbsuEHbDra+/1/B8LkBtk81wFgenDLLljJDezyPWHNxxBnIbIV6KOd //g1yTfm8ISwIPbrxdQRvIMgCklv7YVbDP2zcoag0646wBppAqEiPouuvRZKSfZ28+wA 0wqA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QcGw9r/DebUuxm/osa5ArEEhvXnP6Tg2W0Vu/KCDg0o=; b=CwUtbjwLoFOTF8sW8tEaODuXIgwKrcsgjjkNwdfo5iv5tWXJ4vbA8GgIiT4jhOIl+6 0BVMjGbbCi0po9fyhblm21fpcs3zuxGOCT+ejjZPlDDEEOM2DCXoB41NG4TCCHnjeCgT IuWIuigpm3udARCKUDg4Mgz/xQRbMvkxSHEgDLx3gmu1CVmTL9MXgZHfyMp4TeQrmkNW nI/gsw6iaZNwLu0RXiY/5eSFQ9viHZAIxGzKLtIdED4BYwkZ7edEWX3XapKwiJEK5gh+ oBriO5doYC8L50cu1CD9biobUl3k39zVvHzhsjVDAF0wVlUEI+bvK6vEVWygrxfWDh1O SFeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=doCpQkVE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a50c10a000000b004617bf36c3csi9918568edf.308.2022.11.01.04.56.57; Tue, 01 Nov 2022 04:57:21 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=doCpQkVE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229992AbiKAL3w (ORCPT + 97 others); Tue, 1 Nov 2022 07:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbiKAL2l (ORCPT ); Tue, 1 Nov 2022 07:28:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7436C2652; Tue, 1 Nov 2022 04:28:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D214F615DD; Tue, 1 Nov 2022 11:28:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 226E6C433B5; Tue, 1 Nov 2022 11:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667302105; bh=7r1QOHV06h+9wzOcTmWBQcgWcXag41HhBfVH04SzsOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doCpQkVEkrCtyIEp6fXWy5cc8w+s4OPCSdGLPiwU9wNq8/mJ8KVFyRlueJwsAVsRO 5cNz7UkqW+Vxu6wTM6sVqITv9DbwBLBjXjKw1eZ6uwDwyfcykxaHs5GxP1taNJXyd+ Ohp0YDJIpBZL1g1FrFTcHm6Aab0IPW5jEpwt5OWCC/+D7XGGuFnbEcxKOr4ZlgNLq3 jt3GZ+jtGzbDvni3FujWG9P1sw/+jIAQ3kmSrSOf9jGqqJPJbrbMQTLZr9K84T+ga3 fxZH0RNfGkb1OQn3/1ORuKUBXX5t7nHSbo/qrWx8NLcz/vx24t2Pc+uH4EkRxdVMvd iF+bUxlcjw+RQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Maxime Ripard , Javier Martinez Canillas , Stefan Wahren , Sasha Levin , emma@anholt.net, mripard@kernel.org, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.0 20/34] drm/vc4: hdmi: Check the HSM rate at runtime_resume Date: Tue, 1 Nov 2022 07:27:12 -0400 Message-Id: <20221101112726.799368-20-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221101112726.799368-1-sashal@kernel.org> References: <20221101112726.799368-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Maxime Ripard [ Upstream commit 4190e8bbcbc77a9c36724681801cedc5229e7fc2 ] If our HSM clock has not been properly initialized, any register access will silently lock up the system. Let's check that this can't happen by adding a check for the rate before any register access, and error out otherwise. Link: https://lore.kernel.org/dri-devel/20220922145448.w3xfywkn5ecak2et@pengutronix.de/ Reviewed-by: Javier Martinez Canillas Tested-by: Stefan Wahren Signed-off-by: Maxime Ripard Link: https://patchwork.freedesktop.org/patch/msgid/20220929-rpi-pi3-unplugged-fixes-v1-2-cd22e962296c@cerno.tech Signed-off-by: Sasha Levin --- drivers/gpu/drm/vc4/vc4_hdmi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 1e5f68704d7d..3d8fc32b4d08 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -2869,12 +2869,28 @@ static int vc4_hdmi_runtime_resume(struct device *dev) struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev); unsigned long __maybe_unused flags; u32 __maybe_unused value; + unsigned long rate; int ret; ret = clk_prepare_enable(vc4_hdmi->hsm_clock); if (ret) return ret; + /* + * Whenever the RaspberryPi boots without an HDMI monitor + * plugged in, the firmware won't have initialized the HSM clock + * rate and it will be reported as 0. + * + * If we try to access a register of the controller in such a + * case, it will lead to a silent CPU stall. Let's make sure we + * prevent such a case. + */ + rate = clk_get_rate(vc4_hdmi->hsm_clock); + if (!rate) { + ret = -EINVAL; + goto err_disable_clk; + } + if (vc4_hdmi->variant->reset) vc4_hdmi->variant->reset(vc4_hdmi); @@ -2896,6 +2912,10 @@ static int vc4_hdmi_runtime_resume(struct device *dev) #endif return 0; + +err_disable_clk: + clk_disable_unprepare(vc4_hdmi->hsm_clock); + return ret; } static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) -- 2.35.1