All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Ray Jui" <rjui@broadcom.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com, linux-pwm@vger.kernel.org,
	arm-soc <linux-arm-kernel@lists.infradead.org>,
	linux-devicetree <devicetree@vger.kernel.org>,
	wahrenst@gmx.net, "Linux Input" <linux-input@vger.kernel.org>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Greg KH" <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	linux-gpio <linux-gpio@vger.kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	linux-clk <linux-clk@vger.kernel.org>,
	"Stephen Boyd" <sboyd@kernel.org>,
	linux-rpi-kernel@lists.infradead.org,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers
Date: Thu, 03 Dec 2020 09:53:12 +0100	[thread overview]
Message-ID: <401be3062e06f4896662da179a751a1a08b8a75a.camel@suse.de> (raw)
In-Reply-To: <CAMpxmJX6zdoYek2THEj2x8ycJYz-bxqE_5RnOz1sYv0vwLSFpA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2874 bytes --]

On Thu, 2020-12-03 at 09:05 +0100, Bartosz Golaszewski wrote:
> On Mon, Nov 23, 2020 at 7:38 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.
> > 
> > Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> > 
> > Changes since v3:
> > - Use kref instead of waiting on refcount
> > 
> >  drivers/firmware/raspberrypi.c             | 37 +++++++++++++++++++---
> >  include/soc/bcm2835/raspberrypi-firmware.h |  2 ++
> >  2 files changed, 35 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> > index 30259dc9b805..ed793aef7851 100644
> > --- a/drivers/firmware/raspberrypi.c
> > +++ b/drivers/firmware/raspberrypi.c
> > @@ -7,6 +7,7 @@
> >   */
> > 
> >  #include <linux/dma-mapping.h>
> > +#include <linux/kref.h>
> >  #include <linux/mailbox_client.h>
> >  #include <linux/module.h>
> >  #include <linux/of_platform.h>
> > @@ -27,6 +28,8 @@ struct rpi_firmware {
> >         struct mbox_chan *chan; /* The property channel. */
> >         struct completion c;
> >         u32 enabled;
> > +
> > +       struct kref consumers;
> >  };
> > 
> >  static DEFINE_MUTEX(transaction_lock);
> > @@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev)
> >                                                 -1, NULL, 0);
> >  }
> > 
> > +static void rpi_firmware_delete(struct kref *kref)
> > +{
> > +       struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
> > +                                              consumers);
> > +
> > +       mbox_free_channel(fw->chan);
> > +       kfree(fw);
> > +}
> > +
> > +void rpi_firmware_put(struct rpi_firmware *fw)
> > +{
> > +       kref_put(&fw->consumers, rpi_firmware_delete);
> > +}
> > +EXPORT_SYMBOL_GPL(rpi_firmware_put);
> > +
> >  static int rpi_firmware_probe(struct platform_device *pdev)
> >  {
> >         struct device *dev = &pdev->dev;
> >         struct rpi_firmware *fw;
> > 
> > -       fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
> 
> One nit from my side: maybe add a comment here saying that you really
> want to use non-managed kzalloc() because you're going to get people
> blindly converting it to devm_kzalloc() very soon.

Good point, I'll change it.

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
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 v5 01/11] firmware: raspberrypi: Keep count of all consumers
Date: Thu, 03 Dec 2020 09:53:12 +0100	[thread overview]
Message-ID: <401be3062e06f4896662da179a751a1a08b8a75a.camel@suse.de> (raw)
In-Reply-To: <CAMpxmJX6zdoYek2THEj2x8ycJYz-bxqE_5RnOz1sYv0vwLSFpA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2874 bytes --]

On Thu, 2020-12-03 at 09:05 +0100, Bartosz Golaszewski wrote:
> On Mon, Nov 23, 2020 at 7:38 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.
> > 
> > Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> > 
> > Changes since v3:
> > - Use kref instead of waiting on refcount
> > 
> >  drivers/firmware/raspberrypi.c             | 37 +++++++++++++++++++---
> >  include/soc/bcm2835/raspberrypi-firmware.h |  2 ++
> >  2 files changed, 35 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> > index 30259dc9b805..ed793aef7851 100644
> > --- a/drivers/firmware/raspberrypi.c
> > +++ b/drivers/firmware/raspberrypi.c
> > @@ -7,6 +7,7 @@
> >   */
> > 
> >  #include <linux/dma-mapping.h>
> > +#include <linux/kref.h>
> >  #include <linux/mailbox_client.h>
> >  #include <linux/module.h>
> >  #include <linux/of_platform.h>
> > @@ -27,6 +28,8 @@ struct rpi_firmware {
> >         struct mbox_chan *chan; /* The property channel. */
> >         struct completion c;
> >         u32 enabled;
> > +
> > +       struct kref consumers;
> >  };
> > 
> >  static DEFINE_MUTEX(transaction_lock);
> > @@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev)
> >                                                 -1, NULL, 0);
> >  }
> > 
> > +static void rpi_firmware_delete(struct kref *kref)
> > +{
> > +       struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
> > +                                              consumers);
> > +
> > +       mbox_free_channel(fw->chan);
> > +       kfree(fw);
> > +}
> > +
> > +void rpi_firmware_put(struct rpi_firmware *fw)
> > +{
> > +       kref_put(&fw->consumers, rpi_firmware_delete);
> > +}
> > +EXPORT_SYMBOL_GPL(rpi_firmware_put);
> > +
> >  static int rpi_firmware_probe(struct platform_device *pdev)
> >  {
> >         struct device *dev = &pdev->dev;
> >         struct rpi_firmware *fw;
> > 
> > -       fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
> 
> One nit from my side: maybe add a comment here saying that you really
> want to use non-managed kzalloc() because you're going to get people
> blindly converting it to devm_kzalloc() very soon.

Good point, I'll change it.

Regards,
Nicolas


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

WARNING: multiple messages have this Message-ID (diff)
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
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 v5 01/11] firmware: raspberrypi: Keep count of all consumers
Date: Thu, 03 Dec 2020 09:53:12 +0100	[thread overview]
Message-ID: <401be3062e06f4896662da179a751a1a08b8a75a.camel@suse.de> (raw)
In-Reply-To: <CAMpxmJX6zdoYek2THEj2x8ycJYz-bxqE_5RnOz1sYv0vwLSFpA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2874 bytes --]

On Thu, 2020-12-03 at 09:05 +0100, Bartosz Golaszewski wrote:
> On Mon, Nov 23, 2020 at 7:38 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.
> > 
> > Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> > ---
> > 
> > Changes since v3:
> > - Use kref instead of waiting on refcount
> > 
> >  drivers/firmware/raspberrypi.c             | 37 +++++++++++++++++++---
> >  include/soc/bcm2835/raspberrypi-firmware.h |  2 ++
> >  2 files changed, 35 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> > index 30259dc9b805..ed793aef7851 100644
> > --- a/drivers/firmware/raspberrypi.c
> > +++ b/drivers/firmware/raspberrypi.c
> > @@ -7,6 +7,7 @@
> >   */
> > 
> >  #include <linux/dma-mapping.h>
> > +#include <linux/kref.h>
> >  #include <linux/mailbox_client.h>
> >  #include <linux/module.h>
> >  #include <linux/of_platform.h>
> > @@ -27,6 +28,8 @@ struct rpi_firmware {
> >         struct mbox_chan *chan; /* The property channel. */
> >         struct completion c;
> >         u32 enabled;
> > +
> > +       struct kref consumers;
> >  };
> > 
> >  static DEFINE_MUTEX(transaction_lock);
> > @@ -225,12 +228,27 @@ static void rpi_register_clk_driver(struct device *dev)
> >                                                 -1, NULL, 0);
> >  }
> > 
> > +static void rpi_firmware_delete(struct kref *kref)
> > +{
> > +       struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
> > +                                              consumers);
> > +
> > +       mbox_free_channel(fw->chan);
> > +       kfree(fw);
> > +}
> > +
> > +void rpi_firmware_put(struct rpi_firmware *fw)
> > +{
> > +       kref_put(&fw->consumers, rpi_firmware_delete);
> > +}
> > +EXPORT_SYMBOL_GPL(rpi_firmware_put);
> > +
> >  static int rpi_firmware_probe(struct platform_device *pdev)
> >  {
> >         struct device *dev = &pdev->dev;
> >         struct rpi_firmware *fw;
> > 
> > -       fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
> 
> One nit from my side: maybe add a comment here saying that you really
> want to use non-managed kzalloc() because you're going to get people
> blindly converting it to devm_kzalloc() very soon.

Good point, I'll change it.

Regards,
Nicolas


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-12-03  8:54 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 18:38 [PATCH v5 00/11] Raspberry Pi PoE HAT fan support Nicolas Saenz Julienne
2020-11-23 18:38 ` Nicolas Saenz Julienne
2020-11-23 18:38 ` Nicolas Saenz Julienne
2020-11-23 18:38 ` [PATCH v5 01/11] firmware: raspberrypi: Keep count of all consumers Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:26   ` Florian Fainelli
2020-12-02 17:26     ` Florian Fainelli
2020-12-02 17:26     ` Florian Fainelli
2020-12-03  8:05   ` Bartosz Golaszewski
2020-12-03  8:05     ` Bartosz Golaszewski
2020-12-03  8:05     ` Bartosz Golaszewski
2020-12-03  8:53     ` Nicolas Saenz Julienne [this message]
2020-12-03  8:53       ` Nicolas Saenz Julienne
2020-12-03  8:53       ` Nicolas Saenz Julienne
2020-11-23 18:38 ` [PATCH v5 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:27   ` Florian Fainelli
2020-12-02 17:27     ` Florian Fainelli
2020-12-02 17:27     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 03/11] clk: bcm: rpi: Release firmware handle on unbind Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:28   ` Florian Fainelli
2020-12-02 17:28     ` Florian Fainelli
2020-12-02 17:28     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 04/11] gpio: raspberrypi-exp: " Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:29   ` Florian Fainelli
2020-12-02 17:29     ` Florian Fainelli
2020-12-02 17:29     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 05/11] reset: raspberrypi: " Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:29   ` Florian Fainelli
2020-12-02 17:29     ` Florian Fainelli
2020-12-02 17:29     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 06/11] soc: bcm: raspberrypi-power: " Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:55   ` Florian Fainelli
2020-12-02 17:55     ` Florian Fainelli
2020-12-02 17:55     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 07/11] staging: vchiq: " Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02 17:56   ` Florian Fainelli
2020-12-02 17:56     ` Florian Fainelli
2020-12-02 17:56     ` Florian Fainelli
2020-11-23 18:38 ` [PATCH v5 08/11] input: raspberrypi-ts: Release firmware handle when not needed Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-02  6:03   ` Dmitry Torokhov
2020-12-02  6:03     ` Dmitry Torokhov
2020-12-02  6:03     ` Dmitry Torokhov
2020-12-03 14:52     ` Nicolas Saenz Julienne
2020-12-03 14:52       ` Nicolas Saenz Julienne
2020-12-03 14:52       ` Nicolas Saenz Julienne
2020-11-23 18:38 ` [PATCH v5 09/11] dt-bindings: pwm: Add binding for RPi firmware PWM bus Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38 ` [PATCH v5 10/11] DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38 ` [PATCH v5 11/11] pwm: Add Raspberry Pi Firmware based PWM bus Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-11-23 18:38   ` Nicolas Saenz Julienne
2020-12-09 10:42   ` Nicolas Saenz Julienne
2020-12-09 10:42     ` Nicolas Saenz Julienne
2020-12-09 10:42     ` 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=401be3062e06f4896662da179a751a1a08b8a75a.camel@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.