dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v9 09/13] drm/tegra: Convert to use atomic versions of drm_encoder_helper_funcs
Date: Mon, 30 Nov 2026 11:53:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-240985@kernel.org> (raw)
In-Reply-To: <20261130114155.72920-10-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/tegra: NULL dereference from new state lookup in
  atomic_disable()
- [Low] drm/tegra: redundant tegra_dsi_get_state() in
  tegra_dsi_encoder_enable()
--

commit 74ebbfecbca273aa0938d93154bb9f25f3ba63aa
Author: Svyatoslav Ryhel <clamor95@gmail.com>

drm/tegra: Convert to use atomic versions of drm_encoder_helper_funcs

This commit converts the Tegra DSI, HDMI, RGB, and SOR encoder helpers from
the legacy enable() and disable() callbacks to atomic_enable() and
atomic_disable().

> diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
> index 6d6adc485e51e..dd3fc09f57487 100644
> --- a/drivers/gpu/drm/tegra/dsi.c
> +++ b/drivers/gpu/drm/tegra/dsi.c

[ ... ]

> @@ -855,14 +863,21 @@ static void tegra_dsi_unprepare(struct tegra_dsi *dsi)
>  		dev_err(dsi->dev, "failed to suspend: %d\n", err);
>  }
>  
> -static void tegra_dsi_encoder_disable(struct drm_encoder *encoder)
> +static void tegra_dsi_encoder_disable(struct drm_encoder *encoder,
> +				      struct drm_atomic_commit *comm_state)
>  {
>  	struct tegra_output *output = encoder_to_output(encoder);
> -	struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
>  	struct tegra_dsi *dsi = to_dsi(output);
> +	struct drm_connector_state *conn_state;
> +	struct drm_connector *connector;
> +	struct tegra_dc *dc;
>  	u32 value;
>  	int err;
>  
> +	connector = drm_atomic_get_new_connector_for_encoder(comm_state, encoder);
> +	conn_state = drm_atomic_get_new_connector_state(comm_state, connector);
> +	dc = to_tegra_dc(conn_state->crtc);

[Severity: High]
Does looking up the new connector state in atomic_disable() cause a NULL
pointer dereference when disabling an output?

When an output is disabled, update_connector_routing() clears
new_conn_state->best_encoder to NULL before the commit phase runs
atomic_disable().  drm_atomic_get_new_connector_for_encoder() then returns
NULL, and drm_atomic_get_new_connector_state() dereferences connector->index.
Even if the connector were being moved to another CRTC, the new state would
point to the new CRTC rather than the old CRTC that was driving this encoder.

The same regression is present in tegra_hdmi_encoder_disable(),
tegra_sor_hdmi_disable(), and tegra_sor_dp_disable().  These disable
callbacks should query the old state via
drm_atomic_get_old_connector_for_encoder() and
drm_atomic_get_old_connector_state() (or drm_atomic_get_old_crtc_for_encoder()).

> @@ -919,16 +934,26 @@ static int tegra_dsi_prepare(struct tegra_dsi *dsi)
>  	return 0;
>  }
>  
> -static void tegra_dsi_encoder_enable(struct drm_encoder *encoder)
> +static void tegra_dsi_encoder_enable(struct drm_encoder *encoder,
> +				     struct drm_atomic_commit *comm_state)
>  {
> -	struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
>  	struct tegra_output *output = encoder_to_output(encoder);
> -	struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
>  	struct tegra_dsi *dsi = to_dsi(output);
> +	struct drm_connector_state *conn_state;
> +	struct drm_crtc_state *crtc_state;
> +	struct drm_connector *connector;
>  	struct tegra_dsi_state *state;
> +	struct drm_display_mode *mode;
> +	struct tegra_dc *dc;
>  	u32 value;
>  	int err;
>  
> +	connector = drm_atomic_get_new_connector_for_encoder(comm_state, encoder);
> +	conn_state = drm_atomic_get_new_connector_state(comm_state, connector);
> +	crtc_state = drm_atomic_get_new_crtc_state(comm_state, conn_state->crtc);
> +	dc = to_tegra_dc(conn_state->crtc);
> +	mode = &crtc_state->adjusted_mode;
> +
>  	err = tegra_dsi_prepare(dsi);
>  	if (err < 0) {
>  		dev_err(dsi->dev, "failed to prepare: %d\n", err);
> @@ -944,7 +969,7 @@ static void tegra_dsi_encoder_enable(struct drm_encoder *encoder)
>  	if (value & DSI_POWER_CONTROL_ENABLE)
>  		tegra_dsi_disable(dsi);
>  
> -	state = tegra_dsi_get_state(dsi);
> +	state = tegra_dsi_get_state(dsi, comm_state);
>  
>  	tegra_dsi_set_timeout(dsi, state->bclk, state->vrefresh);
>  
> @@ -957,7 +982,7 @@ static void tegra_dsi_encoder_enable(struct drm_encoder *encoder)
>  	if (output->panel)
>  		drm_panel_prepare(output->panel);
>  
> -	tegra_dsi_configure(dsi, dc->pipe, mode);
> +	tegra_dsi_configure(dsi, dc->pipe, mode, comm_state);

[Severity: Low]
As reported by Mikko Perttunen on v8 [1], since tegra_dsi_encoder_enable()
already retrieves conn_state via drm_atomic_get_new_connector_state(), can it
use to_dsi_state(conn_state) directly and pass struct tegra_dsi_state * into
tegra_dsi_configure() so tegra_dsi_get_state() can be dropped?

[1] https://lore.kernel.org/r/mxfdX1kqQz209wWYqFOofg@nvidia.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130114155.72920-1-clamor95@gmail.com?part=9

  parent reply	other threads:[~2026-11-30 11:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 11:41 [PATCH v9 00/13] drm/tegra: Add support for Tegra20/Tegra30 8-bit CPU interface Svyatoslav Ryhel
2026-11-30 11:41 ` [PATCH v9 01/13] drm: Add MIPI DBI bus support for MIPI DBI Type A and B Svyatoslav Ryhel
2026-11-30 11:55   ` sashiko-bot
2026-11-30 11:41 ` [PATCH v9 03/13] drm/panel: panel-hitachi-tx10d07vm0baa: Convert to mipi_dbi_write_seq_multi() Svyatoslav Ryhel
2026-11-30 11:41 ` [PATCH v9 04/13] drm/panel: panel-lg-lh400wv3: Convert to use MIPI DBI bus Svyatoslav Ryhel
2026-11-30 11:41 ` [PATCH v9 05/13] drm/panel: panel-lg-lh400wv3: Convert to mipi_dbi_write_seq_multi() Svyatoslav Ryhel
2026-11-30 11:41 ` [PATCH v9 06/13] drm/tegra: dc: Add elements required by Tegra MIPI DBI Svyatoslav Ryhel
2026-11-30 11:41 ` [PATCH v9 10/13] dt-bindings: display: tegra: Document nvidia, contiguous-rgb-pins property Svyatoslav Ryhel
     [not found] ` <20261130114155.72920-10-clamor95@gmail.com>
2026-11-30 11:53   ` sashiko-bot [this message]
     [not found] ` <20261130114155.72920-12-clamor95@gmail.com>
2026-11-30 11:59   ` [PATCH v9 11/13] drm/tegra: rgb: Parameterize configuration based on bus flags and DT property sashiko-bot
     [not found] ` <20261130114155.72920-14-clamor95@gmail.com>
2026-11-30 12:11   ` [PATCH v9 13/13] drm/tegra: Add support for 8-bit CPU interface sashiko-bot
     [not found] ` <20261130114155.72920-13-clamor95@gmail.com>
2026-11-30 13:59   ` [PATCH v9 12/13] dt-bindings: display: tegra: Document 8-bit CPU parallel interface Rob Herring (Arm)

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=sashiko-outbox-240985@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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