Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp327252pxu; Thu, 3 Dec 2020 00:56:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxV3dqIwQeOzZW99YjDOpC5Pg24Xj3W5lSEfxjUxztgECI68doYubGtLBgb0/87mgZ2gobD X-Received: by 2002:a17:906:2a4b:: with SMTP id k11mr1508185eje.467.1606985802690; Thu, 03 Dec 2020 00:56:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606985802; cv=none; d=google.com; s=arc-20160816; b=EcOZq2GhfOvLE9pGFZUBbQONh4t5ALw6+TbDHhulqrYfnMEhXhI//ryQlrxbVLKR9I Ll8bVAgHEc5hwIAIboRBkipjOfPDZ4K7Ha8u4EUO3p8FLbnNWxksLlXkuH/htsS/DpbT 3yW5EipCIhqCQ3Kkwn2TpPaGUIRiuP+QSuUwCDgPt8X7yjytOoKDdHPwMMJZchHXrSl9 cIKJRsLDPFDchP/VnK/sGju50H0veaPgtWyoNLW2psr+Ux9yUh6KKnnTt4QGiQxZl1mW Ajku1PdYnPlMegLBRoLWG7Ox0dSrzTIRE1h+Z31UP1hgM/MqPgb2q+NmNprKoq0hnkGn Dh2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :date:cc:to:from:subject:message-id; bh=ammQv7xeIseWM0PqX4Ym9S4wYeuRmfWLsFUoKUwneuY=; b=D+DRcR8u/c0c5AG4iJPCUy6y5IKrCXr9K36Y3TVvTXBUhBOe//ix6CI3/bRuHte2lD VmSZWLHYHNU2MKPnPXtqJlWT1KbhSJlqbXD1rmBZJWQ5Ky8Pq3RjcJ1r/RXSMbLB1+/V BqRiNolCcUqjwO6JRRsGgNBma3pGj7Zu/Kcii24cLqkGRWjyTtHA9iIyAd2DER4E44CR NvxqA/7VYcPQNmIl9kW63Bgy68qC71uHLeWrHdP9WkeC+JaIVuwaoX4uPXHnozWDXyPF CXMM+IfoIc9iwT6HNVq8iyAAGs1/8Ki7E6+Q0KvkhduRm9p4WcqXAa3jwsYMqyDmC/R9 T6Ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si505634edk.251.2020.12.03.00.56.19; Thu, 03 Dec 2020 00:56:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730064AbgLCIx5 (ORCPT + 99 others); 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-kernel@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--