Skip to content

Commit 31ad37b

Browse files
committed
Revert "drm/vc4: hdmi: Remove drm_encoder->crtc usage"
This reverts commit 27da370. Sudip Mukherjee reports that this broke pulseaudio with a NULL pointer dereference in vc4_hdmi_audio_prepare(), bisected it to this commit, and confirmed that a revert fixed the problem. Revert the problematic commit until fixed. Link: https://lore.kernel.org/all/CADVatmPB9-oKd=ypvj25UYysVo6EZhQ6bCM7EvztQBMyiZfAyw@mail.gmail.com/ Link: https://lore.kernel.org/all/CADVatmN5EpRshGEPS_JozbFQRXg5w_8LFB3OMP1Ai-ghxd3w4g@mail.gmail.com/ Reported-and-tested-by: Sudip Mukherjee <[email protected]> Cc: Maxime Ripard <[email protected]> Cc: Emma Anholt <[email protected]> Cc: Dave Airlie <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b1044a9 commit 31ad37b

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

drivers/gpu/drm/vc4/vc4_hdmi.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
432432
struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
433433
struct drm_connector *connector = &vc4_hdmi->connector;
434434
struct drm_connector_state *cstate = connector->state;
435-
struct drm_crtc *crtc = cstate->crtc;
435+
struct drm_crtc *crtc = encoder->crtc;
436436
const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
437437
union hdmi_infoframe frame;
438438
int ret;
@@ -537,11 +537,8 @@ static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder,
537537

538538
static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
539539
{
540+
struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
540541
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
541-
struct drm_connector *connector = &vc4_hdmi->connector;
542-
struct drm_connector_state *cstate = connector->state;
543-
struct drm_crtc *crtc = cstate->crtc;
544-
struct drm_display_mode *mode = &crtc->state->adjusted_mode;
545542

546543
if (!vc4_hdmi_supports_scrambling(encoder, mode))
547544
return;
@@ -562,18 +559,17 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
562559
static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
563560
{
564561
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
565-
struct drm_connector *connector = &vc4_hdmi->connector;
566-
struct drm_connector_state *cstate = connector->state;
562+
struct drm_crtc *crtc = encoder->crtc;
567563

568564
/*
569-
* At boot, connector->state will be NULL. Since we don't know the
565+
* At boot, encoder->crtc will be NULL. Since we don't know the
570566
* state of the scrambler and in order to avoid any
571567
* inconsistency, let's disable it all the time.
572568
*/
573-
if (cstate && !vc4_hdmi_supports_scrambling(encoder, &cstate->crtc->mode))
569+
if (crtc && !vc4_hdmi_supports_scrambling(encoder, &crtc->mode))
574570
return;
575571

576-
if (cstate && !vc4_hdmi_mode_needs_scrambling(&cstate->crtc->mode))
572+
if (crtc && !vc4_hdmi_mode_needs_scrambling(&crtc->mode))
577573
return;
578574

579575
if (delayed_work_pending(&vc4_hdmi->scrambling_work))
@@ -895,9 +891,7 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
895891
vc4_hdmi_encoder_get_connector_state(encoder, state);
896892
struct vc4_hdmi_connector_state *vc4_conn_state =
897893
conn_state_to_vc4_hdmi_conn_state(conn_state);
898-
struct drm_crtc_state *crtc_state =
899-
drm_atomic_get_new_crtc_state(state, conn_state->crtc);
900-
struct drm_display_mode *mode = &crtc_state->adjusted_mode;
894+
struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
901895
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
902896
unsigned long bvb_rate, pixel_rate, hsm_rate;
903897
int ret;
@@ -991,11 +985,7 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
991985
static void vc4_hdmi_encoder_pre_crtc_enable(struct drm_encoder *encoder,
992986
struct drm_atomic_state *state)
993987
{
994-
struct drm_connector_state *conn_state =
995-
vc4_hdmi_encoder_get_connector_state(encoder, state);
996-
struct drm_crtc_state *crtc_state =
997-
drm_atomic_get_new_crtc_state(state, conn_state->crtc);
998-
struct drm_display_mode *mode = &crtc_state->adjusted_mode;
988+
struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
999989
struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
1000990
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
1001991

@@ -1018,11 +1008,7 @@ static void vc4_hdmi_encoder_pre_crtc_enable(struct drm_encoder *encoder,
10181008
static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
10191009
struct drm_atomic_state *state)
10201010
{
1021-
struct drm_connector_state *conn_state =
1022-
vc4_hdmi_encoder_get_connector_state(encoder, state);
1023-
struct drm_crtc_state *crtc_state =
1024-
drm_atomic_get_new_crtc_state(state, conn_state->crtc);
1025-
struct drm_display_mode *mode = &crtc_state->adjusted_mode;
1011+
struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
10261012
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
10271013
struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
10281014
bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
@@ -1210,8 +1196,8 @@ static void vc4_hdmi_audio_set_mai_clock(struct vc4_hdmi *vc4_hdmi,
12101196

12111197
static void vc4_hdmi_set_n_cts(struct vc4_hdmi *vc4_hdmi, unsigned int samplerate)
12121198
{
1213-
struct drm_connector *connector = &vc4_hdmi->connector;
1214-
struct drm_crtc *crtc = connector->state->crtc;
1199+
struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base;
1200+
struct drm_crtc *crtc = encoder->crtc;
12151201
const struct drm_display_mode *mode = &crtc->state->adjusted_mode;
12161202
u32 n, cts;
12171203
u64 tmp;
@@ -1244,13 +1230,13 @@ static inline struct vc4_hdmi *dai_to_hdmi(struct snd_soc_dai *dai)
12441230
static int vc4_hdmi_audio_startup(struct device *dev, void *data)
12451231
{
12461232
struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
1247-
struct drm_connector *connector = &vc4_hdmi->connector;
1233+
struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base;
12481234

12491235
/*
12501236
* If the HDMI encoder hasn't probed, or the encoder is
12511237
* currently in DVI mode, treat the codec dai as missing.
12521238
*/
1253-
if (!connector->state || !(HDMI_READ(HDMI_RAM_PACKET_CONFIG) &
1239+
if (!encoder->crtc || !(HDMI_READ(HDMI_RAM_PACKET_CONFIG) &
12541240
VC4_HDMI_RAM_PACKET_ENABLE))
12551241
return -ENODEV;
12561242

0 commit comments

Comments
 (0)