* [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios()
@ 2017-03-02 13:48 Andy Shevchenko
2017-03-02 22:07 ` Rafael J. Wysocki
2017-03-14 9:58 ` Linus Walleij
0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2017-03-02 13:48 UTC (permalink / raw)
To: Linus Walleij, linux-gpio, Rafael J. Wysocki, linux-acpi,
Mika Westerberg, linux-kernel
Cc: Andy Shevchenko
Introduce device managed variant of acpi_dev_add_driver_gpios() and its
counterpart acpi_dev_remove_driver_gpios().
The functions in most cases are used in driver's ->probe() and
->remove() callbacks, that's why it's useful to have managed variant of
them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
This is supposed to go through GPIO tree.
Linus, can you create an immutable branch that other subsystems can use
it if needed?
(We currently have one possible leak and devm_*() would help there)
drivers/gpio/gpiolib-acpi.c | 31 +++++++++++++++++++++++++++++++
include/linux/acpi.h | 11 +++++++++++
2 files changed, 42 insertions(+)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 1459e6183194..3fe63d8ed426 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -362,6 +362,37 @@ int acpi_dev_add_driver_gpios(struct acpi_device *adev,
}
EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios);
+static void devm_acpi_dev_release_driver_gpios(struct device *dev, void *res)
+{
+ acpi_dev_remove_driver_gpios(ACPI_COMPANION(dev));
+}
+
+int devm_acpi_dev_add_driver_gpios(struct device *dev,
+ const struct acpi_gpio_mapping *gpios)
+{
+ void *res;
+ int ret;
+
+ res = devres_alloc(devm_acpi_dev_release_driver_gpios, 0, GFP_KERNEL);
+ if (!res)
+ return -ENOMEM;
+
+ ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), gpios);
+ if (ret) {
+ devres_free(res);
+ return ret;
+ }
+ devres_add(dev, res);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_acpi_dev_add_driver_gpios);
+
+void devm_acpi_dev_remove_driver_gpios(struct device *dev)
+{
+ WARN_ON(devres_release(dev, devm_acpi_dev_release_driver_gpios, NULL, NULL));
+}
+EXPORT_SYMBOL_GPL(devm_acpi_dev_remove_driver_gpios);
+
static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
const char *name, int index,
struct acpi_reference_args *args)
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 673acda012af..c8eaaad4a9ed 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -952,6 +952,10 @@ static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev)
adev->driver_gpios = NULL;
}
+int devm_acpi_dev_add_driver_gpios(struct device *dev,
+ const struct acpi_gpio_mapping *gpios);
+void devm_acpi_dev_remove_driver_gpios(struct device *dev);
+
int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
#else
static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
@@ -961,6 +965,13 @@ static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
}
static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
+static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
+ const struct acpi_gpio_mapping *gpios)
+{
+ return -ENXIO;
+}
+static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
+
static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
{
return -ENXIO;
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios()
2017-03-02 13:48 [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios() Andy Shevchenko
@ 2017-03-02 22:07 ` Rafael J. Wysocki
2017-03-14 9:58 ` Linus Walleij
1 sibling, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2017-03-02 22:07 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, linux-gpio, linux-acpi, Mika Westerberg,
linux-kernel
On Thursday, March 02, 2017 03:48:05 PM Andy Shevchenko wrote:
> Introduce device managed variant of acpi_dev_add_driver_gpios() and its
> counterpart acpi_dev_remove_driver_gpios().
>
> The functions in most cases are used in driver's ->probe() and
> ->remove() callbacks, that's why it's useful to have managed variant of
> them.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>
> This is supposed to go through GPIO tree.
>
> Linus, can you create an immutable branch that other subsystems can use
> it if needed?
>
> (We currently have one possible leak and devm_*() would help there)
>
> drivers/gpio/gpiolib-acpi.c | 31 +++++++++++++++++++++++++++++++
> include/linux/acpi.h | 11 +++++++++++
> 2 files changed, 42 insertions(+)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index 1459e6183194..3fe63d8ed426 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -362,6 +362,37 @@ int acpi_dev_add_driver_gpios(struct acpi_device *adev,
> }
> EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios);
>
> +static void devm_acpi_dev_release_driver_gpios(struct device *dev, void *res)
> +{
> + acpi_dev_remove_driver_gpios(ACPI_COMPANION(dev));
> +}
> +
> +int devm_acpi_dev_add_driver_gpios(struct device *dev,
> + const struct acpi_gpio_mapping *gpios)
> +{
> + void *res;
> + int ret;
> +
> + res = devres_alloc(devm_acpi_dev_release_driver_gpios, 0, GFP_KERNEL);
> + if (!res)
> + return -ENOMEM;
> +
> + ret = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), gpios);
> + if (ret) {
> + devres_free(res);
> + return ret;
> + }
> + devres_add(dev, res);
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(devm_acpi_dev_add_driver_gpios);
> +
> +void devm_acpi_dev_remove_driver_gpios(struct device *dev)
> +{
> + WARN_ON(devres_release(dev, devm_acpi_dev_release_driver_gpios, NULL, NULL));
> +}
> +EXPORT_SYMBOL_GPL(devm_acpi_dev_remove_driver_gpios);
> +
> static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
> const char *name, int index,
> struct acpi_reference_args *args)
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 673acda012af..c8eaaad4a9ed 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -952,6 +952,10 @@ static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev)
> adev->driver_gpios = NULL;
> }
>
> +int devm_acpi_dev_add_driver_gpios(struct device *dev,
> + const struct acpi_gpio_mapping *gpios);
> +void devm_acpi_dev_remove_driver_gpios(struct device *dev);
> +
> int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
> #else
> static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
> @@ -961,6 +965,13 @@ static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
> }
> static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
>
> +static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
> + const struct acpi_gpio_mapping *gpios)
> +{
> + return -ENXIO;
> +}
> +static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
> +
> static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
> {
> return -ENXIO;
>
ACK for the ACPI header update.
Thanks,
Rafael
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios()
2017-03-02 13:48 [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios() Andy Shevchenko
2017-03-02 22:07 ` Rafael J. Wysocki
@ 2017-03-14 9:58 ` Linus Walleij
2017-03-14 12:27 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2017-03-14 9:58 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-gpio@vger.kernel.org, Rafael J. Wysocki,
ACPI Devel Maling List, Mika Westerberg,
linux-kernel@vger.kernel.org
On Thu, Mar 2, 2017 at 2:48 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Introduce device managed variant of acpi_dev_add_driver_gpios() and its
> counterpart acpi_dev_remove_driver_gpios().
>
> The functions in most cases are used in driver's ->probe() and
> ->remove() callbacks, that's why it's useful to have managed variant of
> them.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>
> This is supposed to go through GPIO tree.
>
> Linus, can you create an immutable branch that other subsystems can use
> it if needed?
I have created ib-acpi-devm in the GPIO tree based on v4.11-rc1, applied
this patch and merged that into my devel branch.
Anyone who needs it can grab that branch, I will push it out later.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios()
2017-03-14 9:58 ` Linus Walleij
@ 2017-03-14 12:27 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2017-03-14 12:27 UTC (permalink / raw)
To: Linus Walleij
Cc: linux-gpio@vger.kernel.org, Rafael J. Wysocki,
ACPI Devel Maling List, Mika Westerberg,
linux-kernel@vger.kernel.org
On Tue, 2017-03-14 at 10:58 +0100, Linus Walleij wrote:
> On Thu, Mar 2, 2017 at 2:48 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
>
> > Introduce device managed variant of acpi_dev_add_driver_gpios() and
> > its
> > counterpart acpi_dev_remove_driver_gpios().
> >
> > The functions in most cases are used in driver's ->probe() and
> > ->remove() callbacks, that's why it's useful to have managed variant
> > of
> > them.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >
> > This is supposed to go through GPIO tree.
> >
> > Linus, can you create an immutable branch that other subsystems can
> > use
> > it if needed?
>
> I have created ib-acpi-devm in the GPIO tree based on v4.11-rc1,
> applied
> this patch and merged that into my devel branch.
>
> Anyone who needs it can grab that branch, I will push it out later.
Thanks!
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-14 12:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-02 13:48 [PATCH v1] gpio: acpi: Add managed variant of acpi_dev_add_driver_gpios() Andy Shevchenko
2017-03-02 22:07 ` Rafael J. Wysocki
2017-03-14 9:58 ` Linus Walleij
2017-03-14 12:27 ` Andy Shevchenko
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).