Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp544260pxb; Thu, 12 Nov 2020 09:55:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiudqPOizCzHMnl7xfivchhOFq5f7nT6xhNNgLsQG8imfdREbVyeccP74WIpOMXoQ1QZ4p X-Received: by 2002:a05:6402:b28:: with SMTP id bo8mr1044651edb.57.1605203717454; Thu, 12 Nov 2020 09:55:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605203717; cv=none; d=google.com; s=arc-20160816; b=ni8zgaBhPuFozdQqGU671J6nB9weyFjkedcGl+7MP0/RTw6aEd9u7srJM0yyy4BtpH epmNYMFQ/GLOTDGwd4fppl4hLJGEdHakO61KcK9ElB2XNKURVnuGsXfw917814DxEUpu yGAVfrH8DlBaDlN4EbXf5X2sot0JT45ZPn4uoXTueaz6yGXZ/wp0/djG2J5J6prr0wGV /gx2c3Ecop92FSVDoMHlH7ld+PlxeuRuL0D1KxgtseU1eZS9BiqstRJec6wu5rzmAIu3 puPQkT4Bkcaym+P+4pMG647+td2rmHPRtxsLd1n0yGCQ92HwUfCAnqA+Kem2c4MZLX+f x86Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EywCTDkeiYnus//+DkG9p7x5uOXcjsUoW/CpBJQjGh4=; b=o8w/lUE1pzJ1dRj8HtLTTz2ufXRNlYd9MVre+2LAWSHsXsW5T0ON6QyTZLnd52FOg6 8J+jDYZZkqgUpOV+SuOSWDlouKnun6AL9ovqS9LBJ9FGrQyUi4F6eJClbQmcO6+HPENZ R+uKwV7N4ORfgf4IDnOrwb2I4bnYi1AGs6jhDFST2bh5gUrDdWJXiYd+C/DSLEtLo/Wj qsuJlDT+IKdbCYtr9bJm4b0bKZtMXa7o9ZJOGNl0uTRqBPhWzW2Mi0mlvJJPlFCH96YH /dJ1PKXlxYNcwIV7/IpVLcfsEktkxoakNrU2s1o55A2VRws/0JHxpHpVuFqpzCV+6VUC lG4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V5FRj9dv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si4412175edr.174.2020.11.12.09.54.54; Thu, 12 Nov 2020 09:55:17 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V5FRj9dv; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726353AbgKLRv0 (ORCPT + 99 others); Thu, 12 Nov 2020 12:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgKLRvZ (ORCPT ); Thu, 12 Nov 2020 12:51:25 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8D06C0613D1; Thu, 12 Nov 2020 09:51:25 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id i7so4813208pgh.6; Thu, 12 Nov 2020 09:51:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EywCTDkeiYnus//+DkG9p7x5uOXcjsUoW/CpBJQjGh4=; b=V5FRj9dv8LZyKY//w8MnGopC83oSkh3/f67EKu2H49jcmyUNYveReXkMJBzGvyFd4q mKcvNnhVICd/UhAL/HH1jUpFUyrBz0394onSteeXHeV50i9Ez+UPXVRJ/ggkQfCzqgGm kZTUJSpVayCtwC4cSeh7i9ajykTWfmMo/ei8+RErGCyLv9pJdlXF4oU6ddtDfkVU1QZ3 C/k7/c7VYeacSw8c3j9jFOs+fpuV13Cto+tr+PxtXt9xpKbVtuE00030bzHITnLQ8DGM vefvzjW/M2wcH5x0dDt9q//PluUhKPH7ylVjCzGUXYm7NdXATfhWLzirDL/eJBFpUpwn k6TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EywCTDkeiYnus//+DkG9p7x5uOXcjsUoW/CpBJQjGh4=; b=e28/RxZ+ARc7dvK3ScOb7cdlXt99THlRc2eehygJRH565Wb3mbY3N4MsyeplAosISQ f33vgt+HuvDTiXul+CDzKFkcPtBRfWosQ9eSPJKDUqCXjSKPa9Iv955b8062n3HysKas 0aYPsX3avOIz6Zpz4iP/ft9xqv206uf/+qaC9TOnLo6yaQgTaKRkjt0P+ONOD9mobpYp eJR8ndYvN/wCN5lY06RxFaElbhxdf/ZzjXwWlwtL4UwIifZpYNHfgZpLNfdeNvKtB0w9 e06a9Mmzn2spHxiPvO9v5wRqFe1GANtXlrJNbUANj4nnFHbGWrxiOg9BvYiGQVU8K33F dqGQ== X-Gm-Message-State: AOAM533fe6X4eJ5dfHMAQ4HA+d9OGTwRatLeHY4rlLXPV9lTSk0sCVh/ BLWnIlefQZMwNtkuBXeWDG3PE151O1eInNO/ehk= X-Received: by 2002:a17:90b:fc6:: with SMTP id gd6mr287022pjb.181.1605203485218; Thu, 12 Nov 2020 09:51:25 -0800 (PST) MIME-Version: 1.0 References: <20201112163630.17177-1-nsaenzjulienne@suse.de> <20201112163630.17177-2-nsaenzjulienne@suse.de> In-Reply-To: <20201112163630.17177-2-nsaenzjulienne@suse.de> From: Andy Shevchenko Date: Thu, 12 Nov 2020 19:52:14 +0200 Message-ID: Subject: Re: [PATCH v4 01/11] firmware: raspberrypi: Keep count of all consumers To: Nicolas Saenz Julienne Cc: =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Linux Kernel Mailing List , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list , linux-pwm@vger.kernel.org, linux-arm Mailing List , devicetree , Stefan Wahren , linux-input , Dmitry Torokhov , Greg Kroah-Hartman , "open list:STAGING SUBSYSTEM" , Philipp Zabel , "open list:GPIO SUBSYSTEM" , Linus Walleij , linux-clk , Stephen Boyd , linux-rpi-kernel , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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() ? > + return fw; > } -- With Best Regards, Andy Shevchenko