From: Maxime Ripard <mripard@kernel.org>
To: Albert Esteve <aesteve@redhat.com>
Cc: "Neil Armstrong" <neil.armstrong@linaro.org>,
"Jessica Zhang" <jesszhan0024@gmail.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Robert Foss" <rfoss@kernel.org>,
"Laurent Pinchart" <Laurent.pinchart@ideasonboard.com>,
"Jonas Karlman" <jonas@kwiboo.se>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
"Inki Dae" <inki.dae@samsung.com>,
"Jagan Teki" <jagan@amarulasolutions.com>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Laurentiu Palcu" <laurentiu.palcu@oss.nxp.com>,
"Lucas Stach" <l.stach@pengutronix.de>,
"Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Paul Cercueil" <paul@crapouillou.net>,
"Linus Walleij" <linusw@kernel.org>,
"Marek Vasut" <marex@denx.de>, "Stefan Agner" <stefan@agner.ch>,
"Tomi Valkeinen" <tomi.valkeinen@ideasonboard.com>,
"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Magnus Damm" <magnus.damm@gmail.com>,
"Biju Das" <biju.das.jz@bp.renesas.com>,
"Sandy Huang" <hjc@rock-chips.com>,
"Heiko Stübner" <heiko@sntech.de>,
"Andy Yan" <andy.yan@rock-chips.com>,
"Yannick Fertre" <yannick.fertre@foss.st.com>,
"Raphael Gallais-Pou" <raphael.gallais-pou@foss.st.com>,
"Philippe Cornu" <philippe.cornu@foss.st.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Chen-Yu Tsai" <wens@kernel.org>,
"Samuel Holland" <samuel@sholland.org>,
"Jyri Sarha" <jyri.sarha@iki.fi>,
"Jingoo Han" <jingoohan1@gmail.com>,
"Seung-Woo Kim" <sw0312.kim@samsung.com>,
"Kyungmin Park" <kyungmin.park@samsung.com>,
"Krzysztof Kozlowski" <krzk@kernel.org>,
"Peter Griffin" <peter.griffin@linaro.org>,
"Alim Akhtar" <alim.akhtar@samsung.com>,
"Alison Wang" <alison.wang@nxp.com>,
"Paul Kocialkowski" <paulk@sys-base.io>,
"Alain Volmat" <alain.volmat@foss.st.com>,
"Raphael Gallais-Pou" <rgallaispou@gmail.com>,
"Thierry Reding" <thierry.reding@kernel.org>,
"Mikko Perttunen" <mperttunen@nvidia.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-mips@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-rockchip@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-sunxi@lists.linux.dev, linux-samsung-soc@vger.kernel.org,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH 3/5] drm/panel: make *find_panel*() return a counted reference
Date: Fri, 26 Jun 2026 14:50:50 +0200 [thread overview]
Message-ID: <20260626-successful-badger-from-neptune-ae2bc6@houat> (raw)
In-Reply-To: <20260626-drm_refcount_wiring-v1-3-cca1a7b3bdef@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3911 bytes --]
On Fri, Jun 26, 2026 at 02:03:25PM +0200, Albert Esteve wrote:
> Callers of of_drm_find_panel() receive a pointer with no reference
> held, creating a window where the panel device can be unregistered
> and freed between the lookup and first use (e.g., drm_panel_prepare()).
>
> find_panel_by_fwnode() is the fwnode counterpart of of_drm_find_panel().
> drm_panel_add_follower() worked around the missing panel kref by calling
> get_device() on the panel's underlying struct device. However, get_device()
> only prevents the device kobject from being freed. It does not prevent the
> panel's kzalloc()'d container memory from being released when the kref
> reaches zero.
>
> Fix both lookup functions by acquiring a reference with drm_panel_get()
> before returning, under panel_lock. Callers are now responsible for calling
> drm_panel_put() when they no longer need the pointer.
>
> Signed-off-by: Albert Esteve <aesteve@redhat.com>
> ---
> drivers/gpu/drm/drm_panel.c | 22 +++++++++++++++++-----
> 1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index 545fe93dc28fe..a00ae98ed0956 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -458,14 +458,17 @@ EXPORT_SYMBOL(__devm_drm_panel_alloc);
>
> #ifdef CONFIG_OF
> /**
> - * of_drm_find_panel - look up a panel using a device tree node
> + * of_drm_find_panel - look up and reference a panel by device tree node
> * @np: device tree node of the panel
> *
> * Searches the set of registered panels for one that matches the given device
> - * tree node. If a matching panel is found, return a pointer to it.
> + * tree node. If a matching panel is found, the panel's reference count is
> + * incremented before returning a pointer to it. The caller must call
> + * drm_panel_put() when it no longer needs the panel pointer.
> *
> - * Return: A pointer to the panel registered for the specified device tree
> - * node or an ERR_PTR() if no panel matching the device tree node can be found.
> + * Return: A reference-counted pointer to the panel registered for the specified
> + * device tree node or an ERR_PTR() if no panel matching the device tree node
> + * can be found.
> *
> * Possible error codes returned by this function:
> *
> @@ -484,6 +487,7 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np)
>
> list_for_each_entry(panel, &panel_list, list) {
> if (panel->dev->of_node == np) {
> + drm_panel_get(panel);
> mutex_unlock(&panel_lock);
> return panel;
> }
> @@ -538,7 +542,13 @@ int of_drm_get_panel_orientation(const struct device_node *np,
> EXPORT_SYMBOL(of_drm_get_panel_orientation);
> #endif
>
> -/* Find panel by fwnode. This should be identical to of_drm_find_panel(). */
> +/*
> + * Find panel by fwnode, returning a counted reference.
> + *
> + * Behaves identically to of_drm_find_panel(). On success the returned
> + * pointer has been passed through drm_panel_get(); the caller must call
> + * drm_panel_put() when done with it.
> + */
> static struct drm_panel *find_panel_by_fwnode(const struct fwnode_handle *fwnode)
> {
> struct drm_panel *panel;
> @@ -550,6 +560,7 @@ static struct drm_panel *find_panel_by_fwnode(const struct fwnode_handle *fwnode
>
> list_for_each_entry(panel, &panel_list, list) {
> if (dev_fwnode(panel->dev) == fwnode) {
> + drm_panel_get(panel);
> mutex_unlock(&panel_lock);
> return panel;
> }
This part should probably be in a separate patch
> @@ -686,6 +697,7 @@ void drm_panel_remove_follower(struct drm_panel_follower *follower)
> mutex_unlock(&panel->follower_lock);
>
> put_device(panel->dev);
> + drm_panel_put(panel);
> }
> EXPORT_SYMBOL(drm_panel_remove_follower);
together with this one?
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
next prev parent reply other threads:[~2026-06-26 12:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 12:03 [PATCH 0/5] drm/panel: refcounting panel lookups and references Albert Esteve
2026-06-26 12:03 ` [PATCH 1/5] drm/panel: have drm_panel_add/remove manage a list reference Albert Esteve
2026-06-26 12:47 ` Maxime Ripard
2026-06-26 12:03 ` [PATCH 2/5] drm/bridge/panel: hold a reference to the wrapped panel Albert Esteve
2026-06-26 12:48 ` Maxime Ripard
2026-06-26 12:03 ` [PATCH 3/5] drm/panel: make *find_panel*() return a counted reference Albert Esteve
2026-06-26 12:50 ` Maxime Ripard [this message]
2026-06-26 15:11 ` Albert Esteve
2026-06-26 12:03 ` [PATCH 4/5] drm/bridge: release panel reference on all lookup exit paths Albert Esteve
2026-06-26 12:53 ` Maxime Ripard
2026-06-26 13:11 ` Albert Esteve
2026-06-26 12:03 ` [PATCH 5/5] drm: release panel reference after panel bridge creation Albert Esteve
2026-06-26 12:59 ` Maxime Ripard
2026-06-26 15:05 ` Albert Esteve
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=20260626-successful-badger-from-neptune-ae2bc6@houat \
--to=mripard@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=aesteve@redhat.com \
--cc=airlied@gmail.com \
--cc=alain.volmat@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=alim.akhtar@samsung.com \
--cc=alison.wang@nxp.com \
--cc=andrzej.hajda@intel.com \
--cc=andy.yan@rock-chips.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=geert+renesas@glider.be \
--cc=heiko@sntech.de \
--cc=hjc@rock-chips.com \
--cc=imx@lists.linux.dev \
--cc=inki.dae@samsung.com \
--cc=jagan@amarulasolutions.com \
--cc=jernej.skrabec@gmail.com \
--cc=jesszhan0024@gmail.com \
--cc=jingoohan1@gmail.com \
--cc=jonas@kwiboo.se \
--cc=jonathanh@nvidia.com \
--cc=jyri.sarha@iki.fi \
--cc=kernel@pengutronix.de \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=krzk@kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=l.stach@pengutronix.de \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=laurentiu.palcu@oss.nxp.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=m.szyprowski@samsung.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=magnus.damm@gmail.com \
--cc=marex@denx.de \
--cc=mcoquelin.stm32@gmail.com \
--cc=mperttunen@nvidia.com \
--cc=neil.armstrong@linaro.org \
--cc=paul@crapouillou.net \
--cc=paulk@sys-base.io \
--cc=peter.griffin@linaro.org \
--cc=philippe.cornu@foss.st.com \
--cc=raphael.gallais-pou@foss.st.com \
--cc=rfoss@kernel.org \
--cc=rgallaispou@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=samuel@sholland.org \
--cc=simona@ffwll.ch \
--cc=stefan@agner.ch \
--cc=sw0312.kim@samsung.com \
--cc=thierry.reding@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=tzimmermann@suse.de \
--cc=wens@kernel.org \
--cc=yannick.fertre@foss.st.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®