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=ham 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 2C774C63777 for ; Thu, 3 Dec 2020 08:53:25 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58517217A0 for ; Thu, 3 Dec 2020 08:53:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58517217A0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=driverdev-devel-bounces@linuxdriverproject.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id BC14720366; Thu, 3 Dec 2020 08:53:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wXQyAlNntT07; Thu, 3 Dec 2020 08:53:19 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 0C17F20381; Thu, 3 Dec 2020 08:53:19 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id EB2AE1BF831 for ; Thu, 3 Dec 2020 08:53:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id E23BE86977 for ; Thu, 3 Dec 2020 08:53:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dAYfm+QQyN1w for ; Thu, 3 Dec 2020 08:53:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by whitealder.osuosl.org (Postfix) with ESMTPS id CAEA1869EF for ; Thu, 3 Dec 2020 08:53:16 +0000 (UTC) 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 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> User-Agent: Evolution 3.38.2 MIME-Version: 1.0 X-BeenThere: driverdev-devel@linuxdriverproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, linux-pwm@vger.kernel.org, Andy Shevchenko , Florian Fainelli , Scott Branden , linux-devicetree , Stephen Boyd , Ray Jui , Linus Walleij , Linux Input , LKML , linux-gpio , Greg KH , bcm-kernel-feedback-list@broadcom.com, wahrenst@gmx.net, Philipp Zabel , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Dmitry Torokhov , linux-clk , arm-soc , linux-rpi-kernel@lists.infradead.org Content-Type: multipart/mixed; boundary="===============6686931480165653806==" Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" --===============6686931480165653806== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-SBC+IJay38JRk592gNwQ" --=-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-- --===============6686931480165653806== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel --===============6686931480165653806==--