From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: "open list:STAGING SUBSYSTEM" <devel@driverdev.osuosl.org>,
linux-pwm@vger.kernel.org,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Scott Branden" <sbranden@broadcom.com>,
devicetree <devicetree@vger.kernel.org>,
"Stephen Boyd" <sboyd@kernel.org>, "Ray Jui" <rjui@broadcom.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
linux-input <linux-input@vger.kernel.org>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
bcm-kernel-feedback-list <bcm-kernel-feedback-list@broadcom.com>,
"Stefan Wahren" <wahrenst@gmx.net>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Bartosz Golaszewski" <bgolaszewski@baylibre.com>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
linux-clk <linux-clk@vger.kernel.org>,
"linux-arm Mailing List" <linux-arm-kernel@lists.infradead.org>,
linux-rpi-kernel <linux-rpi-kernel@lists.infradead.org>
Subject: Re: [PATCH v4 01/11] firmware: raspberrypi: Keep count of all consumers
Date: Thu, 12 Nov 2020 19:52:14 +0200 [thread overview]
Message-ID: <CAHp75Vf9E7UWVDMs=eRjLjoSN6SVOWw9thNdnR8ruCL6GmY7JQ@mail.gmail.com> (raw)
In-Reply-To: <20201112163630.17177-2-nsaenzjulienne@suse.de>
On Thu, Nov 12, 2020 at 6:40 PM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> 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
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
next prev parent reply other threads:[~2020-11-12 17:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 16:36 [PATCH v4 00/11] Raspberry Pi PoE HAT fan support Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 01/11] firmware: raspberrypi: Keep count of all consumers Nicolas Saenz Julienne
2020-11-12 17:52 ` Andy Shevchenko [this message]
2020-11-13 7:26 ` Dmitry Torokhov
2020-11-23 17:19 ` Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Nicolas Saenz Julienne
2020-11-12 17:25 ` Bartosz Golaszewski
2020-11-13 9:21 ` Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 03/11] clk: bcm: rpi: Release firmware handle on unbind Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 04/11] gpio: raspberrypi-exp: " Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 05/11] reset: raspberrypi: " Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 06/11] soc: bcm: raspberrypi-power: " Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 07/11] staging: vchiq: " Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 08/11] input: raspberrypi-ts: Release firmware handle when not needed Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 09/11] dt-bindings: pwm: Add binding for RPi firmware PWM bus Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 10/11] DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support Nicolas Saenz Julienne
2020-11-12 16:36 ` [PATCH v4 11/11] pwm: Add Raspberry Pi Firmware based PWM bus Nicolas Saenz Julienne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHp75Vf9E7UWVDMs=eRjLjoSN6SVOWw9thNdnR8ruCL6GmY7JQ@mail.gmail.com' \
--to=andy.shevchenko@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bgolaszewski@baylibre.com \
--cc=devel@driverdev.osuosl.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=nsaenzjulienne@suse.de \
--cc=p.zabel@pengutronix.de \
--cc=rjui@broadcom.com \
--cc=sboyd@kernel.org \
--cc=sbranden@broadcom.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wahrenst@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).