All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "Laurentiu Palcu" <laurentiu.palcu@oss.nxp.com>,
	<imx@lists.linux.dev>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>
Cc: <dri-devel@lists.freedesktop.org>,
	"Sandor Yu" <sandor.yu@nxp.com>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 5/9] drm/imx: Add support for i.MX94 DCIF
Date: Fri, 31 Oct 2025 09:14:45 +0100	[thread overview]
Message-ID: <DDWCVYBQSV10.2MFZFEEHPYJY4@bootlin.com> (raw)
In-Reply-To: <20250911-dcif-upstreaming-v5-5-a1e8dab8ae40@oss.nxp.com>

Hello Laurentiu,

On Thu Sep 11, 2025 at 1:37 PM CEST, Laurentiu Palcu wrote:

...

> +static struct drm_bridge *dcif_crtc_get_bridge(struct drm_crtc *crtc,
> +					       struct drm_crtc_state *crtc_state)
> +{
> +	struct drm_connector_state *conn_state;
> +	struct drm_encoder *encoder;
> +	struct drm_connector *conn;
> +	struct drm_bridge *bridge;
> +	int i;
> +
> +	for_each_new_connector_in_state(crtc_state->state, conn, conn_state, i) {
> +		if (crtc != conn_state->crtc)
> +			continue;
> +
> +		encoder = conn_state->best_encoder;
> +
> +		bridge = drm_bridge_chain_get_first_bridge(encoder);

The bridge returned by drm_bridge_chain_get_first_bridge() is refcounted
since v6.18-rc1 [0], so you have to put that reference...

> +		if (bridge)
> +			return bridge;
> +	}
> +
> +	return NULL;
> +}
> +
> +static void dcif_crtc_query_output_bus_format(struct drm_crtc *crtc,
> +					      struct drm_crtc_state *crtc_state)
> +{
> +	struct dcif_crtc_state *dcif_state = to_dcif_crtc_state(crtc_state);
> +	struct drm_bridge_state *bridge_state;
> +	struct drm_bridge *bridge;
> +
> +	dcif_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
> +	dcif_state->bus_flags = 0;
> +
> +	bridge = dcif_crtc_get_bridge(crtc, crtc_state);
> +	if (!bridge)
> +		return;
> +
> +	bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state, bridge);
> +	if (!bridge_state)
> +		return;
> +
> +	dcif_state->bus_format = bridge_state->input_bus_cfg.format;
> +	dcif_state->bus_flags = bridge_state->input_bus_cfg.flags;

...perhaps here, when both the bridge pointer and the bridge_state pointer
referencing it go out of scope.

> +}

You can just call drm_bridge_put(bridge) there, or (at your option) use a
cleanup action:

 static void dcif_crtc_query_output_bus_format(struct drm_crtc *crtc,
                                               struct drm_crtc_state *crtc_state)
 {
         struct dcif_crtc_state *dcif_state = to_dcif_crtc_state(crtc_state);
         struct drm_bridge_state *bridge_state;
-        struct drm_bridge *bridge;

         dcif_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
         dcif_state->bus_flags = 0;

-        bridge = dcif_crtc_get_bridge(crtc, crtc_state);
+        struct drm_bridge *bridge __free(drm_bridge_put) = dcif_crtc_get_bridge(crtc, crtc_state);
         if (!bridge)
                 return;

         bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state, bridge);
         if (!bridge_state)
                 return;

         dcif_state->bus_format = bridge_state->input_bus_cfg.format;
         dcif_state->bus_flags = bridge_state->input_bus_cfg.flags;
 }

This would call drm_bridge_put() at end of scope, i.e. end of function.

You can also have a look at recent commits involving drm_bridge_put (git
log -p -Gdrm_bridge_put v6.16..origin/master) to see how other parts of the
kernel have added drm_bridge_put().

[0] https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/8fa5909400f377351836419223c33f1131f0f7d3

Best regards,
Luca

---
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2025-10-31  8:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 11:37 [PATCH v5 0/9] Add support for i.MX94 DCIF Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 1/9] dt-bindings: display: fsl,ldb: Add i.MX94 LDB Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 2/9] drm/bridge: fsl-ldb: Get the next non-panel bridge Laurentiu Palcu
2025-10-29 12:58   ` Francesco Valla
2025-09-11 11:37 ` [PATCH v5 3/9] drm/bridge: fsl-ldb: Add support for i.MX94 Laurentiu Palcu
2025-10-31  8:27   ` Luca Ceresoli
2025-10-31 12:15     ` Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 4/9] dt-bindings: display: imx: Add i.MX94 DCIF Laurentiu Palcu
2025-09-11 15:26   ` Frank Li
2025-09-12  7:09   ` Krzysztof Kozlowski
2025-09-11 11:37 ` [PATCH v5 5/9] drm/imx: Add support for " Laurentiu Palcu
2025-10-31  8:14   ` Luca Ceresoli [this message]
2025-10-31 12:15     ` Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 6/9] dt-bindings: clock: nxp,imx95-blk-ctl: Add ldb child node Laurentiu Palcu
2025-09-11 11:37   ` [PATCH v5 6/9] dt-bindings: clock: nxp, imx95-blk-ctl: " Laurentiu Palcu
2025-09-12  7:10   ` [PATCH v5 6/9] dt-bindings: clock: nxp,imx95-blk-ctl: " Krzysztof Kozlowski
2025-09-11 11:37 ` [PATCH v5 7/9] arm64: dts: imx943: Add display pipeline nodes Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 8/9] arm64: dts: imx943-evk: Add display support using IT6263 Laurentiu Palcu
2025-09-11 11:37 ` [PATCH v5 9/9] MAINTAINERS: Add entry for i.MX94 DCIF driver Laurentiu Palcu

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=DDWCVYBQSV10.2MFZFEEHPYJY4@bootlin.com \
    --to=luca.ceresoli@bootlin.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=laurentiu.palcu@oss.nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sandor.yu@nxp.com \
    --cc=shawnguo@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.