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.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 0C27DC4742C for ; Fri, 13 Nov 2020 07:27:46 +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 85CF820825 for ; Fri, 13 Nov 2020 07:27:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Oy0PyVZY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GMiotV0G" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85CF820825 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0FsnFffaPY6EtO6Y5Gz9H2K05BtqZFi0G0FHrLzkcQ0=; b=Oy0PyVZYlKMWWhAqhohzh8bZ7 /fmkf6ALWniaQhG/W5NkzjBPZPY3avJRQwdUYOVM22ZwUl1bC3eTAQynpwYzUMqNgPzuNNo5HRqVv lwI2d2qdZOR7k2YegHOd6V+D6h3knhSou0yziGroqO6ur+/+K07+XnlgtoNHnGgAsEkMPB+HVlu8q 6ApuSfi02v9JmVJpD4fX8s/qAJ5E283HfIOk4jZm2JTSAoil9tWqWR+K9GxZULdoD4Kt9pujRLvXn 08GaB5ip6R+o/R6D4qQjR0f8PQ2GWFalD2yJQwoW7tK2SJqsCSsh2GI/qYjpUGrXgPPnjJw9+Hb94 VDu/Dh+hw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdTTV-0005GW-E6; Fri, 13 Nov 2020 07:26:25 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdTTT-0005Fx-4I; Fri, 13 Nov 2020 07:26:23 +0000 Received: by mail-pl1-x644.google.com with SMTP id y22so4152362plr.6; Thu, 12 Nov 2020 23:26:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bVc4aZk4rKy/6/VqEhMXbEQ5ZVosOHXwKRbVIxDDoGY=; b=GMiotV0GyRZSn0pn1dgPWm/1yR1DzPikBgKi5Lbkr2+y/iNDlpqYBVO7SfIvAgqAbf uIaCVLY528t7w5yWehm/+G4BNoS1lB69IH4dB9iSPueZ2vY4/XYJoWpU0aQEMS570PMt gfyrGW2DRdfuIkQPiOQfGiyd6Icf9TqwlJVhKT9GlbO7q/Mj4/7h6vRa/vNWfxW1mehI GBBBTEzl+JU36/Sc52m4n+V0gVtafzPbCLB2RuMl1UZyUSG2LeWJBlAiNPu5ZgflYKFh dBz3JOOX0NRmiUfmf22A+yolC5R2dAEyS/GcPJGRpS4tu3Prtj7hQV+cpG105mS2OmpU cB8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bVc4aZk4rKy/6/VqEhMXbEQ5ZVosOHXwKRbVIxDDoGY=; b=pJrMdbN0v66F1DLDe6umtFXLPS7o9qvy6OZlAp9oNOJ5BuGWg1Nx/M+alNFD5FwBzS 17josXi0sZGnOjZfudl9DpR67JL5Aw+3BBpgrcpAmtUJ0u5uJyuWJueh6i6THsMwTkfW vhippxrs3vOwyFDVvjDxearIAYJ4/iQiebR4Jv82qFOOTf3ISmVytZ3K9Krt8L6WMAmD 8YrAqIEf2VI0oULSTUrUAdGUd19GMPNEi+4a1MzKdy3d992L+toE+YzXON99K0gGXBLp L2Awjl6Btd9X05EXbtp+bfKeAVT19csEEp3LC+W288UPU3198B7NwFCcozhqhkJWmClh WMSw== X-Gm-Message-State: AOAM531GpjpR2kmNA35+FIVSoP5ZPSZ5Qq7QP5PymKcxWchjG5wf/BnN yoQSiwIWWB9NUJLFiJr6m2s= X-Google-Smtp-Source: ABdhPJwxvk3sEiTwtCGzh6+CErNAzuUpI0fhTqrV5pUBqPIIf6eT7t4y2GPOTdCy6tzoqSvWpYqfbA== X-Received: by 2002:a17:902:c016:b029:d7:1a0:7cf0 with SMTP id v22-20020a170902c016b02900d701a07cf0mr878425plx.64.1605252379251; Thu, 12 Nov 2020 23:26:19 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:a6ae:11ff:fe11:fcc3]) by smtp.gmail.com with ESMTPSA id l20sm9170507pfd.103.2020.11.12.23.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 23:26:18 -0800 (PST) Date: Thu, 12 Nov 2020 23:26:15 -0800 From: Dmitry Torokhov To: Andy Shevchenko Subject: Re: [PATCH v4 01/11] firmware: raspberrypi: Keep count of all consumers Message-ID: <20201113072615.GE356503@dtor-ws> References: <20201112163630.17177-1-nsaenzjulienne@suse.de> <20201112163630.17177-2-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_022623_219601_CC1E2101 X-CRM114-Status: GOOD ( 22.45 ) 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, linux-rpi-kernel , 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 , linux-arm Mailing List , Philipp Zabel , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Bartosz Golaszewski , linux-clk , Nicolas Saenz Julienne , Stefan Wahren Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: > > > > 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. > > > > Keep a reference count of all consumers and introduce rpi_firmware_put() > > which will permit automatically decrease the reference count upon > > unbinding consumer drivers. > > ... > > > /** > > - * rpi_firmware_get - Get pointer to rpi_firmware structure. > > * @firmware_node: Pointer to the firmware Device Tree node. > > * > > + * The reference to rpi_firmware has to be released with rpi_firmware_put(). > > + * > > * Returns NULL is the firmware device is not ready. > > */ > > struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node) > > { > > struct platform_device *pdev = of_find_device_by_node(firmware_node); > > + struct rpi_firmware *fw; > > > > if (!pdev) > > return NULL; > > > > - return platform_get_drvdata(pdev); > > + fw = platform_get_drvdata(pdev); > > + if (!fw) > > + return NULL; > > + > > + if (!kref_get_unless_zero(&fw->consumers)) > > + return NULL; > > Don't we have a more traditional way of doing this, i.e. > try_module_get() coupled with get_device() ? 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. Thanks. -- Dmitry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel