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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 27862C2D0E4 for ; Mon, 23 Nov 2020 17:22:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 8FD1220728 for ; Mon, 23 Nov 2020 17:22:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tOyaqapn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FD1220728 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Date:To:From:Subject:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YT9z6P32q8R1EMkE6Ff8BoSnu/vBINhBlxNWRQUJgiY=; b=tOyaqapncUP14wig+824y7In1 Mxcm7tuGvkom3BnemBCL80c7LrAAXXbLqw+AEWpnX93BWsR+w4B341WAv+Uwt+izwAwqjx2DkGPM2 ZD7C7LsSr7e2GKIcCTPMtmTGJE04l9hNrYNaQbGrPpiXI9NpE9O1UjPQwQRJiQppMyKzVkippuWmI S4Pbr52fTdlt1VAYwPD+JRdyJhlyy6c80lOf/h/tZQymMIgcbveQDtEl73Y1hDwfM9MQ2J9bDfsKf YR7whGLW9xAs01DXwRDe9yBNnRszgm37iQDCczBCPzkrjEwkviDqiVXU9V640LMg1v75K6436Ndpw ZpMlXKvTg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khFX4-0001es-TU; Mon, 23 Nov 2020 17:21:42 +0000 Received: from mx2.suse.de ([195.135.220.15]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khFX1-0001aH-OM; Mon, 23 Nov 2020 17:21:40 +0000 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 52398AC82; Mon, 23 Nov 2020 17:19:37 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4 01/11] firmware: raspberrypi: Keep count of all consumers From: Nicolas Saenz Julienne To: Dmitry Torokhov , Andy Shevchenko Date: Mon, 23 Nov 2020 18:19:35 +0100 In-Reply-To: <20201113072615.GE356503@dtor-ws> References: <20201112163630.17177-1-nsaenzjulienne@suse.de> <20201112163630.17177-2-nsaenzjulienne@suse.de> <20201113072615.GE356503@dtor-ws> User-Agent: Evolution 3.38.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_122140_016407_3FF6952B X-CRM114-Status: GOOD ( 26.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:STAGING SUBSYSTEM" , linux-pwm@vger.kernel.org, Florian Fainelli , Scott Branden , devicetree , Stephen Boyd , Ray Jui , Linus Walleij , linux-input , Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Greg Kroah-Hartman , bcm-kernel-feedback-list , Stefan Wahren , Philipp Zabel , Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Bartosz Golaszewski , linux-clk , linux-arm Mailing List , linux-rpi-kernel Content-Type: multipart/mixed; boundary="===============5459558824259436106==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============5459558824259436106== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-4mT4pfaztxo3yJL0guCg" --=-4mT4pfaztxo3yJL0guCg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2020-11-12 at 23:26 -0800, Dmitry Torokhov wrote: > On Thu, Nov 12, 2020 at 07:52:14PM +0200, Andy Shevchenko wrote: > > On Thu, Nov 12, 2020 at 6:40 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_pu= t() > > > which will permit automatically decrease the reference count upon > > > unbinding consumer drivers. > >=20 > > ... > >=20 > > > =C2=A0/** > > > - * rpi_firmware_get - Get pointer to rpi_firmware structure. > > > =C2=A0=C2=A0* @firmware_node: Pointer to the firmware Device Tree = node. > > > =C2=A0=C2=A0* > > > + * The reference to rpi_firmware has to be released with rpi_firmwar= e_put(). > > > + * > > > =C2=A0=C2=A0* Returns NULL is the firmware device is not ready. > > > =C2=A0=C2=A0*/ > > > =C2=A0struct rpi_firmware *rpi_firmware_get(struct device_node *firmw= are_node) > > > =C2=A0{ > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct platform_devic= e *pdev =3D of_find_device_by_node(firmware_node); > > > + struct rpi_firmware *fw; > > >=20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (!pdev) > > > =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=A0return NULL; > > >=20 > > > - return platform_get_drvdata(pdev); > > > + fw =3D platform_get_drvdata(pdev); > > > + if (!fw) > > > + return NULL; > > > + > > > + if (!kref_get_unless_zero(&fw->consumers)) > > > + return NULL; > >=20 Hi Andy, Dimitry, > > Don't we have a more traditional way of doing this, i.e. > > try_module_get() coupled with get_device() ? >=20 > get_device() will make sure that device is there, but gives no > assurances that device is bound to a driver, so it will not help with > the racy access to firmware via platform_get_drvdata() call. I also looked at using get/put_device() just as a means for refcounting (i.= e. replacing fw->consumers), but I can't make it work either. I'd need a way t= o hook up into one of the struct device_ktype release() functions. AFAIK it's= not possible for private uses like this. IIUC the way to do this would be to bypass platform device and create a spe= cial device class/bus for RPi's firmware dependent devices (I could pretty much = copy SCMI's implementation), but I fear that's overkill. So, for now I'll stick with the kref based implementation, I'll be happy to change it if you find a better solution. :) Regards, Nicolas --=-4mT4pfaztxo3yJL0guCg 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+77ycACgkQlfZmHno8 x/4SuAf/fbVt5dbVlASpaXs9h1cMXb/e8xl+GmDU2l1pP/uQHmyY+sGKGqNo7+G1 gtKuEhPEavnasiHhJaBTWCCpwytJF9/iToX0i75cDZIObrF1xbO1A3L7hvlRiO6x C+oECKGo3/Awayb7MRHqEiRrLqtuu0odnT3Usn26Rbo7J2o5Lc4KF8WwYblFkmV9 KCW77SlB/6W865vD6KK1KaN6nPqOD3XmKC7doM/MWHIvYd8siFy8qlT5m06s/vhC OHHbX2/7bhgcB+3/9LA9TF5J/JU9KIDHuUVbPYC2hcAVbkELXL93OwJ3DnN7csjp 6obres4oiWUNt0B5Zi7lJDT4Y1KnUw== =C3d8 -----END PGP SIGNATURE----- --=-4mT4pfaztxo3yJL0guCg-- --===============5459558824259436106== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============5459558824259436106==--