* [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match
@ 2024-05-13 7:59 Devyn Liu
2024-05-13 9:25 ` Andy Shevchenko
2024-05-20 4:37 ` Mika Westerberg
0 siblings, 2 replies; 5+ messages in thread
From: Devyn Liu @ 2024-05-13 7:59 UTC (permalink / raw)
To: linus.walleij, brgl
Cc: f.fangjian, linux-gpio, linux-kernel, mika.westerberg,
andriy.shevchenko, linux-acpi, jonathan.cameron, yangyicong,
yisen.zhuang, kong.kongxinwei, liudingyuan
Previous patch modified the standard used by acpi_gpiochip_find()
to match device nodes. Using the device node set in gc->gpiodev->d-
ev instead of gc->parent.
However, there is a situation in gpio-dwapb where the GPIO device
driver will set gc->fwnode for each port corresponding to a child
node under a GPIO device, so gc->gpiodev->dev will be assigned the
value of each child node in gpiochip_add_data().
gpio-dwapb.c:
128,31 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
struct dwapb_port_property *pp,
unsigned int offs);
port->gc.fwnode = pp->fwnode;
693,39 static int dwapb_gpio_probe;
err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
When other drivers request GPIO pin resources through the GPIO device
node provided by ACPI (corresponding to the parent node), the change
of the matching object to gc->gpiodev->dev in acpi_gpiochip_find()
only allows finding the value of each port (child node), resulting
in a failed request.
Reapply the condition of using gc->parent for match in acpi_gpio-
chip_find() in the code can compatible with the problem of gpio-dwapb,
and will not affect the two cases mentioned in the patch:
1. There is no setting for gc->fwnode.
2. The case that depends on using gc->fwnode for match.
Fixes: 5062e4c14b75 ("gpiolib: acpi: use the fwnode in acpi_gpiochip_find()")
Fixes: 067dbc1ea5ce ("gpiolib: acpi: Don't use GPIO chip fwnode in acpi_gpiochip_find()")
Signed-off-by: Devyn Liu <liudingyuan@huawei.com>
---
drivers/gpio/gpiolib-acpi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 7f140df40f35..6078fea3e021 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -128,7 +128,8 @@ static bool acpi_gpio_deferred_req_irqs_done;
static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
{
- return device_match_acpi_handle(&gc->gpiodev->dev, data);
+ return device_match_acpi_handle(&gc->gpiodev->dev, data) ||
+ (gc->parent && device_match_acpi_handle(gc->parent, data));
}
/**
--
2.30.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match
2024-05-13 7:59 [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match Devyn Liu
@ 2024-05-13 9:25 ` Andy Shevchenko
2024-05-13 15:43 ` Benjamin Tissoires
2024-05-20 4:37 ` Mika Westerberg
1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-05-13 9:25 UTC (permalink / raw)
To: Devyn Liu, Benjamin Tissoires
Cc: linus.walleij, brgl, f.fangjian, linux-gpio, linux-kernel,
mika.westerberg, linux-acpi, jonathan.cameron, yangyicong,
yisen.zhuang, kong.kongxinwei
On Mon, May 13, 2024 at 03:59:01PM +0800, Devyn Liu wrote:
> Previous patch modified the standard used by acpi_gpiochip_find()
> to match device nodes. Using the device node set in gc->gpiodev->d-
> ev instead of gc->parent.
>
> However, there is a situation in gpio-dwapb where the GPIO device
> driver will set gc->fwnode for each port corresponding to a child
> node under a GPIO device, so gc->gpiodev->dev will be assigned the
> value of each child node in gpiochip_add_data().
>
> gpio-dwapb.c:
> 128,31 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
> struct dwapb_port_property *pp,
> unsigned int offs);
> port->gc.fwnode = pp->fwnode;
>
> 693,39 static int dwapb_gpio_probe;
> err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
>
> When other drivers request GPIO pin resources through the GPIO device
> node provided by ACPI (corresponding to the parent node), the change
> of the matching object to gc->gpiodev->dev in acpi_gpiochip_find()
> only allows finding the value of each port (child node), resulting
> in a failed request.
>
> Reapply the condition of using gc->parent for match in acpi_gpio-
> chip_find() in the code can compatible with the problem of gpio-dwapb,
> and will not affect the two cases mentioned in the patch:
> 1. There is no setting for gc->fwnode.
> 2. The case that depends on using gc->fwnode for match.
Thanks for the report, analysis, and patch.
...
> static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
> {
> - return device_match_acpi_handle(&gc->gpiodev->dev, data);
> + return device_match_acpi_handle(&gc->gpiodev->dev, data) ||
> + (gc->parent && device_match_acpi_handle(gc->parent, data));
> }
I'm wondering if the below approach will work for all:
static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
{
struct device *dev = acpi_get_first_physical_node(ACPI_COMPANION(&gc->gpiodev->dev));
return device_match_acpi_handle(dev, data);
}
Cc'ing to Benjamin for testing and commenting.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match
2024-05-13 9:25 ` Andy Shevchenko
@ 2024-05-13 15:43 ` Benjamin Tissoires
0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Tissoires @ 2024-05-13 15:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Devyn Liu, linus.walleij, brgl, f.fangjian, linux-gpio,
linux-kernel, mika.westerberg, linux-acpi, jonathan.cameron,
yangyicong, yisen.zhuang, kong.kongxinwei
On May 13 2024, Andy Shevchenko wrote:
> On Mon, May 13, 2024 at 03:59:01PM +0800, Devyn Liu wrote:
> > Previous patch modified the standard used by acpi_gpiochip_find()
> > to match device nodes. Using the device node set in gc->gpiodev->d-
> > ev instead of gc->parent.
> >
> > However, there is a situation in gpio-dwapb where the GPIO device
> > driver will set gc->fwnode for each port corresponding to a child
> > node under a GPIO device, so gc->gpiodev->dev will be assigned the
> > value of each child node in gpiochip_add_data().
> >
> > gpio-dwapb.c:
> > 128,31 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
> > struct dwapb_port_property *pp,
> > unsigned int offs);
> > port->gc.fwnode = pp->fwnode;
> >
> > 693,39 static int dwapb_gpio_probe;
> > err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
> >
> > When other drivers request GPIO pin resources through the GPIO device
> > node provided by ACPI (corresponding to the parent node), the change
> > of the matching object to gc->gpiodev->dev in acpi_gpiochip_find()
> > only allows finding the value of each port (child node), resulting
> > in a failed request.
> >
> > Reapply the condition of using gc->parent for match in acpi_gpio-
> > chip_find() in the code can compatible with the problem of gpio-dwapb,
> > and will not affect the two cases mentioned in the patch:
> > 1. There is no setting for gc->fwnode.
> > 2. The case that depends on using gc->fwnode for match.
>
> Thanks for the report, analysis, and patch.
>
> ...
>
> > static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
> > {
> > - return device_match_acpi_handle(&gc->gpiodev->dev, data);
> > + return device_match_acpi_handle(&gc->gpiodev->dev, data) ||
> > + (gc->parent && device_match_acpi_handle(gc->parent, data));
> > }
The original patch (from Devyn) is:
Tested-by: Benjamin Tissoires <bentiss@kernel.org>
For reference, a successful run can be seen at:
https://gitlab.freedesktop.org/bentiss/hid/-/jobs/58661693
>
> I'm wondering if the below approach will work for all:
>
> static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
> {
> struct device *dev = acpi_get_first_physical_node(ACPI_COMPANION(&gc->gpiodev->dev));
>
> return device_match_acpi_handle(dev, data);
> }
Looks like I get a bad dev pointer in this situation:
https://gitlab.freedesktop.org/bentiss/hid/-/jobs/58662689#L704
Not sure if this is because the not-yet-upstream patches I have in
hid-cp2112 are doing something wrong or if there is a good reason for
it...
The patch that adds fwnode to hid-cp2112 are:
https://gitlab.freedesktop.org/bentiss/gitlab-kernel-ci/-/blob/master/VM/0002-HID-usbhid-Share-USB-device-firmware-node-with-child.patch
https://gitlab.freedesktop.org/bentiss/gitlab-kernel-ci/-/blob/master/VM/0003-HID-cp2112-Fwnode-Support.patch
both of those patches are applied before compilation in the CI run from
above.
>
> Cc'ing to Benjamin for testing and commenting.
TL;DR: initial patch is fine, yours will probably need a check on the
dev return value, so not sure if we gain a lot...
Cheers,
Benjamin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match
2024-05-13 7:59 [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match Devyn Liu
2024-05-13 9:25 ` Andy Shevchenko
@ 2024-05-20 4:37 ` Mika Westerberg
2024-05-21 15:47 ` Andy Shevchenko
1 sibling, 1 reply; 5+ messages in thread
From: Mika Westerberg @ 2024-05-20 4:37 UTC (permalink / raw)
To: Devyn Liu
Cc: linus.walleij, brgl, f.fangjian, linux-gpio, linux-kernel,
andriy.shevchenko, linux-acpi, jonathan.cameron, yangyicong,
yisen.zhuang, kong.kongxinwei
On Mon, May 13, 2024 at 03:59:01PM +0800, Devyn Liu wrote:
> Previous patch modified the standard used by acpi_gpiochip_find()
> to match device nodes. Using the device node set in gc->gpiodev->d-
> ev instead of gc->parent.
>
> However, there is a situation in gpio-dwapb where the GPIO device
> driver will set gc->fwnode for each port corresponding to a child
> node under a GPIO device, so gc->gpiodev->dev will be assigned the
> value of each child node in gpiochip_add_data().
>
> gpio-dwapb.c:
> 128,31 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
> struct dwapb_port_property *pp,
> unsigned int offs);
> port->gc.fwnode = pp->fwnode;
>
> 693,39 static int dwapb_gpio_probe;
> err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
>
> When other drivers request GPIO pin resources through the GPIO device
> node provided by ACPI (corresponding to the parent node), the change
> of the matching object to gc->gpiodev->dev in acpi_gpiochip_find()
> only allows finding the value of each port (child node), resulting
> in a failed request.
>
> Reapply the condition of using gc->parent for match in acpi_gpio-
> chip_find() in the code can compatible with the problem of gpio-dwapb,
> and will not affect the two cases mentioned in the patch:
> 1. There is no setting for gc->fwnode.
> 2. The case that depends on using gc->fwnode for match.
>
> Fixes: 5062e4c14b75 ("gpiolib: acpi: use the fwnode in acpi_gpiochip_find()")
> Fixes: 067dbc1ea5ce ("gpiolib: acpi: Don't use GPIO chip fwnode in acpi_gpiochip_find()")
> Signed-off-by: Devyn Liu <liudingyuan@huawei.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match
2024-05-20 4:37 ` Mika Westerberg
@ 2024-05-21 15:47 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-05-21 15:47 UTC (permalink / raw)
To: Mika Westerberg
Cc: Devyn Liu, linus.walleij, brgl, f.fangjian, linux-gpio,
linux-kernel, linux-acpi, jonathan.cameron, yangyicong,
yisen.zhuang, kong.kongxinwei
On Mon, May 20, 2024 at 07:37:49AM +0300, Mika Westerberg wrote:
> On Mon, May 13, 2024 at 03:59:01PM +0800, Devyn Liu wrote:
> > Previous patch modified the standard used by acpi_gpiochip_find()
> > to match device nodes. Using the device node set in gc->gpiodev->d-
> > ev instead of gc->parent.
> >
> > However, there is a situation in gpio-dwapb where the GPIO device
> > driver will set gc->fwnode for each port corresponding to a child
> > node under a GPIO device, so gc->gpiodev->dev will be assigned the
> > value of each child node in gpiochip_add_data().
> >
> > gpio-dwapb.c:
> > 128,31 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio,
> > struct dwapb_port_property *pp,
> > unsigned int offs);
> > port->gc.fwnode = pp->fwnode;
> >
> > 693,39 static int dwapb_gpio_probe;
> > err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
> >
> > When other drivers request GPIO pin resources through the GPIO device
> > node provided by ACPI (corresponding to the parent node), the change
> > of the matching object to gc->gpiodev->dev in acpi_gpiochip_find()
> > only allows finding the value of each port (child node), resulting
> > in a failed request.
> >
> > Reapply the condition of using gc->parent for match in acpi_gpio-
> > chip_find() in the code can compatible with the problem of gpio-dwapb,
> > and will not affect the two cases mentioned in the patch:
> > 1. There is no setting for gc->fwnode.
> > 2. The case that depends on using gc->fwnode for match.
> >
> > Fixes: 5062e4c14b75 ("gpiolib: acpi: use the fwnode in acpi_gpiochip_find()")
> > Fixes: 067dbc1ea5ce ("gpiolib: acpi: Don't use GPIO chip fwnode in acpi_gpiochip_find()")
> > Signed-off-by: Devyn Liu <liudingyuan@huawei.com>
>
> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Pushed to my review and testing queue, thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-21 15:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-13 7:59 [PATCH] gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match Devyn Liu
2024-05-13 9:25 ` Andy Shevchenko
2024-05-13 15:43 ` Benjamin Tissoires
2024-05-20 4:37 ` Mika Westerberg
2024-05-21 15:47 ` 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).