[PATCH 09/12] drm/atomic-helper: Mark drm_atomic_crtc_state_for_each_plane_state() unsafe
Ville Syrjala
ville.syrjala at linux.intel.com
Mon Nov 16 01:11:27 PST 2026
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
drm_atomic_crtc_state_for_each_plane_state() uses the unsafe
__drm_atomic_get_current_plane_state() under the hood. Mark
it all unsafe and give it a __drm prefix to make it doubly
clear that it's a footgun waiting to happen.
I want the old name for a slightly different (safer) purpose.
Everyone really should stop using this, and find a better
way to do things.
Cc: Miguel Ojeda <ojeda at kernel.org>
Cc: amd-gfx at lists.freedesktop.org
Cc: André Almeida <andrealmeid at igalia.com>
Cc: Boris Brezillon <bbrezillon at kernel.org>
Cc: Christopher Snowhill <chris at kode54.net>
Cc: Dave Stevenson <dave.stevenson at raspberrypi.com>
Cc: Dharma Balasubiramani <dharma.b at microchip.com>
Cc: Dmitry Baryshkov <lumag at kernel.org>
Cc: freedreno at lists.freedesktop.org
Cc: Gustavo Padovan <gustavo.padovan at collabora.com>
Cc: Huacai Chen <chenhuacai at kernel.org>
Cc: Icenowy Zheng <zhengxingda at iscas.ac.cn>
Cc: intel-gfx at lists.freedesktop.org
Cc: intel-xe at lists.freedesktop.org
Cc: Jianmin Lv <lvjianmin at loongson.cn>
Cc: linux-arm-msm at vger.kernel.org
Cc: linux-mediatek at lists.infradead.org
Cc: linux-rockchip at lists.infradead.org
Cc: linux-tegra at vger.kernel.org
Cc: Liviu Dudau <liviu.dudau at arm.com>
Cc: Maíra Canal <mcanal at igalia.com>
Cc: Manikandan Muralidharan <manikandan.m at microchip.com>
Cc: Maxime Ripard <mripard at kernel.org>
Cc: Mingcong Bai <jeffbai at aosc.io>
Cc: nouveau at lists.freedesktop.org
Cc: Qianhai Wu <wuqianhai at loongson.cn>
Cc: Raspberry Pi Kernel Maintenance <kernel-list at raspberrypi.com>
Cc: Simon Ser <contact at emersion.fr>
Cc: wayland-devel at lists.freedesktop.org
Cc: Xaver Hugl <xaver.hugl at kde.org>
Cc: Xi Ruoyao <xry111 at xry111.site>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
.clang-format | 2 +-
drivers/gpu/drm/arm/malidp_crtc.c | 6 +++---
drivers/gpu/drm/i915/display/i9xx_wm.c | 2 +-
drivers/gpu/drm/i915/display/intel_display.h | 4 ++--
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c | 2 +-
drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 2 +-
drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 2 +-
drivers/gpu/drm/tegra/dc.c | 6 +++---
drivers/gpu/drm/vc4/vc4_hvs.c | 2 +-
include/drm/drm_atomic.h | 6 +++---
include/drm/drm_atomic_helper.h | 12 ++++++++----
11 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/.clang-format b/.clang-format
index 395292ab2ac6..db707fd6a684 100644
--- a/.clang-format
+++ b/.clang-format
@@ -160,7 +160,7 @@ ForEachMacros:
- 'do_for_each_ftrace_op'
- 'drm_atomic_crtc_for_each_plane'
- 'drm_atomic_crtc_state_for_each_plane'
- - 'drm_atomic_crtc_state_for_each_plane_state'
+ - '__drm_atomic_crtc_state_for_each_plane_state_unsafe'
- 'drm_atomic_for_each_plane_damage'
- 'drm_client_for_each_connector_iter'
- 'drm_client_for_each_modeset'
diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c
index ec7b9db8b0b4..3c02f7ec92b8 100644
--- a/drivers/gpu/drm/arm/malidp_crtc.c
+++ b/drivers/gpu/drm/arm/malidp_crtc.c
@@ -268,7 +268,7 @@ static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc,
if (scaling & (scaling - 1))
return -EINVAL;
- drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, pstate, state) {
struct malidp_plane *mp = to_malidp_plane(plane);
u32 phase;
@@ -373,7 +373,7 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc,
*/
/* first count the number of rotated planes */
- drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, pstate, crtc_state) {
struct drm_framebuffer *fb = pstate->fb;
if ((pstate->rotation & MALIDP_ROTATED_MASK) || fb->modifier)
@@ -389,7 +389,7 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc,
rot_mem_free += hwdev->rotation_memory[1];
/* now validate the rotation memory requirements */
- drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, pstate, crtc_state) {
struct malidp_plane *mp = to_malidp_plane(plane);
struct malidp_plane_state *ms = to_malidp_plane_state(pstate);
struct drm_framebuffer *fb = pstate->fb;
diff --git a/drivers/gpu/drm/i915/display/i9xx_wm.c b/drivers/gpu/drm/i915/display/i9xx_wm.c
index 46bfada7c060..efd1791efd5f 100644
--- a/drivers/gpu/drm/i915/display/i9xx_wm.c
+++ b/drivers/gpu/drm/i915/display/i9xx_wm.c
@@ -2931,7 +2931,7 @@ static int ilk_compute_pipe_wm(struct intel_atomic_state *state,
pipe_wm = &crtc_state->wm.ilk.optimal;
- intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
+ __intel_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, crtc_state) {
if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
pristate = plane_state;
else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY)
diff --git a/drivers/gpu/drm/i915/display/intel_display.h b/drivers/gpu/drm/i915/display/intel_display.h
index d53b7b4a80e7..43701325b3de 100644
--- a/drivers/gpu/drm/i915/display/intel_display.h
+++ b/drivers/gpu/drm/i915/display/intel_display.h
@@ -307,13 +307,13 @@ enum phy_fia {
for_each_if(((old_crtc_state) = intel_atomic_get_old_crtc_state((__state), (crtc)), \
(new_crtc_state) = intel_atomic_get_new_crtc_state((__state), (crtc))))
-#define intel_atomic_crtc_state_for_each_plane_state( \
+#define __intel_atomic_crtc_state_for_each_plane_state_unsafe( \
plane, plane_state, \
crtc_state) \
for_each_intel_plane_mask(((crtc_state)->uapi.state->dev), (plane), \
((crtc_state)->uapi.plane_mask)) \
for_each_if ((plane_state = \
- to_intel_plane_state(__drm_atomic_get_current_plane_state((crtc_state)->uapi.state, &plane->base))))
+ to_intel_plane_state(__drm_atomic_get_current_plane_state_unsafe((crtc_state)->uapi.state, &plane->base))))
#define for_each_new_intel_connector_in_state(__state, connector, new_connector_state, __i) \
for ((__i) = 0; \
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
index 9fa55904dba1..6f45adb9c7ae 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c
@@ -65,7 +65,7 @@ static u64 _dpu_core_perf_calc_bw(const struct dpu_perf_cfg *perf_cfg,
u64 crtc_plane_bw = 0;
u32 bw_factor;
- drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, state)
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, state)
crtc_plane_bw += to_dpu_plane_state(plane_state)->plane_fetch_bw;
bw_factor = perf_cfg->bw_inefficiency_factor;
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index 77a2d1f6700d..f5cf9cae732e 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -1568,7 +1568,7 @@ static int dpu_crtc_atomic_check(struct drm_crtc *crtc,
}
/* FIXME: move this to dpu_plane_atomic_check? */
- drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, pstate, crtc_state) {
struct dpu_plane_state *dpu_pstate = to_dpu_plane_state(pstate);
if (IS_ERR_OR_NULL(pstate)) {
diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
index 1e1fff37380c..df85027b7ee0 100644
--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
@@ -711,7 +711,7 @@ static int mdp5_crtc_atomic_check(struct drm_crtc *crtc,
DBG("%s: check", crtc->name);
- drm_atomic_crtc_state_for_each_plane_state(plane, pstate, crtc_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, pstate, crtc_state) {
struct mdp5_plane_state *mdp5_pstate =
to_mdp5_plane_state(pstate);
diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 9cd6399b85bb..4ce93b2ef300 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -2471,7 +2471,7 @@ tegra_plane_overlap_mask(struct drm_crtc_state *state,
if (tegra_plane_is_cursor(plane_state))
return 0;
- drm_atomic_crtc_state_for_each_plane_state(plane, other_state, state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, other_state, state) {
rect = plane_state->dst;
tegra = to_tegra_plane(other_state->plane);
@@ -2529,7 +2529,7 @@ static int tegra_crtc_calculate_memory_bandwidth(struct drm_crtc *crtc,
* overlap. Note that bitmask[plane] includes BIT(plane) in order
* to make further code nicer and simpler.
*/
- drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, new_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, new_state) {
tegra_state = to_const_tegra_plane_state(plane_state);
tegra = to_tegra_plane(plane);
@@ -2559,7 +2559,7 @@ static int tegra_crtc_calculate_memory_bandwidth(struct drm_crtc *crtc,
* in order to set up latency allowance based on the peak BW, see
* tegra_crtc_update_memory_bandwidth().
*/
- drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, new_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, new_state) {
u32 i, old_peak_bw, new_peak_bw, overlap_bw = 0;
/*
diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
index 537aaa992129..abda0309393b 100644
--- a/drivers/gpu/drm/vc4/vc4_hvs.c
+++ b/drivers/gpu/drm/vc4/vc4_hvs.c
@@ -806,7 +806,7 @@ int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
if (hweight32(crtc_state->connector_mask) > 1)
return -EINVAL;
- drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
+ __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, crtc_state) {
u32 plane_dlist_count = vc4_plane_dlist_size(plane_state);
drm_dbg_driver(dev, "[CRTC:%d:%s] Found [PLANE:%d:%s] with DLIST size: %u\n",
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index f60a77ad9b9b..b6414229dc8f 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -887,7 +887,7 @@ drm_atomic_get_new_connector_state(const struct drm_atomic_commit *state,
}
/**
- * __drm_atomic_get_current_plane_state - get current plane state
+ * __drm_atomic_get_current_plane_state_unsafe - get current plane state
* @state: global atomic state object
* @plane: plane to grab
*
@@ -913,8 +913,8 @@ drm_atomic_get_new_connector_state(const struct drm_atomic_commit *state,
* Read-only pointer to the current plane state.
*/
static inline const struct drm_plane_state *
-__drm_atomic_get_current_plane_state(const struct drm_atomic_commit *state,
- struct drm_plane *plane)
+__drm_atomic_get_current_plane_state_unsafe(const struct drm_atomic_commit *state,
+ struct drm_plane *plane)
{
struct drm_plane_state *plane_state;
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 278560760e6e..06b6dc9bc4be 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -214,7 +214,7 @@ int drm_atomic_helper_page_flip_target(
drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
/**
- * drm_atomic_crtc_state_for_each_plane_state - iterate over attached planes in new state
+ * __drm_atomic_crtc_state_for_each_plane_state_unsafe - iterate over attached planes in new state
* @plane: the loop cursor
* @plane_state: loop cursor for the plane's state, must be const
* @crtc_state: the incoming CRTC state
@@ -227,12 +227,16 @@ int drm_atomic_helper_page_flip_target(
* Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a
* const plane_state. This is useful when a driver just wants to peek at other
* active planes on this CRTC, but does not need to change it.
+ *
+ * WARNING:
+ * This is generally unsafe to use. See
+ * __drm_atomic_get_current_plane_state_unsafe() for further details.
*/
-#define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \
+#define __drm_atomic_crtc_state_for_each_plane_state_unsafe(plane, plane_state, crtc_state) \
drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \
for_each_if ((plane_state = \
- __drm_atomic_get_current_plane_state((crtc_state)->state, \
- plane)))
+ __drm_atomic_get_current_plane_state_unsafe((crtc_state)->state, \
+ plane)))
/**
* drm_atomic_plane_enabling - check whether a plane is being enabled
--
2.56.0
More information about the Linux-rockchip
mailing list