mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>,
	Harry Wentland <harry.wentland@amd.com>,
	Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>,
	Tom Chung <chiahsuan.chung@amd.com>, Roman Li <roman.li@amd.com>,
	Alex Hung <alex.hung@amd.com>,
	Aurabindo Pillai <aurabindo.pillai@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	Sasha Levin <sashal@kernel.org>,
	sunpeng.li@amd.com, christian.koenig@amd.com, airlied@gmail.com,
	simona@ffwll.ch, mario.limonciello@amd.com, Wayne.Lin@amd.com,
	dominik.kaszewski@amd.com, mwen@igalia.com,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 10/43] drm/amd/display: Add NULL pointer checks in dm_force_atomic_commit()
Date: Sun,  1 Jun 2025 19:41:50 -0400	[thread overview]
Message-ID: <20250601234224.3517599-10-sashal@kernel.org> (raw)
In-Reply-To: <20250601234224.3517599-1-sashal@kernel.org>

From: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>

[ Upstream commit 3f397cd203f247879c2f1a061e90d4c8d23655de ]

This commit updates the dm_force_atomic_commit function to replace the
usage of PTR_ERR_OR_ZERO with IS_ERR for checking error states after
retrieving the Connector (drm_atomic_get_connector_state), CRTC
(drm_atomic_get_crtc_state), and Plane (drm_atomic_get_plane_state)
states.

The function utilized PTR_ERR_OR_ZERO for error checking. However, this
approach is inappropriate in this context because the respective
functions do not return NULL; they return pointers that encode errors.

This change ensures that error pointers are properly checked using
IS_ERR before attempting to dereference.

Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Cc: Tom Chung <chiahsuan.chung@amd.com>
Cc: Roman Li <roman.li@amd.com>
Cc: Alex Hung <alex.hung@amd.com>
Cc: Aurabindo Pillai <aurabindo.pillai@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

Based on my analysis, here's my assessment: **YES** This commit should
be backported to stable kernel trees. Here's my detailed analysis: ##
Commit Analysis **1. Bug Fix Nature:** This commit fixes a clear
programming error where `PTR_ERR_OR_ZERO()` was incorrectly used to
check error pointers returned by `drm_atomic_get_connector_state()`,
`drm_atomic_get_crtc_state()`, and `drm_atomic_get_plane_state()`. The
commit message clearly states these functions "do not return NULL; they
return pointers that encode errors." **2. Specific Code Issues Fixed:**
- **Before:** Used `PTR_ERR_OR_ZERO(conn_state)` which is inappropriate
since these functions never return NULL - **After:** Uses
`IS_ERR(conn_state)` followed by `PTR_ERR(conn_state)` which is the
correct pattern for error pointer checking **3. Comparison with Similar
Commits:** Looking at the provided examples, this commit closely matches
**Similar Commit #4 (Status: YES)** which also: - Adds null pointer
checks for proper error handling - Fixes potential crashes from
dereferencing error pointers - Is a small, contained bug fix - Addresses
static analysis findings (Coverity-style issues) **4. Risk Assessment:**
- **Low Risk:** The change is minimal and only affects error handling
paths - **No Architectural Changes:** This is purely a bug fix with no
feature additions - **Contained Impact:** Only affects the
`dm_force_atomic_commit()` function in AMD display driver - **Improves
Stability:** Prevents potential kernel crashes from dereferencing error
pointers **5. Stable Tree Criteria Met:** - ✅ Fixes an important bug
(potential crash) - ✅ Small and contained change - ✅ No new features
introduced - ✅ Minimal regression risk - ✅ Clear fix for incorrect API
usage **6. Critical System Impact:** The DRM subsystem is critical for
display functionality, and improper error handling in atomic commits
could lead to: - Kernel oops/crashes during display mode changes -
System instability during hotplug events - Potential security
implications from dereferencing invalid pointers The fix ensures proper
error propagation in the display driver's atomic commit path, which is
essential for system stability.

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 25e1908b2fd33..e4b697f2a9f14 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -10049,16 +10049,20 @@ static int dm_force_atomic_commit(struct drm_connector *connector)
 	 */
 	conn_state = drm_atomic_get_connector_state(state, connector);
 
-	ret = PTR_ERR_OR_ZERO(conn_state);
-	if (ret)
+	/* Check for error in getting connector state */
+	if (IS_ERR(conn_state)) {
+		ret = PTR_ERR(conn_state);
 		goto out;
+	}
 
 	/* Attach crtc to drm_atomic_state*/
 	crtc_state = drm_atomic_get_crtc_state(state, &disconnected_acrtc->base);
 
-	ret = PTR_ERR_OR_ZERO(crtc_state);
-	if (ret)
+	/* Check for error in getting crtc state */
+	if (IS_ERR(crtc_state)) {
+		ret = PTR_ERR(crtc_state);
 		goto out;
+	}
 
 	/* force a restore */
 	crtc_state->mode_changed = true;
@@ -10066,9 +10070,11 @@ static int dm_force_atomic_commit(struct drm_connector *connector)
 	/* Attach plane to drm_atomic_state */
 	plane_state = drm_atomic_get_plane_state(state, plane);
 
-	ret = PTR_ERR_OR_ZERO(plane_state);
-	if (ret)
+	/* Check for error in getting plane state */
+	if (IS_ERR(plane_state)) {
+		ret = PTR_ERR(plane_state);
 		goto out;
+	}
 
 	/* Call commit internally with the state we just constructed */
 	ret = drm_atomic_commit(state);
-- 
2.39.5


  parent reply	other threads:[~2025-06-01 23:42 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-01 23:41 [PATCH AUTOSEL 5.15 01/43] drm/amdgpu/gfx6: fix CSIB handling Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 02/43] sunrpc: update nextcheck time when adding new cache entries Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 03/43] drm/bridge: analogix_dp: Add irq flag IRQF_NO_AUTOEN instead of calling disable_irq() Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 04/43] exfat: fix double free in delayed_free Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 05/43] arm64/cpuinfo: only show one cpu's info in c_show() Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 06/43] drm/bridge: anx7625: change the gpiod_set_value API Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 07/43] media: i2c: imx334: Enable runtime PM before sub-device registration Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 08/43] drm/msm/hdmi: add runtime PM calls to DDC transfer function Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 09/43] media: uapi: v4l: Fix V4L2_TYPE_IS_OUTPUT condition Sasha Levin
2025-06-01 23:41 ` Sasha Levin [this message]
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 11/43] drm/msm/a6xx: Increase HFI response timeout Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 12/43] media: i2c: imx334: Fix runtime PM handling in remove function Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 13/43] drm/amdgpu/gfx10: fix CSIB handling Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 14/43] media: ccs-pll: Better validate VT PLL branch Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 15/43] media: uapi: v4l: Change V4L2_TYPE_IS_CAPTURE condition Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 16/43] drm/amdgpu/gfx7: fix CSIB handling Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 17/43] ext4: ext4: unify EXT4_EX_NOCACHE|NOFAIL flags in ext4_ext_remove_space() Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 18/43] jfs: fix array-index-out-of-bounds read in add_missing_indices Sasha Levin
2025-06-01 23:41 ` [PATCH AUTOSEL 5.15 19/43] media: ti: cal: Fix wrong goto on error path Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 20/43] media: rkvdec: h264: Use bytesperline and buffer height as virstride Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 21/43] media: rkvdec: Initialize the m2m context before the controls Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 22/43] sunrpc: fix race in cache cleanup causing stale nextcheck time Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 23/43] ext4: prevent stale extent cache entries caused by concurrent get es_cache Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 24/43] drm/amdgpu/gfx8: fix CSIB handling Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 25/43] drm/amdgpu/gfx9: " Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 26/43] jfs: Fix null-ptr-deref in jfs_ioc_trim Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 27/43] drm/msm/dpu: don't select single flush for active CTL blocks Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 28/43] drm/amdkfd: Set SDMA_RLCx_IB_CNTL/SWITCH_INSIDE_IB Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 29/43] media: tc358743: ignore video while HPD is low Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 30/43] media: platform: exynos4-is: Add hardware sync wait to fimc_is_hw_change_mode() Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 31/43] media: i2c: imx334: update mode_3840x2160_regs array Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 32/43] nios2: force update_mmu_cache on spurious tlb-permission--related pagefaults Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 33/43] ACPI: bus: Bail out if acpi_kobj registration fails Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 34/43] pmdomain: ti: Fix STANDBY handling of PER power domain Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 35/43] PM: runtime: fix denying of auto suspend in pm_suspend_timer_fn() Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 36/43] thermal/drivers/qcom/tsens: Update conditions to strictly evaluate for IP v2+ Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 37/43] clocksource: Fix the CPUs' choice in the watchdog per CPU verification Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 38/43] ACPICA: Avoid sequence overread in call to strncmp() Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 39/43] ACPICA: utilities: Fix overflow check in vsnprintf() Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 40/43] ALSA: seq: Remove unused snd_seq_queue_client_leave_cells Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 41/43] cpufreq: Force sync policy boost with global boost on sysfs update Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 42/43] power: supply: bq27xxx: Retrieve again when busy Sasha Levin
2025-06-01 23:42 ` [PATCH AUTOSEL 5.15 43/43] ASoC: tas2770: Power cycle amp on ISENSE/VSENSE change Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250601234224.3517599-10-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Wayne.Lin@amd.com \
    --cc=airlied@gmail.com \
    --cc=alex.hung@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=aurabindo.pillai@amd.com \
    --cc=chiahsuan.chung@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dominik.kaszewski@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=harry.wentland@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mwen@igalia.com \
    --cc=nicholas.kazlauskas@amd.com \
    --cc=patches@lists.linux.dev \
    --cc=roman.li@amd.com \
    --cc=simona@ffwll.ch \
    --cc=srinivasan.shanmugam@amd.com \
    --cc=stable@vger.kernel.org \
    --cc=sunpeng.li@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®