DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: devel@driverdev.osuosl.org, linux-pwm@vger.kernel.org,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	linux-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>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-gpio <linux-gpio@vger.kernel.org>,
	"Greg KH" <gregkh@linuxfoundation.org>,
	bcm-kernel-feedback-list@broadcom.com, wahrenst@gmx.net,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	linux-clk <linux-clk@vger.kernel.org>,
	arm-soc <linux-arm-kernel@lists.infradead.org>,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH v4 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get()
Date: Thu, 12 Nov 2020 18:25:46 +0100
Message-ID: <CAMpxmJWZsqfkkTP99a_8mu+O4xHwNWDqHuvgt7Cs88bA-iMvQA@mail.gmail.com> (raw)
In-Reply-To: <20201112163630.17177-3-nsaenzjulienne@suse.de>

On Thu, Nov 12, 2020 at 5:44 PM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> wrote:
>
> Itroduce devm_rpi_firmware_get(), it'll simplify the firmware handling
> for most consumers.
>
> Suggested-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>
> Changes since v2:
> - Introduce devm_rpi_firmware_get()
>
>  drivers/firmware/raspberrypi.c             | 31 +++++++++++++++++++++-
>  include/soc/bcm2835/raspberrypi-firmware.h |  8 ++++++
>  2 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index 438e17074a97..4ab2dfdc82ad 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
> @@ -237,10 +237,17 @@ static void rpi_firmware_delete(struct kref *kref)
>         kfree(fw);
>  }
>
> -void rpi_firmware_put(struct rpi_firmware *fw)
> +static void __rpi_firmware_put(void *data)
>  {

The '__' prefix is very vague and usually used for unlocked variants
of functions. The casting to void * in rpi_firmware_put() is also
unneeded. I would much prefer that the devres release callback be
called devm_rpi_firmware_put() and that it call rpi_firmware_put()
which would then call kref_put().

Bartosz

> +       struct rpi_firmware *fw = data;
> +
>         kref_put(&fw->consumers, rpi_firmware_delete);
>  }
> +
> +void rpi_firmware_put(struct rpi_firmware *fw)
> +{
> +       __rpi_firmware_put(fw);
> +}
>  EXPORT_SYMBOL_GPL(rpi_firmware_put);
>
>  static int rpi_firmware_probe(struct platform_device *pdev)
> @@ -326,6 +333,28 @@ struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
>  }
>  EXPORT_SYMBOL_GPL(rpi_firmware_get);
>
> +/**
> + * devm_rpi_firmware_get - Get pointer to rpi_firmware structure.
> + * @firmware_node:    Pointer to the firmware Device Tree node.
> + *
> + * Returns NULL is the firmware device is not ready.
> + */
> +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
> +                                          struct device_node *firmware_node)
> +{
> +       struct rpi_firmware *fw;
> +
> +       fw = rpi_firmware_get(firmware_node);
> +       if (!fw)
> +               return NULL;
> +
> +       if (devm_add_action_or_reset(dev, __rpi_firmware_put, fw))
> +               return NULL;
> +
> +       return fw;
> +}
> +EXPORT_SYMBOL_GPL(devm_rpi_firmware_get);
> +
>  static const struct of_device_id rpi_firmware_of_match[] = {
>         { .compatible = "raspberrypi,bcm2835-firmware", },
>         {},
> diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
> index fdfef7fe40df..73ad784fca96 100644
> --- a/include/soc/bcm2835/raspberrypi-firmware.h
> +++ b/include/soc/bcm2835/raspberrypi-firmware.h
> @@ -142,6 +142,8 @@ int rpi_firmware_property_list(struct rpi_firmware *fw,
>                                void *data, size_t tag_size);
>  void rpi_firmware_put(struct rpi_firmware *fw);
>  struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
> +struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
> +                                          struct device_node *firmware_node);
>  #else
>  static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
>                                         void *data, size_t len)
> @@ -160,6 +162,12 @@ static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware
>  {
>         return NULL;
>  }
> +
> +static inline struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
> +                                       struct device_node *firmware_node)
> +{
> +       return NULL;
> +}
>  #endif
>
>  #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */
> --
> 2.29.2
>
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply index

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
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 [this message]
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=CAMpxmJWZsqfkkTP99a_8mu+O4xHwNWDqHuvgt7Cs88bA-iMvQA@mail.gmail.com \
    --to=bgolaszewski@baylibre.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.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

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git