From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8823C83013 for ; Thu, 3 Dec 2020 08:54:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9741C22203 for ; Thu, 3 Dec 2020 08:54:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730057AbgLCIx5 (ORCPT ); Thu, 3 Dec 2020 03:53:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:58580 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730016AbgLCIx4 (ORCPT ); Thu, 3 Dec 2020 03:53:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6E0E5AC55; Thu, 3 Dec 2020 08:53:14 +0000 (UTC) Message-ID: <401be3062e06f4896662da179a751a1a08b8a75a.camel@suse.de> Subject: Re: [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers From: Nicolas Saenz Julienne To: Bartosz Golaszewski Cc: Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , LKML , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, linux-pwm@vger.kernel.org, arm-soc , linux-devicetree , wahrenst@gmx.net, Linux Input , Dmitry Torokhov , Greg KH , devel@driverdev.osuosl.org, Philipp Zabel , linux-gpio , Linus Walleij , linux-clk , Stephen Boyd , linux-rpi-kernel@lists.infradead.org, Andy Shevchenko Date: Thu, 03 Dec 2020 09:53:12 +0100 In-Reply-To: References: <20201123183833.18750-1-nsaenzjulienne@suse.de> <20201123183833.18750-2-nsaenzjulienne@suse.de> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-SBC+IJay38JRk592gNwQ" User-Agent: Evolution 3.38.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org --=-SBC+IJay38JRk592gNwQ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2020-12-03 at 09:05 +0100, Bartosz Golaszewski wrote: > On Mon, Nov 23, 2020 at 7:38 PM Nicolas Saenz Julienne > wrote: > >=20 > > When unbinding the firmware device we need to make sure it has no > > consumers left. Otherwise we'd leave them with a firmware handle > > pointing at freed memory. > >=20 > > Keep a reference count of all consumers and introduce rpi_firmware_put(= ) > > which will permit automatically decrease the reference count upon > > unbinding consumer drivers. > >=20 > > Suggested-by: Uwe Kleine-K=C3=B6nig > > Signed-off-by: Nicolas Saenz Julienne > > --- > >=20 > > Changes since v3: > > - Use kref instead of waiting on refcount > >=20 > > =C2=A0drivers/firmware/raspberrypi.c | 37 +++++++++++++++++= ++--- > > =C2=A0include/soc/bcm2835/raspberrypi-firmware.h | 2 ++ > > =C2=A02 files changed, 35 insertions(+), 4 deletions(-) > >=20 > > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberr= ypi.c > > index 30259dc9b805..ed793aef7851 100644 > > --- a/drivers/firmware/raspberrypi.c > > +++ b/drivers/firmware/raspberrypi.c > > @@ -7,6 +7,7 @@ > > =C2=A0=C2=A0*/ > >=20 > > =C2=A0#include > > +#include > > =C2=A0#include > > =C2=A0#include > > =C2=A0#include > > @@ -27,6 +28,8 @@ struct rpi_firmware { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct mbox_chan *chan;= /* The property channel. */ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct completion c; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0u32 enabled; > > + > > + struct kref consumers; > > =C2=A0}; > >=20 > > =C2=A0static DEFINE_MUTEX(transaction_lock); > > @@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device= *dev) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0-1, NU= LL, 0); > > =C2=A0} > >=20 > > +static void rpi_firmware_delete(struct kref *kref) > > +{ > > + struct rpi_firmware *fw =3D container_of(kref, struct rpi_firmw= are, > > + consumers); > > + > > + mbox_free_channel(fw->chan); > > + kfree(fw); > > +} > > + > > +void rpi_firmware_put(struct rpi_firmware *fw) > > +{ > > + kref_put(&fw->consumers, rpi_firmware_delete); > > +} > > +EXPORT_SYMBOL_GPL(rpi_firmware_put); > > + > > =C2=A0static int rpi_firmware_probe(struct platform_device *pdev) > > =C2=A0{ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct device *dev =3D = &pdev->dev; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct rpi_firmware *fw= ; > >=20 > > - fw =3D devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL); >=20 > One nit from my side: maybe add a comment here saying that you really > want to use non-managed kzalloc() because you're going to get people > blindly converting it to devm_kzalloc() very soon. Good point, I'll change it. Regards, Nicolas --=-SBC+IJay38JRk592gNwQ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEErOkkGDHCg2EbPcGjlfZmHno8x/4FAl/Ip3gACgkQlfZmHno8 x/5Ncwf8C0HFE7YBc4W1hWu3koQkBNupWVGDMLkAR36Dfmk6pph04kKcLSt6ZIu1 2SMHgfQG4VikmJnqGQp66Y93QWodjPeglOr+09VL5rY7rehOGcdBICaNPJcS1vrl LnF+n0Lqyfirpq4rVd7qX5taBOz890GfthlZMmFsNcbFcSEuuUVogJC7iCDe+0cy nqEYLXfaCEVDE0jR4Zvmyvs20dEZpXHR0gfoc29hMBtRLDL2l1CClG7Vm9im7Ob1 2Jm9YqHMduon8YCqLZF+jxnZesbb9ktTry5StYQ7lSZyfDxb32nOjAQqGeZfsYyF y1nknR5dNeL/6dbIqCn33h4p6HSTbA== =idux -----END PGP SIGNATURE----- --=-SBC+IJay38JRk592gNwQ--