From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4B9B03F5BC2; Fri, 26 Jun 2026 12:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782478254; cv=none; b=ePRDRvHeSnnGVGDddQUkLDqcl3qftQ/zTPG617dTLnzvSS23nrzgIBkP3K9y/xeA0XtlNQ9onjl+k6idWSJmQLScxS8WND008qWa16tdM0XWUtDfwMTM+3OhNEwB76/1IzSOp4WENajADCWv2Qe9wh0g8hS0ywDGoSvPVavXRrk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782478254; c=relaxed/simple; bh=mpn1xOBmTLtXTbXFCpce/LOn/ZxcejCkHLaZi0LRvLg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T31AlC2ByiuiqMZGrAzx9+iwNmbpzIy+X87Jad/dks3ZRdJ9ZcIB9Zceobd8bufL0vu7pJiK40EWmpCaFbTaX5xu/bDTzBWyUi+/4avxU+hk7Kf1Y7+xLufGrDrtsnB/ofJuzywMQ9laxUmL9neBYqO71rbON6E4LLxQFNU/DYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kFciZu6i; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kFciZu6i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 558761F000E9; Fri, 26 Jun 2026 12:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782478253; bh=6/EMO4Xkqp5EWfNibLrVgkVHrXeObxmVUQOZpRPdNsM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=kFciZu6i07zWeKKDY/50OS1OI70Cj4lvWkQFfSD5XtViJd2eByvBcu8aj3KWP+Ukv X+eTj5TV3Gir4AshCO3pgdC3PnxPVcZD4iuwQ/SFGACct9WvG+7U4Tv6GD6UtvG0Nu bWKQPx38vfASM1850IT1mVI5Uh4QH2/cGIC6CEogxc2zpihNmpqdMHrCiDYFjYojxW n3NKX6j//1QPW4WtjNvvl+Bpzewi0M35lQFCC4LKi9sAoFmAfIwVWzHYgThOmzjymG 8IHHNECFegf/L0PxcMHB2ONFWTonLZDRneFleG5rAvwrYXU836B4fEp0NwM/MWpETy Ci7qg7FbfYPGA== Date: Fri, 26 Jun 2026 14:50:50 +0200 From: Maxime Ripard To: Albert Esteve Cc: Neil Armstrong , Jessica Zhang , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Inki Dae , Jagan Teki , Marek Szyprowski , Laurentiu Palcu , Lucas Stach , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Paul Cercueil , Linus Walleij , Marek Vasut , Stefan Agner , Tomi Valkeinen , Laurent Pinchart , Kieran Bingham , Geert Uytterhoeven , Magnus Damm , Biju Das , Sandy Huang , Heiko =?utf-8?Q?St=C3=BCbner?= , Andy Yan , Yannick Fertre , Raphael Gallais-Pou , Philippe Cornu , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Samuel Holland , Jyri Sarha , Jingoo Han , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Peter Griffin , Alim Akhtar , Alison Wang , Paul Kocialkowski , Alain Volmat , Raphael Gallais-Pou , Thierry Reding , Mikko Perttunen , Jonathan Hunter , 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 Message-ID: <20260626-successful-badger-from-neptune-ae2bc6@houat> References: <20260626-drm_refcount_wiring-v1-0-cca1a7b3bdef@redhat.com> <20260626-drm_refcount_wiring-v1-3-cca1a7b3bdef@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha384; protocol="application/pgp-signature"; boundary="7zohsnv3e6hz33ls" Content-Disposition: inline In-Reply-To: <20260626-drm_refcount_wiring-v1-3-cca1a7b3bdef@redhat.com> --7zohsnv3e6hz33ls Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH 3/5] drm/panel: make *find_panel*() return a counted reference MIME-Version: 1.0 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()). >=20 > 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. >=20 > Fix both lookup functions by acquiring a reference with drm_panel_get() > before returning, under panel_lock. Callers are now responsible for calli= ng > drm_panel_put() when they no longer need the pointer. >=20 > Signed-off-by: Albert Esteve > --- > drivers/gpu/drm/drm_panel.c | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) >=20 > 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); > =20 > #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 tr= ee > - * 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 s= pecified > + * 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 devi= ce_node *np) > =20 > list_for_each_entry(panel, &panel_list, list) { > if (panel->dev->of_node =3D=3D 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 > =20 > -/* Find panel by fwnode. This should be identical to of_drm_find_panel()= =2E */ > +/* > + * 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 s= truct fwnode_handle *fwnode > =20 > list_for_each_entry(panel, &panel_list, list) { > if (dev_fwnode(panel->dev) =3D=3D 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_follo= wer *follower) > mutex_unlock(&panel->follower_lock); > =20 > put_device(panel->dev); > + drm_panel_put(panel); > } > EXPORT_SYMBOL(drm_panel_remove_follower); together with this one? Maxime --7zohsnv3e6hz33ls Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJUEABMJAB0WIQTkHFbLp4ejekA/qfgnX84Zoj2+dgUCaj51qgAKCRAnX84Zoj2+ diwIAX4n8GVfdswI/CYfLEgOWgs6vyFmb4OyfcLhnjRxNbOAswd2I4Y6MISm2y2O xbmkorsBgIsdJUP81eahqp4/Cdcc0U1VPZVV2ocSL3asD7KeHDuqM1tJ2aAS3RWB swFnQal7+A== =gMuG -----END PGP SIGNATURE----- --7zohsnv3e6hz33ls--