From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0C0832F750 for ; Fri, 9 Jan 2026 08:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767948574; cv=none; b=Ac5V6/WTTxuqi4UATEatUpmLuckDUKiWVDt6j0rUCoq56RVhN2ejxDWaW0lekmhDGFebJ4WwPfaz6BTNH7wxLa1BKjOErQv8tI1Ks4i/i2UP41ikcajB2dqFJIssWL9BqlpKLjnzohc7fHK9PWFRTCcykkqZhYCc5jCidMBqctI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767948574; c=relaxed/simple; bh=2JzW8EO1rUI59BPjma0QygJYtEOpyoEa24wfVHdgqXs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:In-Reply-To: Content-Type:References; b=DE7Wlj+i2nddpbGykXgv5ixLY3pnhpoTRft5EqsmpLzNJvN9oHgpv77UcX4ew0nK5xiGMpji6Cul6eJC4pkCtZ6fMIIUajYRNkCyCpbztQAWb5Ut/egQ4zdCRiyNXMTTTuqle5XfBJ0xXCFkCTieME1Rl8mWad5En9oEa2ruaAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=Mqvi6VnS; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Mqvi6VnS" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20260109084924euoutp01eb61de00c3a2fe34189812e0808b6f37~JA9o3uUky2122521225euoutp01- for ; Fri, 9 Jan 2026 08:49:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20260109084924euoutp01eb61de00c3a2fe34189812e0808b6f37~JA9o3uUky2122521225euoutp01- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1767948564; bh=c/SwZOTAWGRjC/jOsnr+JcML73MY8MIOtSVDjsJsr/A=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=Mqvi6VnSI+CqaxNhSov0BFfWfW+NPRCSr1KW/RSAFYA+1Gf5MHNWUTkWA5+dY08NO m5CIBzPkCWZtBAdfRdTe2inPqn7yJPtVIdr2GNdToUf9Iuvq3SQZ3bcyMPo2SH9YbV yxqsWKXsar1KHHVBKWzgrPmCi0k1q2Ailkga0CYM= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20260109084923eucas1p1f8f659a0971bb13f38e8358bdec8a393~JA9oVbnXV2402824028eucas1p1U; Fri, 9 Jan 2026 08:49:23 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260109084922eusmtip2df18ddfed878c3c954ee6deb52bb639c~JA9m9Osqh0432004320eusmtip2H; Fri, 9 Jan 2026 08:49:22 +0000 (GMT) Message-ID: <11d08a53-44b2-48c0-8fc4-8b633e72b1ba@samsung.com> Date: Fri, 9 Jan 2026 09:49:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH v2 10/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: use a temporary variable for the next bridge To: Luca Ceresoli , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Philippe Cornu , benjamin.gaignard@linaro.org, Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Adrien Grassein , Liu Ying , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki Cc: Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Content-Language: en-US From: Marek Szyprowski In-Reply-To: <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-10-8bad3ef90b9f@bootlin.com> Content-Transfer-Encoding: 7bit X-CMS-MailID: 20260109084923eucas1p1f8f659a0971bb13f38e8358bdec8a393 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20260109074009eucas1p21117b6a8a2eba825ebad7b77bd19efd4 X-EPHeader: CA X-CMS-RootMailID: 20260109074009eucas1p21117b6a8a2eba825ebad7b77bd19efd4 References: <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-0-8bad3ef90b9f@bootlin.com> <20260109-drm-bridge-alloc-getput-drm_of_find_bridge-2-v2-10-8bad3ef90b9f@bootlin.com> On 09.01.2026 08:31, 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 as late as possible, i.e. just before > calling pdata->host_ops->attach() which uses it (only in the exynos > driver). > > Not strictly needed, but for symmetry move the clearing of dsi->out_bridge > in samsung_dsim_host_detach() to after pdata->host_ops->detach(). > > Signed-off-by: Luca Ceresoli Tested-by: Marek Szyprowski > --- > > Changes in v2: > - fix "pointer set too late" bug (NULL pointer deref in the exynos case) > - *not* add Acked-by: Maxime as the patch has changed > --- > drivers/gpu/drm/bridge/samsung-dsim.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c > index eabc4c32f6ab..8dd058124e93 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; > } > @@ -1958,10 +1959,13 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, > return ret; > } > > + // The next bridge can be used by host_ops->attach > + dsi->out_bridge = next_bridge; > + > if (pdata->host_ops && pdata->host_ops->attach) { > ret = pdata->host_ops->attach(dsi, device); > if (ret) > - return ret; > + goto err_release_next_bridge; > } > > dsi->lanes = device->lanes; > @@ -1969,6 +1973,10 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, > dsi->mode_flags = device->mode_flags; > > return 0; > + > +err_release_next_bridge: > + dsi->out_bridge = NULL; > + return ret; > } > > static void samsung_dsim_unregister_te_irq(struct samsung_dsim *dsi) > @@ -1985,11 +1993,11 @@ static int samsung_dsim_host_detach(struct mipi_dsi_host *host, > struct samsung_dsim *dsi = host_to_dsi(host); > const struct samsung_dsim_plat_data *pdata = dsi->plat_data; > > - dsi->out_bridge = NULL; > - > if (pdata->host_ops && pdata->host_ops->detach) > pdata->host_ops->detach(dsi, device); > > + dsi->out_bridge = NULL; > + > samsung_dsim_unregister_te_irq(dsi); > > drm_bridge_remove(&dsi->bridge); > Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland