* [PATCH v2 0/2] drm/vc4: hdmi: Fix pointer dereference before check @ 2022-11-10 13:47 José Expósito 2022-11-10 13:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() José Expósito 2022-11-10 13:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito 0 siblings, 2 replies; 5+ messages in thread From: José Expósito @ 2022-11-10 13:47 UTC (permalink / raw) To: mripard Cc: emma, airlied, daniel, dri-devel, linux-kernel, José Expósito v1 -> v2: As suggested by Maxime, I simplified a bit vc4_hdmi_supports_scrambling() making it receive a struct vc4_hdmi as argument instead of a struct drm_encoder. Also, variables are initialized close to where they are used in the second patch. José Expósito (2): drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() drm/vc4: hdmi: Fix pointer dereference before check drivers/gpu/drm/vc4/vc4_hdmi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() 2022-11-10 13:47 [PATCH v2 0/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito @ 2022-11-10 13:47 ` José Expósito 2022-11-10 13:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito 1 sibling, 0 replies; 5+ messages in thread From: José Expósito @ 2022-11-10 13:47 UTC (permalink / raw) To: mripard Cc: emma, airlied, daniel, dri-devel, linux-kernel, José Expósito Simplify vc4_hdmi_supports_scrambling() by changing its first parameter from struct drm_encoder to struct vc4_hdmi. Signed-off-by: José Expósito <jose.exposito89@gmail.com> --- drivers/gpu/drm/vc4/vc4_hdmi.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 0d78c800ed51..a49f88e5d2b9 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -124,9 +124,8 @@ static unsigned long long vc4_hdmi_encoder_compute_mode_clock(const struct drm_display_mode *mode, unsigned int bpc, enum vc4_hdmi_output_format fmt); -static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder) +static bool vc4_hdmi_supports_scrambling(struct vc4_hdmi *vc4_hdmi) { - struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct drm_display_info *display = &vc4_hdmi->connector.display_info; lockdep_assert_held(&vc4_hdmi->mutex); @@ -321,7 +320,6 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, { struct drm_device *drm = connector->dev; struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); - struct drm_encoder *encoder = &vc4_hdmi->encoder.base; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -349,7 +347,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!crtc_state->active) return 0; - if (!vc4_hdmi_supports_scrambling(encoder)) + if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return 0; scrambling_needed = vc4_hdmi_mode_needs_scrambling(&vc4_hdmi->saved_adjusted_mode, @@ -867,7 +865,7 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder) lockdep_assert_held(&vc4_hdmi->mutex); - if (!vc4_hdmi_supports_scrambling(encoder)) + if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return; if (!vc4_hdmi_mode_needs_scrambling(mode, -- 2.25.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check 2022-11-10 13:47 [PATCH v2 0/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito 2022-11-10 13:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() José Expósito @ 2022-11-10 13:47 ` José Expósito 2022-11-17 17:28 ` Nick Desaulniers 1 sibling, 1 reply; 5+ messages in thread From: José Expósito @ 2022-11-10 13:47 UTC (permalink / raw) To: mripard Cc: emma, airlied, daniel, dri-devel, linux-kernel, José Expósito Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced the vc4_hdmi_reset_link() function. This function dereferences the "connector" pointer before checking whether it is NULL or not. Rework variable assignment to avoid this issue. Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") Signed-off-by: José Expósito <jose.exposito89@gmail.com> --- drivers/gpu/drm/vc4/vc4_hdmi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index a49f88e5d2b9..6b223a5fcf6f 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -318,8 +318,8 @@ static int reset_pipe(struct drm_crtc *crtc, static int vc4_hdmi_reset_link(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx) { - struct drm_device *drm = connector->dev; - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); + struct drm_device *drm; + struct vc4_hdmi *vc4_hdmi; struct drm_connector_state *conn_state; struct drm_crtc_state *crtc_state; struct drm_crtc *crtc; @@ -330,6 +330,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!connector) return 0; + drm = connector->dev; ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx); if (ret) return ret; @@ -347,6 +348,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, if (!crtc_state->active) return 0; + vc4_hdmi = connector_to_vc4_hdmi(connector); if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) return 0; -- 2.25.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check 2022-11-10 13:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito @ 2022-11-17 17:28 ` Nick Desaulniers 2022-11-17 17:32 ` Nathan Chancellor 0 siblings, 1 reply; 5+ messages in thread From: Nick Desaulniers @ 2022-11-17 17:28 UTC (permalink / raw) To: José Expósito Cc: mripard, emma, airlied, daniel, dri-devel, linux-kernel, llvm On Thu, Nov 10, 2022 at 02:47:52PM +0100, José Expósito wrote: > Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced > the vc4_hdmi_reset_link() function. This function dereferences the > "connector" pointer before checking whether it is NULL or not. > > Rework variable assignment to avoid this issue. > > Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") > Signed-off-by: José Expósito <jose.exposito89@gmail.com> > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index a49f88e5d2b9..6b223a5fcf6f 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -318,8 +318,8 @@ static int reset_pipe(struct drm_crtc *crtc, > static int vc4_hdmi_reset_link(struct drm_connector *connector, > struct drm_modeset_acquire_ctx *ctx) > { > - struct drm_device *drm = connector->dev; > - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); > + struct drm_device *drm; > + struct vc4_hdmi *vc4_hdmi; Hi, I think this change, or another in this area recently, is causing the following warning. PTAL drivers/gpu/drm/vc4/vc4_hdmi.c:351:14: warning: variable 'vc4_hdmi' is uninitialized when used here [-Wuninitialized] mutex_lock(&vc4_hdmi->mutex); ^~~~~~~~ drivers/gpu/drm/vc4/vc4_hdmi.c:322:27: note: initialize the variable 'vc4_hdmi' to silence this warning struct vc4_hdmi *vc4_hdmi; ^ = NULL > struct drm_connector_state *conn_state; > struct drm_crtc_state *crtc_state; > struct drm_crtc *crtc; > @@ -330,6 +330,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, > if (!connector) > return 0; > > + drm = connector->dev; > ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx); > if (ret) > return ret; > @@ -347,6 +348,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, > if (!crtc_state->active) > return 0; > > + vc4_hdmi = connector_to_vc4_hdmi(connector); > if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) > return 0; > > -- > 2.25.1 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check 2022-11-17 17:28 ` Nick Desaulniers @ 2022-11-17 17:32 ` Nathan Chancellor 0 siblings, 0 replies; 5+ messages in thread From: Nathan Chancellor @ 2022-11-17 17:32 UTC (permalink / raw) To: Nick Desaulniers Cc: José Expósito, mripard, emma, airlied, daniel, dri-devel, linux-kernel, llvm On Thu, Nov 17, 2022 at 09:28:49AM -0800, Nick Desaulniers wrote: > On Thu, Nov 10, 2022 at 02:47:52PM +0100, José Expósito wrote: > > Commit 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") introduced > > the vc4_hdmi_reset_link() function. This function dereferences the > > "connector" pointer before checking whether it is NULL or not. > > > > Rework variable assignment to avoid this issue. > > > > Fixes: 6bed2ea3cb38 ("drm/vc4: hdmi: Reset link on hotplug") > > Signed-off-by: José Expósito <jose.exposito89@gmail.com> > > --- > > drivers/gpu/drm/vc4/vc4_hdmi.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > > index a49f88e5d2b9..6b223a5fcf6f 100644 > > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > > @@ -318,8 +318,8 @@ static int reset_pipe(struct drm_crtc *crtc, > > static int vc4_hdmi_reset_link(struct drm_connector *connector, > > struct drm_modeset_acquire_ctx *ctx) > > { > > - struct drm_device *drm = connector->dev; > > - struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); > > + struct drm_device *drm; > > + struct vc4_hdmi *vc4_hdmi; > > Hi, I think this change, or another in this area recently, is causing > the following warning. PTAL > > drivers/gpu/drm/vc4/vc4_hdmi.c:351:14: warning: variable 'vc4_hdmi' is uninitialized when used here [-Wuninitialized] > mutex_lock(&vc4_hdmi->mutex); > ^~~~~~~~ > drivers/gpu/drm/vc4/vc4_hdmi.c:322:27: note: initialize the variable 'vc4_hdmi' to silence this warning > struct vc4_hdmi *vc4_hdmi; > ^ > = NULL Guess we just crossed paths but this is just a problem with -next due to a bad conflict resolution on Stephen's part: https://lore.kernel.org/Y3ZvffZiR+SgtY6h@dev-arch.thelio-3990X/ > > struct drm_connector_state *conn_state; > > struct drm_crtc_state *crtc_state; > > struct drm_crtc *crtc; > > @@ -330,6 +330,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, > > if (!connector) > > return 0; > > > > + drm = connector->dev; > > ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx); > > if (ret) > > return ret; > > @@ -347,6 +348,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector, > > if (!crtc_state->active) > > return 0; > > > > + vc4_hdmi = connector_to_vc4_hdmi(connector); This version of the patch is fine, as there is no mutex_lock() call here. > > if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) > > return 0; > > > > -- > > 2.25.1 > > > > > Cheers, Nathan ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-17 17:32 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-11-10 13:47 [PATCH v2 0/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito 2022-11-10 13:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Pass vc4_hdmi to vc4_hdmi_supports_scrambling() José Expósito 2022-11-10 13:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Fix pointer dereference before check José Expósito 2022-11-17 17:28 ` Nick Desaulniers 2022-11-17 17:32 ` Nathan Chancellor
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®