From: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
To: "Marek Szyprowski" <m.szyprowski@samsung.com>,
"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>,
"Philippe Cornu" <philippe.cornu@st.com>,
<benjamin.gaignard@linaro.org>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Robert Foss" <rfoss@kernel.org>,
"Laurent Pinchart" <Laurent.pinchart@ideasonboard.com>,
"Jonas Karlman" <jonas@kwiboo.se>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Adrien Grassein" <adrien.grassein@gmail.com>,
"Liu Ying" <victor.liu@nxp.com>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Inki Dae" <inki.dae@samsung.com>,
"Jagan Teki" <jagan@amarulasolutions.com>
Cc: "Hui Pu" <Hui.Pu@gehealthcare.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>,
<imx@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 10/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: use a temporary variable for the next bridge
Date: Thu, 08 Jan 2026 14:33:21 +0100 [thread overview]
Message-ID: <DFJ8VHH9BVEZ.2445GF73YTGSO@bootlin.com> (raw)
In-Reply-To: <be425ab8-1772-46fb-84ee-0c8840c3eef2@samsung.com>
Hi Marek,
On Thu Jan 8, 2026 at 10:26 AM CET, Marek Szyprowski wrote:
> On 07.01.2026 14:13, Luca Ceresoli wrote:
>> In preparation to handle refcounting of the out_bridge, we need to ensure
>> the out_bridge pointer contains either a valid bridge pointer or NULL, not
>> an ERR_PTR. Otherwise calls such as drm_bridge_get/put() would try to
>> redeference an ERR_PTR.
>>
>> As a preliminary cleanup, add a temporary local 'next_bridge' pointer and
>> only copy it in dsi->out_bridge when returning successfully.
>>
>> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>> ---
>> drivers/gpu/drm/bridge/samsung-dsim.c | 14 ++++++++------
>> 1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c
>> index eabc4c32f6ab..b3003aa49dc3 100644
>> --- a/drivers/gpu/drm/bridge/samsung-dsim.c
>> +++ b/drivers/gpu/drm/bridge/samsung-dsim.c
>> @@ -1886,6 +1886,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>> {
>> struct samsung_dsim *dsi = host_to_dsi(host);
>> const struct samsung_dsim_plat_data *pdata = dsi->plat_data;
>> + struct drm_bridge *next_bridge;
>> struct device *dev = dsi->dev;
>> struct device_node *np = dev->of_node;
>> struct device_node *remote;
>> @@ -1924,17 +1925,17 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>>
>> panel = of_drm_find_panel(remote);
>> if (!IS_ERR(panel)) {
>> - dsi->out_bridge = devm_drm_panel_bridge_add(dev, panel);
>> + next_bridge = devm_drm_panel_bridge_add(dev, panel);
>> } else {
>> - dsi->out_bridge = of_drm_find_bridge(remote);
>> - if (!dsi->out_bridge)
>> - dsi->out_bridge = ERR_PTR(-EINVAL);
>> + next_bridge = of_drm_find_bridge(remote);
>> + if (!next_bridge)
>> + next_bridge = ERR_PTR(-EINVAL);
>> }
>>
>> of_node_put(remote);
>>
>> - if (IS_ERR(dsi->out_bridge)) {
>> - ret = PTR_ERR(dsi->out_bridge);
>> + if (IS_ERR(next_bridge)) {
>> + ret = PTR_ERR(next_bridge);
>> DRM_DEV_ERROR(dev, "failed to find the bridge: %d\n", ret);
>> return ret;
>> }
>> @@ -1967,6 +1968,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
>> dsi->lanes = device->lanes;
>> dsi->format = device->format;
>> dsi->mode_flags = device->mode_flags;
>> + dsi->out_bridge = next_bridge;
>>
>
> This assignment is too late, dsi->out_bridge is used (indirectly, by
> samsung_dsim_attach() called from drm_bridge_attach()) by
>
> ret = pdata->host_ops->attach(dsi, device);
Thanks for testing, reporting, and suggesting a solution. I'm not sure why
it worked on my setup, but this is indeed a bug.
> a few lines before this assignment, so the following fix has to be added:
>
> diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c
> b/drivers/gpu/drm/bridge/samsung-dsim.c index b3003aa49dc3..f88aa8ab2879
> 100644 --- a/drivers/gpu/drm/bridge/samsung-dsim.c +++
> b/drivers/gpu/drm/bridge/samsung-dsim.c @@ -1959,6 +1959,7 @@ static int
> samsung_dsim_host_attach(struct mipi_dsi_host *host, return ret; } +
> dsi->out_bridge = next_bridge; if (pdata->host_ops &&
> pdata->host_ops->attach) { ret = pdata->host_ops->attach(dsi, device);
> if (ret) @@ -1968,7 +1969,6 @@ static int
> samsung_dsim_host_attach(struct mipi_dsi_host *host, dsi->lanes =
> device->lanes; dsi->format = device->format; dsi->mode_flags =
> device->mode_flags; - dsi->out_bridge = next_bridge; return 0; }
This needed a bit of demangling :) but it looks like a correct solution.
I took a moment to understand why this did not break my setup. The answer
is I have a fsl,imx8mp-mipi-dsim, which has no .attach set in its
samsung_dsim_host_ops.
Sorry for the inconvenience. I'm fixing this in v2.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-01-08 13:33 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260107131333eucas1p2ee0b7afe47dc2fafa29e893e4283962b@eucas1p2.samsung.com>
2026-01-07 13:12 ` [PATCH 00/12] drm/bridge: convert users of of_drm_find_bridge(), part 2 Luca Ceresoli
2026-01-07 13:12 ` [PATCH 01/12] drm: of: drm_of_panel_bridge_remove(): fix device_node leak Luca Ceresoli
2026-01-07 13:33 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 02/12] drm: of: drm_of_panel_bridge_remove(): convert to of_drm_find_and_get_bridge() Luca Ceresoli
2026-01-07 13:34 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 03/12] drm/bridge: sii902x: " Luca Ceresoli
2026-01-07 13:38 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 04/12] drm/bridge: thc63lvd1024: " Luca Ceresoli
2026-01-07 13:38 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 05/12] drm/bridge: tfp410: " Luca Ceresoli
2026-01-07 13:38 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 06/12] drm/bridge: tpd12s015: " Luca Ceresoli
2026-01-07 13:39 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 07/12] drm/bridge: lt8912b: " Luca Ceresoli
2026-01-07 13:56 ` Maxime Ripard
2026-01-07 13:12 ` [PATCH 08/12] drm/bridge: imx8mp-hdmi-pvi: " Luca Ceresoli
2026-01-07 13:56 ` Maxime Ripard
2026-01-07 13:13 ` [PATCH 09/12] drm/bridge: imx8qxp-ldb: " Luca Ceresoli
2026-01-07 14:08 ` Maxime Ripard
2026-01-07 14:45 ` Luca Ceresoli
2026-01-07 13:13 ` [PATCH 10/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: use a temporary variable for the next bridge Luca Ceresoli
2026-01-07 14:09 ` Maxime Ripard
2026-01-08 9:26 ` Marek Szyprowski
2026-01-08 13:33 ` Luca Ceresoli [this message]
2026-01-07 13:13 ` [PATCH 11/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: don't use the bridge pointer as an error indicator Luca Ceresoli
2026-01-07 14:11 ` Maxime Ripard
2026-01-07 13:13 ` [PATCH 12/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: convert to of_drm_find_and_get_bridge() Luca Ceresoli
2026-01-07 14:26 ` Maxime Ripard
2026-01-07 23:48 ` [PATCH 00/12] drm/bridge: convert users of of_drm_find_bridge(), part 2 Marek Szyprowski
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=DFJ8VHH9BVEZ.2445GF73YTGSO@bootlin.com \
--to=luca.ceresoli@bootlin.com \
--cc=Hui.Pu@gehealthcare.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=adrien.grassein@gmail.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=benjamin.gaignard@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=inki.dae@samsung.com \
--cc=jagan@amarulasolutions.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=philippe.cornu@st.com \
--cc=rfoss@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=simona@ffwll.ch \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
--cc=victor.liu@nxp.com \
/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.