mbox series

[00/13,v2] Regulator ena_gpiod fixups

Message ID 20181201154151.14890-1-linus.walleij@linaro.org
Headers show
Series Regulator ena_gpiod fixups | expand

Message

Linus Walleij Dec. 1, 2018, 3:41 p.m. UTC
Here is a second iteration of these fixups after thinking
over Charles Keepax excellent comments on the first series
of fixes.

To make sure GPIO descriptors are never left dangling
(as far as I can tell!) I use this stepwise approach:

1. Fix the regulator_register() in the core to guarantee
   that after calling this with a valid GPIO descriptor
   in ena_gpiod it will be gpiod_put() if there is any
   problem.

2. Fix up simple descriptor consumers to just gpiod_get()
   and let the core take over the descriptor. Only handle
   the errorpath up to this point.

3. Export gpiod_get_from_of_node() and let max77686
   obtain a GPIO descriptor from the device tree without
   any devres make-up in the DT parsing callback.

4. Invent devm_gpiod_unhinge() that will remove the devres
   monitoring of a devm_* allocated GPIO descriptor
   right before handling it over to the regulator core,
   and use this in the otherwise hairy da9211,
   s5m8767, tps65090 and s2mps11 drivers.

Linus Walleij (13):
  regulator: core: Track dangling GPIO descriptors
  regulator: fixed: Let core handle GPIO descriptor
  regulator: lm363x: Let core handle GPIO descriptor
  regulator: lp8788-ldo: Let core handle GPIO descriptor
  regulator: max8952: Let core handle GPIO descriptor
  regulator: max8973: Let core handle GPIO descriptor
  gpio: Export gpiod_get_from_of_node()
  regulator: max77686: Let core handle GPIO descriptor
  gpio: Add devm_gpiod_unhinge()
  regulator: da9211: Hand over GPIO to regulator core
  regulator: s5m8767: Hand over GPIO to regulator core
  regulator: tps65090: Hand over GPIO to regulator core
  regulator: s2mps11: Hand over GPIO to regulator core

 Documentation/driver-model/devres.txt  |  1 +
 drivers/gpio/gpiolib-devres.c          | 17 ++++++++
 drivers/gpio/gpiolib.h                 |  6 ---
 drivers/regulator/core.c               | 55 +++++++++++++++++++++-----
 drivers/regulator/da9211-regulator.c   |  6 +++
 drivers/regulator/fixed.c              |  6 ++-
 drivers/regulator/lm363x-regulator.c   |  8 +++-
 drivers/regulator/lp8788-ldo.c         |  8 +++-
 drivers/regulator/max77686-regulator.c | 14 ++++---
 drivers/regulator/max8952.c            | 10 +++--
 drivers/regulator/max8973-regulator.c  | 23 +++++++----
 drivers/regulator/s2mps11.c            |  7 +++-
 drivers/regulator/s5m8767.c            |  9 ++++-
 drivers/regulator/tps65090-regulator.c |  6 +++
 include/linux/gpio/consumer.h          | 23 +++++++++++
 15 files changed, 161 insertions(+), 38 deletions(-)

-- 
2.19.1

Comments

Marek Szyprowski Dec. 3, 2018, 2:35 p.m. UTC | #1
Hi Linus,

On 2018-12-01 16:41, Linus Walleij wrote:
> Here is a second iteration of these fixups after thinking

> over Charles Keepax excellent comments on the first series

> of fixes.

>

> To make sure GPIO descriptors are never left dangling

> (as far as I can tell!) I use this stepwise approach:

>

> 1. Fix the regulator_register() in the core to guarantee

>    that after calling this with a valid GPIO descriptor

>    in ena_gpiod it will be gpiod_put() if there is any

>    problem.

>

> 2. Fix up simple descriptor consumers to just gpiod_get()

>    and let the core take over the descriptor. Only handle

>    the errorpath up to this point.

>

> 3. Export gpiod_get_from_of_node() and let max77686

>    obtain a GPIO descriptor from the device tree without

>    any devres make-up in the DT parsing callback.

>

> 4. Invent devm_gpiod_unhinge() that will remove the devres

>    monitoring of a devm_* allocated GPIO descriptor

>    right before handling it over to the regulator core,

>    and use this in the otherwise hairy da9211,

>    s5m8767, tps65090 and s2mps11 drivers.



The idea is good imho, but it looks that there are some missing cases in
the code. Here are some logs from the boards I have access to:


Artik5 evaluation board (arch/arm/boot/dts/exynos3250-artik5-eval.dtb):

s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12
------------[ cut here ]------------
WARNING: CPU: 1 PID: 1 at drivers/gpio/gpiolib-devres.c:336
s2mps11_pmic_probe+0x1c4/0x49c
Modules linked in:
CPU: 1 PID: 1 Comm: swapper/0 Not tainted
4.20.0-rc5-next-20181203-00020-gf6d64d46ca8c #1156
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[<c01125fc>] (unwind_backtrace) from [<c010e140>] (show_stack+0x10/0x14)
[<c010e140>] (show_stack) from [<c0a510bc>] (dump_stack+0x98/0xc4)
[<c0a510bc>] (dump_stack) from [<c0127078>] (__warn+0x10c/0x124)
[<c0127078>] (__warn) from [<c01271a4>] (warn_slowpath_null+0x40/0x48)
[<c01271a4>] (warn_slowpath_null) from [<c04e5c94>]
(s2mps11_pmic_probe+0x1c4/0x49c)
[<c04e5c94>] (s2mps11_pmic_probe) from [<c0583e60>]
(platform_drv_probe+0x48/0x9c)
[<c0583e60>] (platform_drv_probe) from [<c0581858>]
(really_probe+0x274/0x400)
[<c0581858>] (really_probe) from [<c0581ba0>]
(driver_probe_device+0x78/0x1b8)
[<c0581ba0>] (driver_probe_device) from [<c0581e08>]
(__driver_attach+0x128/0x144)
[<c0581e08>] (__driver_attach) from [<c057f71c>]
(bus_for_each_dev+0x68/0xb4)
[<c057f71c>] (bus_for_each_dev) from [<c0580a1c>]
(bus_add_driver+0x1a8/0x268)
[<c0580a1c>] (bus_add_driver) from [<c0582e44>] (driver_register+0x78/0x10c)
[<c0582e44>] (driver_register) from [<c0103154>]
(do_one_initcall+0x8c/0x410)
[<c0103154>] (do_one_initcall) from [<c0f0124c>]
(kernel_init_freeable+0x3c8/0x4d0)
[<c0f0124c>] (kernel_init_freeable) from [<c0a6afd4>]
(kernel_init+0x8/0x10c)
random: fast init done
[<c0a6afd4>] (kernel_init) from [<c01010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xd8cc1fb0 to 0xd8cc1ff8)
1fa0:                                     00000000 00000000 00000000
00000000
1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000
1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
irq event stamp: 98209
hardirqs last  enabled at (98217): [<c0192e14>] console_unlock+0x4ac/0x698
hardirqs last disabled at (98256): [<c0192a34>] console_unlock+0xcc/0x698
softirqs last  enabled at (98276): [<c0102618>] __do_softirq+0x4f0/0x5e0
softirqs last disabled at (98289): [<c012f2f4>] irq_exit+0x160/0x16c
---[ end trace fed5502b2c7cd57b ]---
Unable to handle kernel paging request at virtual address fffffff0
pgd = (ptrval)
[fffffff0] *pgd=597ce841, *pte=00000000, *ppte=00000000
Internal error: Oops: 27 [#1] PREEMPT SMP ARM
Modules linked in:
CPU: 1 PID: 1 Comm: swapper/0 Tainted: G        W        
4.20.0-rc5-next-20181203-00020-gf6d64d46ca8c #1156
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
PC is at devm_gpiod_match+0x4/0x18
LR is at devres_remove+0x68/0xb8
...
Flags: NzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 4000406a  DAC: 00000051
Process swapper/0 (pid: 1, stack limit = 0x(ptrval))
Stack: (0xd8cc1d58 to 0xd8cc2000)
...
[<c04a6f1c>] (devm_gpiod_match) from [<c05854b8>] (devres_remove+0x68/0xb8)
[<c05854b8>] (devres_remove) from [<c0585cdc>] (devres_destroy+0x8/0x24)
[<c0585cdc>] (devres_destroy) from [<c04a74a4>]
(devm_gpiod_unhinge+0x1c/0x38)
[<c04a74a4>] (devm_gpiod_unhinge) from [<c04e5c94>]
(s2mps11_pmic_probe+0x1c4/0x49c)
[<c04e5c94>] (s2mps11_pmic_probe) from [<c0583e60>]
(platform_drv_probe+0x48/0x9c)
[<c0583e60>] (platform_drv_probe) from [<c0581858>]
(really_probe+0x274/0x400)
[<c0581858>] (really_probe) from [<c0581ba0>]
(driver_probe_device+0x78/0x1b8)
[<c0581ba0>] (driver_probe_device) from [<c0581e08>]
(__driver_attach+0x128/0x144)
[<c0581e08>] (__driver_attach) from [<c057f71c>]
(bus_for_each_dev+0x68/0xb4)
[<c057f71c>] (bus_for_each_dev) from [<c0580a1c>]
(bus_add_driver+0x1a8/0x268)
[<c0580a1c>] (bus_add_driver) from [<c0582e44>] (driver_register+0x78/0x10c)
[<c0582e44>] (driver_register) from [<c0103154>]
(do_one_initcall+0x8c/0x410)
[<c0103154>] (do_one_initcall) from [<c0f0124c>]
(kernel_init_freeable+0x3c8/0x4d0)
[<c0f0124c>] (kernel_init_freeable) from [<c0a6afd4>]
(kernel_init+0x8/0x10c)
[<c0a6afd4>] (kernel_init) from [<c01010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xd8cc1fb0 to 0xd8cc1ff8)
...
---[ end trace fed5502b2c7cd57c ]---


Rinato (arch/arm/boot/dts/exynos3250-rinato.dtb):

s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12
random: fast init done
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at drivers/gpio/gpiolib-devres.c:336
s2mps11_pmic_probe+0x1c4/0x49c
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted
4.20.0-rc5-next-20181203-00020-gf6d64d46ca8c #1156
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[<c01125fc>] (unwind_backtrace) from [<c010e140>] (show_stack+0x10/0x14)
[<c010e140>] (show_stack) from [<c0a510bc>] (dump_stack+0x98/0xc4)
[<c0a510bc>] (dump_stack) from [<c0127078>] (__warn+0x10c/0x124)
[<c0127078>] (__warn) from [<c01271a4>] (warn_slowpath_null+0x40/0x48)
[<c01271a4>] (warn_slowpath_null) from [<c04e5c94>]
(s2mps11_pmic_probe+0x1c4/0x49c)
[<c04e5c94>] (s2mps11_pmic_probe) from [<c0583e60>]
(platform_drv_probe+0x48/0x9c)
[<c0583e60>] (platform_drv_probe) from [<c0581858>]
(really_probe+0x274/0x400)
[<c0581858>] (really_probe) from [<c0581ba0>]
(driver_probe_device+0x78/0x1b8)
[<c0581ba0>] (driver_probe_device) from [<c0581e08>]
(__driver_attach+0x128/0x144)
[<c0581e08>] (__driver_attach) from [<c057f71c>]
(bus_for_each_dev+0x68/0xb4)
[<c057f71c>] (bus_for_each_dev) from [<c0580a1c>]
(bus_add_driver+0x1a8/0x268)
[<c0580a1c>] (bus_add_driver) from [<c0582e44>] (driver_register+0x78/0x10c)
[<c0582e44>] (driver_register) from [<c0103154>]
(do_one_initcall+0x8c/0x410)
[<c0103154>] (do_one_initcall) from [<c0f0124c>]
(kernel_init_freeable+0x3c8/0x4d0)
[<c0f0124c>] (kernel_init_freeable) from [<c0a6afd4>]
(kernel_init+0x8/0x10c)
[<c0a6afd4>] (kernel_init) from [<c01010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xd94c1fb0 to 0xd94c1ff8)
...
irq event stamp: 114729
hardirqs last  enabled at (114747): [<c0192e14>] console_unlock+0x4ac/0x698
hardirqs last disabled at (114764): [<c0192a34>] console_unlock+0xcc/0x698
softirqs last  enabled at (114762): [<c0102618>] __do_softirq+0x4f0/0x5e0
softirqs last disabled at (114781): [<c012f2f4>] irq_exit+0x160/0x16c
---[ end trace 5961f9fa5249019f ]---
Unable to handle kernel paging request at virtual address fffffff0
pgd = (ptrval)
[fffffff0] *pgd=5fece841, *pte=00000000, *ppte=00000000
Internal error: Oops: 27 [#1] PREEMPT SMP ARM
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Tainted: G        W        
4.20.0-rc5-next-20181203-00020-gf6d64d46ca8c #1156
Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
PC is at devm_gpiod_match+0x4/0x18
LR is at devres_remove+0x68/0xb8
...
Flags: NzCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 4000406a  DAC: 00000051
Process swapper/0 (pid: 1, stack limit = 0x(ptrval))
Stack: (0xd94c1d58 to 0xd94c2000)
...
[<c04a6f1c>] (devm_gpiod_match) from [<c05854b8>] (devres_remove+0x68/0xb8)
[<c05854b8>] (devres_remove) from [<c0585cdc>] (devres_destroy+0x8/0x24)
[<c0585cdc>] (devres_destroy) from [<c04a74a4>]
(devm_gpiod_unhinge+0x1c/0x38)
[<c04a74a4>] (devm_gpiod_unhinge) from [<c04e5c94>]
(s2mps11_pmic_probe+0x1c4/0x49c)
[<c04e5c94>] (s2mps11_pmic_probe) from [<c0583e60>]
(platform_drv_probe+0x48/0x9c)
[<c0583e60>] (platform_drv_probe) from [<c0581858>]
(really_probe+0x274/0x400)
[<c0581858>] (really_probe) from [<c0581ba0>]
(driver_probe_device+0x78/0x1b8)
[<c0581ba0>] (driver_probe_device) from [<c0581e08>]
(__driver_attach+0x128/0x144)
[<c0581e08>] (__driver_attach) from [<c057f71c>]
(bus_for_each_dev+0x68/0xb4)
[<c057f71c>] (bus_for_each_dev) from [<c0580a1c>]
(bus_add_driver+0x1a8/0x268)
[<c0580a1c>] (bus_add_driver) from [<c0582e44>] (driver_register+0x78/0x10c)
[<c0582e44>] (driver_register) from [<c0103154>]
(do_one_initcall+0x8c/0x410)
[<c0103154>] (do_one_initcall) from [<c0f0124c>]
(kernel_init_freeable+0x3c8/0x4d0)
[<c0f0124c>] (kernel_init_freeable) from [<c0a6afd4>]
(kernel_init+0x8/0x10c)
[<c0a6afd4>] (kernel_init) from [<c01010b4>] (ret_from_fork+0x14/0x20)
Exception stack(0xd94c1fb0 to 0xd94c1ff8)
...
---[ end trace 5961f9fa524901a0 ]---


Other boards with other variants of s2mps11 or other PMICs works fine.




>

> Linus Walleij (13):

>   regulator: core: Track dangling GPIO descriptors

>   regulator: fixed: Let core handle GPIO descriptor

>   regulator: lm363x: Let core handle GPIO descriptor

>   regulator: lp8788-ldo: Let core handle GPIO descriptor

>   regulator: max8952: Let core handle GPIO descriptor

>   regulator: max8973: Let core handle GPIO descriptor

>   gpio: Export gpiod_get_from_of_node()

>   regulator: max77686: Let core handle GPIO descriptor

>   gpio: Add devm_gpiod_unhinge()

>   regulator: da9211: Hand over GPIO to regulator core

>   regulator: s5m8767: Hand over GPIO to regulator core

>   regulator: tps65090: Hand over GPIO to regulator core

>   regulator: s2mps11: Hand over GPIO to regulator core

>

>  Documentation/driver-model/devres.txt  |  1 +

>  drivers/gpio/gpiolib-devres.c          | 17 ++++++++

>  drivers/gpio/gpiolib.h                 |  6 ---

>  drivers/regulator/core.c               | 55 +++++++++++++++++++++-----

>  drivers/regulator/da9211-regulator.c   |  6 +++

>  drivers/regulator/fixed.c              |  6 ++-

>  drivers/regulator/lm363x-regulator.c   |  8 +++-

>  drivers/regulator/lp8788-ldo.c         |  8 +++-

>  drivers/regulator/max77686-regulator.c | 14 ++++---

>  drivers/regulator/max8952.c            | 10 +++--

>  drivers/regulator/max8973-regulator.c  | 23 +++++++----

>  drivers/regulator/s2mps11.c            |  7 +++-

>  drivers/regulator/s5m8767.c            |  9 ++++-

>  drivers/regulator/tps65090-regulator.c |  6 +++

>  include/linux/gpio/consumer.h          | 23 +++++++++++

>  15 files changed, 161 insertions(+), 38 deletions(-)

>

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Linus Walleij Dec. 4, 2018, 9:31 a.m. UTC | #2
Hi Marek,

first, thanks a *lot* for testing this, it is is much, much appreciated!

On Mon, Dec 3, 2018 at 3:35 PM Marek Szyprowski
<m.szyprowski@samsung.com> wrote:

> The idea is good imho, but it looks that there are some missing cases in

> the code. Here are some logs from the boards I have access to:


OK let's fix this!

> Artik5 evaluation board (arch/arm/boot/dts/exynos3250-artik5-eval.dtb):

> s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12


Question: this is supposed to fail, right? It is something
like a probe deferral or nonexisting GPIO controller?

I look in the upstream tree:
arch/arm/boot/dts/exynos3250-artik5.dtsi
where s2mps14 is defined:

ldo12_reg: LDO12 {
    /* VDD72 ~ VDD73 */
    regulator-name = "VLDO12_2.8V";
    regulator-min-microvolt = <2800000>;
    regulator-max-microvolt = <2800000>;
    samsung,ext-control-gpios = <&gpk0 2 GPIO_ACTIVE_HIGH>;
};

I didn't really change anything about this, so this missing
GPIO descriptor looks worrysome.

Anyways what happens is this:

gpio[reg] = devm_gpiod_get_from_of_node(...)
if (IS_ERR(gpio[reg]))
(...)
            continue;

So this IS_ERR descriptor is left around. So we should
probably handle erronoeus or NULL descriptors in
gpiod_unhinge().

If you add this on top, does it start working?

diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c
index 5864e758d7f2..e35751bf0ea8 100644
--- a/drivers/gpio/gpiolib-devres.c
+++ b/drivers/gpio/gpiolib-devres.c
@@ -332,6 +332,8 @@ EXPORT_SYMBOL(devm_gpiod_put);

 void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc)
 {
+       if (IS_ERR_OR_NULL(desc))
+               return;
        WARN_ON(devres_destroy(dev, devm_gpiod_release,
                               devm_gpiod_match, desc));
 }

Yours,
Linus Walleij
Marek Szyprowski Dec. 4, 2018, 10:33 a.m. UTC | #3
Hi Linus,

On 2018-12-04 10:31, Linus Walleij wrote:
> Hi Marek,

>

> first, thanks a *lot* for testing this, it is is much, much appreciated!

>

> On Mon, Dec 3, 2018 at 3:35 PM Marek Szyprowski

> <m.szyprowski@samsung.com> wrote:

>

>> The idea is good imho, but it looks that there are some missing cases in

>> the code. Here are some logs from the boards I have access to:

> OK let's fix this!

>

>> Artik5 evaluation board (arch/arm/boot/dts/exynos3250-artik5-eval.dtb):

>> s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12

> Question: this is supposed to fail, right? It is something

> like a probe deferral or nonexisting GPIO controller?


It looks that the issue has been introduced earlier, but I didn't notice it.

gpiod_get_from_of_node() doesn't handle GPIOD_FLAGS_BIT_NONEXCLUSIVE
flag, the rest is just a result of it.


Here we have a case, where 2 regulators provided by s2mps11 driver have
a common gpio enable line (by PMIC design), so s2mps11 calls
devm_gpiod_get_from_of_node() 2 times for exactly the same gpio descriptor.


Fixing gpiod_get_from_of_node() for GPIOD_FLAGS_BIT_NONEXCLUSIVE is trivial:

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cd84315ad586..ace194665b19 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4192,6 +4192,8 @@ struct gpio_desc *gpiod_get_from_of_node(struct
device_node *node,
        transitory = flags & OF_GPIO_TRANSITORY;

        ret = gpiod_request(desc, label);
+       if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
+               return desc;
        if (ret)
                return ERR_PTR(ret);


With the above fix I still however get 2 warnings from devres functions,
but this is probably caused by adding the same entry 2 times to the list
without proper refcounting... I will check that later.


> I look in the upstream tree:

> arch/arm/boot/dts/exynos3250-artik5.dtsi

> where s2mps14 is defined:

>

> ldo12_reg: LDO12 {

>     /* VDD72 ~ VDD73 */

>     regulator-name = "VLDO12_2.8V";

>     regulator-min-microvolt = <2800000>;

>     regulator-max-microvolt = <2800000>;

>     samsung,ext-control-gpios = <&gpk0 2 GPIO_ACTIVE_HIGH>;

> };

>

> I didn't really change anything about this, so this missing

> GPIO descriptor looks worrysome.

>

> Anyways what happens is this:

>

> gpio[reg] = devm_gpiod_get_from_of_node(...)

> if (IS_ERR(gpio[reg]))

> (...)

>             continue;

>

> So this IS_ERR descriptor is left around. So we should

> probably handle erronoeus or NULL descriptors in

> gpiod_unhinge().

>

> If you add this on top, does it start working?

>

> diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c

> index 5864e758d7f2..e35751bf0ea8 100644

> --- a/drivers/gpio/gpiolib-devres.c

> +++ b/drivers/gpio/gpiolib-devres.c

> @@ -332,6 +332,8 @@ EXPORT_SYMBOL(devm_gpiod_put);

>

>  void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc)

>  {

> +       if (IS_ERR_OR_NULL(desc))

> +               return;

>         WARN_ON(devres_destroy(dev, devm_gpiod_release,

>                                devm_gpiod_match, desc));

>  }

>

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Linus Walleij Dec. 4, 2018, 12:44 p.m. UTC | #4
On Tue, Dec 4, 2018 at 11:33 AM Marek Szyprowski
<m.szyprowski@samsung.com> wrote:

> >> Artik5 evaluation board (arch/arm/boot/dts/exynos3250-artik5-eval.dtb):

> >> s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12

> > Question: this is supposed to fail, right? It is something

> > like a probe deferral or nonexisting GPIO controller?

>

> It looks that the issue has been introduced earlier, but I didn't notice it.


Sorry :(

> gpiod_get_from_of_node() doesn't handle GPIOD_FLAGS_BIT_NONEXCLUSIVE

> flag, the rest is just a result of it.


OK I see.

> Here we have a case, where 2 regulators provided by s2mps11 driver have

> a common gpio enable line (by PMIC design), so s2mps11 calls

> devm_gpiod_get_from_of_node() 2 times for exactly the same gpio descriptor.

>

> Fixing gpiod_get_from_of_node() for GPIOD_FLAGS_BIT_NONEXCLUSIVE is trivial:


I will add a patch like this to the series!

> With the above fix I still however get 2 warnings from devres functions,

> but this is probably caused by adding the same entry 2 times to the list

> without proper refcounting... I will check that later.


Ah I see this regulator driver really excercise all corner cases of
these nonexclusive GPIO lines. (Which is good!)

Indeed devres is not going to like adding the same thing twice.

I just sent a fix for that, subject:
"gpio: devres: Handle nonexclusive GPIOs"
you could perhaps try it on top of this
series? I intend to merge that separately as a fix for current,
as it is a bug.

Yours,
Linus Walleij
Marek Szyprowski Dec. 5, 2018, 2:30 p.m. UTC | #5
Hi Linus,

On 2018-12-04 13:44, Linus Walleij wrote:
> On Tue, Dec 4, 2018 at 11:33 AM Marek Szyprowski

> <m.szyprowski@samsung.com> wrote:

>

>>>> Artik5 evaluation board (arch/arm/boot/dts/exynos3250-artik5-eval.dtb):

>>>> s2mps11-pmic s2mps14-regulator: Failed to get control GPIO for 11/LDO12

>>> Question: this is supposed to fail, right? It is something

>>> like a probe deferral or nonexisting GPIO controller?

>> It looks that the issue has been introduced earlier, but I didn't notice it.

> Sorry :(

>

>> gpiod_get_from_of_node() doesn't handle GPIOD_FLAGS_BIT_NONEXCLUSIVE

>> flag, the rest is just a result of it.

> OK I see.

>

>> Here we have a case, where 2 regulators provided by s2mps11 driver have

>> a common gpio enable line (by PMIC design), so s2mps11 calls

>> devm_gpiod_get_from_of_node() 2 times for exactly the same gpio descriptor.

>>

>> Fixing gpiod_get_from_of_node() for GPIOD_FLAGS_BIT_NONEXCLUSIVE is trivial:

> I will add a patch like this to the series!

>

>> With the above fix I still however get 2 warnings from devres functions,

>> but this is probably caused by adding the same entry 2 times to the list

>> without proper refcounting... I will check that later.

> Ah I see this regulator driver really excercise all corner cases of

> these nonexclusive GPIO lines. (Which is good!)

>

> Indeed devres is not going to like adding the same thing twice.

>

> I just sent a fix for that, subject:

> "gpio: devres: Handle nonexclusive GPIOs"

> you could perhaps try it on top of this

> series? I intend to merge that separately as a fix for current,

> as it is a bug.


Those 2 warnings were worrying me and I finally found! devres_*
functions require to pass a pointer to the pointer as match_data, so
desc must be passed as &desc to devres_find() and devres_destroy()
functions, otherwise they always return -ENOENT. I will comment
respective lines in your patches then.


Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Linus Walleij Dec. 5, 2018, 2:32 p.m. UTC | #6
On Wed, Dec 5, 2018 at 3:30 PM Marek Szyprowski
<m.szyprowski@samsung.com> wrote:

> > I just sent a fix for that, subject:

> > "gpio: devres: Handle nonexclusive GPIOs"

> > you could perhaps try it on top of this

> > series? I intend to merge that separately as a fix for current,

> > as it is a bug.

>

> Those 2 warnings were worrying me and I finally found! devres_*

> functions require to pass a pointer to the pointer as match_data, so

> desc must be passed as &desc to devres_find() and devres_destroy()

> functions, otherwise they always return -ENOENT. I will comment

> respective lines in your patches then.


Ah thanks so much Marek!

I will follow up with a v4 patch set immediately once I have it nailed
down. Devres is tricky, and I'm not the smartest...

Yours,
Linus Walleij