mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dpu1: dpu_encoder: fix a missing check on list iterator
@ 2022-03-27  7:32 Xiaomeng Tong
  2022-04-11  0:56 ` Dmitry Baryshkov
  0 siblings, 1 reply; 3+ messages in thread
From: Xiaomeng Tong @ 2022-03-27  7:32 UTC (permalink / raw)
  To: robdclark, sean, airlied, daniel
  Cc: quic_abhinavk, dmitry.baryshkov, swboyd, bjorn.andersson,
	quic_khsieh, quic_kalyant, markyacoub, jsanka, linux-arm-msm,
	dri-devel, freedreno, linux-kernel, Xiaomeng Tong, stable

The bug is here:
	 cstate = to_dpu_crtc_state(drm_crtc->state);

For the drm_for_each_crtc(), just like list_for_each_entry(),
the list iterator 'drm_crtc' will point to a bogus position
containing HEAD if the list is empty or no element is found.
This case must be checked before any use of the iterator,
otherwise it will lead to a invalid memory access.

To fix this bug, use a new variable 'iter' as the list iterator,
while use the origin variable 'drm_crtc' as a dedicated pointer
to point to the found element.

Cc: stable@vger.kernel.org
Fixes: b107603b4ad0f ("drm/msm/dpu: map mixer/ctl hw blocks in encoder modeset")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
index 1e648db439f9..d3fdb18e96f9 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
@@ -965,7 +965,7 @@ static void dpu_encoder_virt_mode_set(struct drm_encoder *drm_enc,
 	struct dpu_kms *dpu_kms;
 	struct list_head *connector_list;
 	struct drm_connector *conn = NULL, *conn_iter;
-	struct drm_crtc *drm_crtc;
+	struct drm_crtc *drm_crtc = NULL, *iter;
 	struct dpu_crtc_state *cstate;
 	struct dpu_global_state *global_state;
 	struct dpu_hw_blk *hw_pp[MAX_CHANNELS_PER_ENC];
@@ -1007,9 +1007,14 @@ static void dpu_encoder_virt_mode_set(struct drm_encoder *drm_enc,
 		return;
 	}
 
-	drm_for_each_crtc(drm_crtc, drm_enc->dev)
-		if (drm_crtc->state->encoder_mask & drm_encoder_mask(drm_enc))
+	drm_for_each_crtc(iter, drm_enc->dev)
+		if (iter->state->encoder_mask & drm_encoder_mask(drm_enc)) {
+			drm_crtc = iter;
 			break;
+		}
+
+	if (!drm_crtc)
+		return;
 
 	/* Query resource that have been reserved in atomic check step. */
 	num_pp = dpu_rm_get_assigned_resources(&dpu_kms->rm, global_state,
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-11  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27  7:32 [PATCH] dpu1: dpu_encoder: fix a missing check on list iterator Xiaomeng Tong
2022-04-11  0:56 ` Dmitry Baryshkov
2022-04-11  1:20   ` Dmitry Baryshkov

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®