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 82B92352921 for ; Fri, 9 Jan 2026 08:50:13 +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=1767948615; cv=none; b=jrIWZMRKMuLQkWipsZG6JeiguCWc0o9/qlz59+CoaKbrYQHkTiIhpdGE826qXsVQTL4YFuKfd+NNtUKtBDlsX4ut5X/4TPCHlvteMO8dWHmXBZIJMP7nWJInz7wRLFYNKm7Xmiy/NgFFzgJzbDCpHu2Dq6i/Gfnfl3zN8rHY0k0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767948615; c=relaxed/simple; bh=DwDr9lhQqXNlumAFeY6ARF/9gu3PD3RKSa6UaHRxNJ0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:In-Reply-To: Content-Type:References; b=nI8+hiq1XAu3MTtcRLflQEmVqJ4nXF1C96LznJewKQNcRq2BREBcqizny/Ea6TBfOnTc3s5QkEd0vSELHky4hUL/+9P7LAnle2oiM6Ob82WRKouN/lvYZPHvNWmkwbn0PX9i8MRCXqrl3jjhi/B5Qr41vo/x/NuJlH2+qMDoRCw= 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=jl8V1hyT; 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="jl8V1hyT" Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20260109085011euoutp01407204e9e83d6d62e873dd0c98a33e2f~JA_U1lYZa2091320913euoutp01V for ; Fri, 9 Jan 2026 08:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20260109085011euoutp01407204e9e83d6d62e873dd0c98a33e2f~JA_U1lYZa2091320913euoutp01V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1767948611; bh=9nrTgJ1fPRBZ5eKN3EFtjQRxmnL67+4GleGznV0Og94=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=jl8V1hyTmZgKkfA3qNbL0xn6zKIaV16Qve4X078BJ/FWPkD8UM3JPkuFx9cWPe6RK VN0SNlmoAcPoLck1PQaLdDyIfkXH7CIXc72uzylh0hgq1zq1MbdmAxoiNgypK4ykKs qB36XKFfyUeij0edb1kcpKIQB/4i9uE5pFebbDk4= Received: from eusmtip2.samsung.com (unknown [203.254.199.222]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20260109085011eucas1p2825c7d44757c204152e65965f5864715~JA_UXFXip0983509835eucas1p2V; Fri, 9 Jan 2026 08:50:11 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260109085009eusmtip20e7d4ebf0b633fecfd09193091d0f534~JA_S04kDD0959909599eusmtip2F; Fri, 9 Jan 2026 08:50:09 +0000 (GMT) Message-ID: Date: Fri, 9 Jan 2026 09:50:09 +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 12/12] drm/bridge: samsung-dsim: samsung_dsim_host_attach: convert to of_drm_find_and_get_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-12-8bad3ef90b9f@bootlin.com> Content-Transfer-Encoding: 7bit X-CMS-MailID: 20260109085011eucas1p2825c7d44757c204152e65965f5864715 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20260109073236eucas1p27fab1926761fc4058cc2a127c117e219 X-EPHeader: CA X-CMS-RootMailID: 20260109073236eucas1p27fab1926761fc4058cc2a127c117e219 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-12-8bad3ef90b9f@bootlin.com> On 09.01.2026 08:31, Luca Ceresoli wrote: > of_drm_find_bridge() is deprecated. Move to its replacement > of_drm_find_and_get_bridge() which gets a bridge reference, and ensure it > is put when done. Also switch to the drm_bridge::next_bridge pointer. > > This needs to handle both cases: when of_drm_find_panel() succeeds and when > it fails. > > In the 'else' case (i.e. when of_drm_find_panel() fails), just switch to > of_drm_find_and_get_bridge() to ensure the bridge is not freed while in use > in the function tail, when it is stored in dsi->bridge.next_bridge. > > In the 'then' case (i.e. when of_drm_find_panel() succeeds), > devm_drm_panel_bridge_add() already increments the refcount using devres > which ties the bridge allocation lifetime to the device lifetime, so we > would not need to do anything. However to have the same behaviour in both > branches take an additional reference here, so that the bridge needs to be > put whichever branch is taken without more complicated logic. Ensure to > clear the bridge pointer however, to avoid calling drm_bridge_put() on an > ERR_PTR. > > Signed-off-by: Luca Ceresoli Tested-by: Marek Szyprowski > --- > > Changes in v2: > - updated after "pointer set too late" fix inprevious patch > - *not* add Acked-by: Maxime as the patch has changed > --- > drivers/gpu/drm/bridge/samsung-dsim.c | 20 +++++++++++++------- > include/drm/bridge/samsung-dsim.h | 1 - > 2 files changed, 13 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge/samsung-dsim.c > index afaa63c4d3f7..1d85e706c74b 100644 > --- a/drivers/gpu/drm/bridge/samsung-dsim.c > +++ b/drivers/gpu/drm/bridge/samsung-dsim.c > @@ -1828,7 +1828,7 @@ static int samsung_dsim_attach(struct drm_bridge *bridge, > { > struct samsung_dsim *dsi = bridge_to_dsi(bridge); > > - return drm_bridge_attach(encoder, dsi->out_bridge, bridge, > + return drm_bridge_attach(encoder, dsi->bridge.next_bridge, bridge, > flags); > } > > @@ -1886,7 +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 drm_bridge *next_bridge __free(drm_bridge_put) = NULL; > struct device *dev = dsi->dev; > struct device_node *np = dev->of_node; > struct device_node *remote; > @@ -1926,10 +1926,14 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, > panel = of_drm_find_panel(remote); > if (!IS_ERR(panel)) { > next_bridge = devm_drm_panel_bridge_add(dev, panel); > - if (IS_ERR(next_bridge)) > + if (IS_ERR(next_bridge)) { > ret = PTR_ERR(next_bridge); > + next_bridge = NULL; // Inhibit the cleanup action on an ERR_PTR > + } else { > + drm_bridge_get(next_bridge); > + } > } else { > - next_bridge = of_drm_find_bridge(remote); > + next_bridge = of_drm_find_and_get_bridge(remote); > if (!next_bridge) > ret = -EINVAL; > } > @@ -1961,7 +1965,7 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, > } > > // The next bridge can be used by host_ops->attach > - dsi->out_bridge = next_bridge; > + dsi->bridge.next_bridge = drm_bridge_get(next_bridge); > > if (pdata->host_ops && pdata->host_ops->attach) { > ret = pdata->host_ops->attach(dsi, device); > @@ -1976,7 +1980,8 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host, > return 0; > > err_release_next_bridge: > - dsi->out_bridge = NULL; > + drm_bridge_put(dsi->bridge.next_bridge); > + dsi->bridge.next_bridge = NULL; > return ret; > } > > @@ -1997,7 +2002,8 @@ static int samsung_dsim_host_detach(struct mipi_dsi_host *host, > if (pdata->host_ops && pdata->host_ops->detach) > pdata->host_ops->detach(dsi, device); > > - dsi->out_bridge = NULL; > + drm_bridge_put(dsi->bridge.next_bridge); > + dsi->bridge.next_bridge = NULL; > > samsung_dsim_unregister_te_irq(dsi); > > diff --git a/include/drm/bridge/samsung-dsim.h b/include/drm/bridge/samsung-dsim.h > index 31d7ed589233..03005e474704 100644 > --- a/include/drm/bridge/samsung-dsim.h > +++ b/include/drm/bridge/samsung-dsim.h > @@ -100,7 +100,6 @@ struct samsung_dsim_plat_data { > struct samsung_dsim { > struct mipi_dsi_host dsi_host; > struct drm_bridge bridge; > - struct drm_bridge *out_bridge; > struct device *dev; > struct drm_display_mode mode; > > Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland