From nobody Tue Dec 16 07:13:52 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22AE113D891 for ; Tue, 14 Jan 2025 18:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736878637; cv=none; b=JpL0PaugKfVyMjMdqMPunJ/yCM4l81g55oDybObsV7XcBI3fkIFTCMZnXuFhNQg1JjV43c/d5pLL/Qflu9/yfA4+WthHz7FcMRqw0NOns9Dp0ZKcz/dl5TI5vW4Dvk/wV/IgDhnpUkf3eVRo2RzV7fwyTXV0hdw/odFJw5900lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736878637; c=relaxed/simple; bh=5CKTYzeFI9xVT6Gfp9lhBqTUfnNdcMGy8htgqm9SI44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Js3tZ/XFBkeAqUpW/ZAbt2H4BUI6UgU5b6Dy816Kb1zuoxctekClbIlrRjfFItjivJ6VepsGXHtAV/QTGcxh1Z3QPXtspCxjO/TYiqPqYk66HkcNhPyXc0wu8+jtv4wzIe+RvIv5EPMBZkVev7pbmx/rN28K1IkN+ZP1cXR5qYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=DfJgUMri; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="DfJgUMri" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1736878633; bh=5CKTYzeFI9xVT6Gfp9lhBqTUfnNdcMGy8htgqm9SI44=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DfJgUMript4kQu01HustOE0qTEFY9P2sazYBZaS+JjeqMNgYmm7KB/C0I6KYWN3NR SLKtAofInEFaf7mLg176/tganHSbnRvGuzGDL9bUg8eoEePFRhwBcbjDgrb/D8iN6m sinQihzGPHZlMAsRp1OqibzayH3156zDqtglVuiqdzQAzcVQm0u+q64KbOBiZZOcZ/ +RoyT+/TcNcSDDln9faIm2wZuP33c7h5f9zYSLpJfPg5zOeBdkv59kvy6Jqgm4WyvB jlhxvWGTFt0+V0wGjVB//JTG6YARTO00F/UjLyqMkEqp9s7BdpYRkQ3exPv9wCPeEU GNUb8+XzaJ3jw== Received: from localhost (unknown [82.76.59.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id 1335D17E0DD3; Tue, 14 Jan 2025 19:17:13 +0100 (CET) From: Cristian Ciocaltea Date: Tue, 14 Jan 2025 20:16:56 +0200 Subject: [PATCH v3 1/2] drm/connector: hdmi: Handle NULL display mode in state check helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250114-hdmi-conn-null-mode-v3-1-16bca91e11b0@collabora.com> References: <20250114-hdmi-conn-null-mode-v3-0-16bca91e11b0@collabora.com> In-Reply-To: <20250114-hdmi-conn-null-mode-v3-0-16bca91e11b0@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , Dmitry Baryshkov Cc: kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno X-Mailer: b4 0.14.2 drm_atomic_helper_connector_hdmi_check() helper makes use of connector_state_get_mode() to obtain a drm_display_mode pointer, but it doesn't validate it, which may lead to a NULL pointer dereference in some cases, i.e. unloading a DRM module: [ 1002.910414] Unable to handle kernel NULL pointer dereference at virtual = address 0000000000000000 [...] [ 1002.923833] Hardware name: Radxa ROCK 5B (DT) [ 1002.924819] pc : drm_match_cea_mode+0x30/0x280 [drm] [ 1002.925318] lr : hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper] [...] [ 1002.932411] Call trace: [ 1002.932626] drm_match_cea_mode+0x30/0x280 [drm] (P) [ 1002.933120] hdmi_try_format_bpc+0x7c/0x580 [drm_display_helper] [ 1002.933662] drm_atomic_helper_connector_hdmi_check+0x10c/0x478 [drm_dis= play_helper] [ 1002.934355] drm_bridge_connector_atomic_check+0x20/0x40 [drm_display_he= lper] [ 1002.934993] drm_atomic_helper_check_modeset+0x698/0xd28 [drm_kms_helper] [ 1002.935607] drm_atomic_helper_check+0x28/0xb8 [drm_kms_helper] [ 1002.936143] drm_atomic_check_only+0x794/0x988 [drm] [ 1002.936635] drm_atomic_commit+0x60/0xe0 [drm] [ 1002.937082] drm_atomic_helper_disable_all+0x184/0x218 [drm_kms_helper] [ 1002.937678] drm_atomic_helper_shutdown+0x90/0x150 [drm_kms_helper] [ 1002.938243] rockchip_drm_unbind+0x38/0x80 [rockchipdrm] [ 1002.938720] component_master_del+0xac/0xf8 [ 1002.939089] rockchip_drm_platform_remove+0x34/0x78 [rockchipdrm] [...] Add the missing NULL check before passing the mode pointer further. Fixes: f035f4097f1e ("drm/connector: hdmi: Calculate TMDS character rate") Reviewed-by: Dmitry Baryshkov Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Cristian Ciocaltea --- drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c b/drivers/gpu/= drm/display/drm_hdmi_state_helper.c index cfc2aaee1da08a103cbf933c891d5cc31b0886a8..e4d4fce6ab59d37067327d3e6da= 235c9a5a45b42 100644 --- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c @@ -503,6 +503,9 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_c= onnector *connector, connector_state_get_mode(new_conn_state); int ret; =20 + if (!mode) + return 0; + new_conn_state->hdmi.is_limited_range =3D hdmi_is_limited_range(connector= , new_conn_state); =20 ret =3D hdmi_compute_config(connector, new_conn_state, mode); --=20 2.47.1 From nobody Tue Dec 16 07:13:52 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D53651FECC6 for ; Tue, 14 Jan 2025 18:17:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736878637; cv=none; b=rueydPmLsrAj3jD6l1+JJlzynApI4nwi46rGDMzK0SBlAgXsMyIqQD5v8X/l+RodcJOLVcqxzoCfaYGJNerHs57TB2tPjpaugG6FVjs6Ph+7JivLtMnfUQ36koX4uwhWkJL9uXXPhw04th+t3RJcW4ThrvkG7lY0g3UDeFyDPok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736878637; c=relaxed/simple; bh=+l9zb4hoh+tVTykJo0VS3bVUA00OYLvGyHXEer002NU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HwKoX0FhXbE6rLTzHSan8ku0yoMHiICXQujwSFTQmA+Vz+PoP7ttFONiz9LJkOyenyCquaEYm1/kvVui0M1vlFAbMYvYJzLtur/14G1Sur9W1B+DcbvyNuLURkNGPxgT1IRyeQgfPuVzv3AkajTpuqQPRxp557x/5Bpbgbqsvvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=O2g0FZip; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="O2g0FZip" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1736878634; bh=+l9zb4hoh+tVTykJo0VS3bVUA00OYLvGyHXEer002NU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O2g0FZipMJOuIqTyfJJo6gqDd2CgJf2YuaoVK5OC/qN0PGfnxYMlxArDg36xNOLv6 k1qCt091ArKVef/vbRj+aAnHPqS3gLXO+AxGakBzODM78AdXJK1eRLv+8Ybt7ayZdY D/jx/n+VM3fVO0xm0UXxIjgOcfYdaL+raQXgoGc6SXIc419XEThxEGA48LyRVJHvzd OgcZzlYPtIN7J/cUxQpcI/ViL73WhhpWXHi74JgahvOuqH/4Qf8SimXX0z+29JFn34 sFkJLSNQ4GpzqvnurMOcDQmArJo6BHH1qoOUXvDEepwemwNViUx8yfY2xRCGMc7jGI Gltb0DL8jlxuw== Received: from localhost (unknown [82.76.59.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by bali.collaboradmins.com (Postfix) with ESMTPSA id DD5F417E0E64; Tue, 14 Jan 2025 19:17:13 +0100 (CET) From: Cristian Ciocaltea Date: Tue, 14 Jan 2025 20:16:57 +0200 Subject: [PATCH v3 2/2] drm/tests: hdmi: Add connector's CRTC deactivation test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250114-hdmi-conn-null-mode-v3-2-16bca91e11b0@collabora.com> References: <20250114-hdmi-conn-null-mode-v3-0-16bca91e11b0@collabora.com> In-Reply-To: <20250114-hdmi-conn-null-mode-v3-0-16bca91e11b0@collabora.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , Dmitry Baryshkov Cc: kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 Following up a fixed bug in drm_atomic_helper_connector_hdmi_check(), discovered while unloading a DRM module, add a test to make sure the helper will not exhibit any abnormal behaviour for use cases that involve shutting down the connector's CRTC. Signed-off-by: Cristian Ciocaltea --- drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 76 ++++++++++++++++++= ++++ 1 file changed, 76 insertions(+) diff --git a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c b/drivers/g= pu/drm/tests/drm_hdmi_state_helper_test.c index c3b693bb966f1f8b04066d19f520bfa4bf11c23d..e6e79da200c4e81699c6e159a1b= b2725004baf96 100644 --- a/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +++ b/drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c @@ -1568,6 +1568,81 @@ static void drm_test_check_output_bpc_format_display= _8bpc_only(struct kunit *tes KUNIT_EXPECT_EQ(test, conn_state->hdmi.output_format, HDMI_COLORSPACE_RGB= ); } =20 +/* + * Test that if we deactivate connector's CRTC, we trigger a mode change + * on that CRTC, along with setting {connectors|active}_changed. + */ +static void drm_test_check_crtc_deactivate_mode_changed(struct kunit *test) +{ + struct drm_atomic_helper_connector_hdmi_priv *priv; + struct drm_modeset_acquire_ctx *ctx; + struct drm_connector_state *old_conn_state; + struct drm_connector_state *new_conn_state; + struct drm_crtc_state *old_crtc_state; + struct drm_crtc_state *new_crtc_state; + struct drm_atomic_state *state; + struct drm_display_mode *preferred; + struct drm_connector *conn; + struct drm_device *drm; + struct drm_crtc *crtc; + int ret; + + priv =3D drm_kunit_helper_connector_hdmi_init(test, + BIT(HDMI_COLORSPACE_RGB), + 8); + KUNIT_ASSERT_NOT_NULL(test, priv); + + conn =3D &priv->connector; + KUNIT_ASSERT_TRUE(test, conn->display_info.is_hdmi); + + ctx =3D drm_kunit_helper_acquire_ctx_alloc(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + preferred =3D find_preferred_mode(conn); + KUNIT_ASSERT_NOT_NULL(test, preferred); + + drm =3D &priv->drm; + crtc =3D priv->crtc; + ret =3D light_up_connector(test, drm, crtc, conn, preferred, ctx); + KUNIT_ASSERT_EQ(test, ret, 0); + + state =3D drm_kunit_helper_atomic_state_alloc(test, drm, ctx); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state); + + new_conn_state =3D drm_atomic_get_connector_state(state, conn); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_conn_state); + + old_conn_state =3D drm_atomic_get_old_connector_state(state, conn); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_conn_state); + + new_crtc_state =3D drm_atomic_get_crtc_state(state, crtc); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_crtc_state); + + old_crtc_state =3D drm_atomic_get_old_crtc_state(state, crtc); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, old_crtc_state); + + ret =3D drm_atomic_set_mode_for_crtc(new_crtc_state, NULL); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_ASSERT_NE(test, old_crtc_state->enable, new_crtc_state->enable); + + new_crtc_state->active =3D false; + KUNIT_ASSERT_NE(test, old_crtc_state->active, new_crtc_state->active); + + ret =3D drm_atomic_set_crtc_for_connector(new_conn_state, NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_ASSERT_PTR_NE(test, old_conn_state->crtc, new_conn_state->crtc); + + ret =3D drm_atomic_check_only(state); + KUNIT_ASSERT_EQ(test, ret, 0); + + new_crtc_state =3D drm_atomic_get_new_crtc_state(state, crtc); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_crtc_state); + KUNIT_EXPECT_TRUE(test, new_crtc_state->mode_changed); + KUNIT_EXPECT_TRUE(test, new_crtc_state->connectors_changed); + KUNIT_EXPECT_TRUE(test, new_crtc_state->active_changed); +} + static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = =3D { KUNIT_CASE(drm_test_check_broadcast_rgb_auto_cea_mode), KUNIT_CASE(drm_test_check_broadcast_rgb_auto_cea_mode_vic_1), @@ -1596,6 +1671,7 @@ static struct kunit_case drm_atomic_helper_connector_= hdmi_check_tests[] =3D { KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_8bpc), KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_10bpc), KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_12bpc), + KUNIT_CASE(drm_test_check_crtc_deactivate_mode_changed), /* * TODO: We should have tests to check that a change in the * format triggers a CRTC mode change just like we do for the --=20 2.47.1