platform/x86: x86-android-tablets: fix gpio_secondary_fwnode_init() not working
PATCH 1/1 platform/x86: x86-android-tablets: fix gpio_secondary_fwnode_init() not working
acpi_bus_find_device_by_name() call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init() then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).
This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify gpio_secondary_fwnode_init() to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.
This fixes the GPIO lookups not working.
--- drivers/platform/x86/x86-android-tablets/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/x86-android-tablets/core.c +8 -2
@@ -417,9 +417,15 @@ static int gpio_secondary_fwnode_init(struct device *parent,if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode); +struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev)); +if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name); - ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (dev)); +set_secondary_fwnode (phys_dev, fwnode); + + ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (phys_dev));if (ret)return ret; }
Signature · 1 line
2.55.0
Quoted 7 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).
Quoted 6 lines
This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
Nice find, thank you!
Quoted 16 lines
Fixes 1448c2d2ca5c ("platform/x86: x86-android-tablets: enable fwnode matching of GPIO chips")Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/x86-android-tablets/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +0
-1@@ -417,9 +417,15 @@ static int gpio_secondary_fwnode_init(struct device *parent,if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode);
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 428
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +8
-1+struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev)); +if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name); - ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (dev)); +set_secondary_fwnode (phys_dev, fwnode); + + ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (phys_dev));
I am surprised that acpi_get_first_physical_node() does not bump up refcount of the device...
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 430
Quoted 2 lines
drivers/platform/x86/x86-android-tablets/core.c +0
-0if (ret)return ret;
This leaks refcount on error though...
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 431
Quoted 1 line
drivers/platform/x86/x86-android-tablets/core.c +0
-0}
Thanks.
Signature · 1 line
Dmitry
Hi,
Quoted 46 lines · Dmitry Torokhov
Quoted 7 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).Quoted 6 lines
This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
Nice find, thank you!
Quoted 16 lines
Fixes 1448c2d2ca5c ("platform/x86: x86-android-tablets: enable fwnode matching of GPIO chips")Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/x86-android-tablets/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +0
-1@@ -417,9 +417,15 @@ static int gpio_secondary_fwnode_init(struct device *parent,if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode);drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 428
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +8
-1+struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev)); +if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name); - ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (dev)); +set_secondary_fwnode (phys_dev, fwnode); + + ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (phys_dev));I am surprised that
acpi_get_first_physical_node()does not bump up refcount of the device...
Quoted 4 lines
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 430
Quoted 2 lines
drivers/platform/x86/x86-android-tablets/core.c +0
-0> if (ret)return ret;This leaks refcount on error though...
The or_reset part of devm_add_action_or_reset() will call gpio_secondary_unset on failure which puts the ref we take here on phys_dev.
And the original reference on the ACPI bus device returned by acpi_bus_find_device_by_name() us auto-free-ed since dev is declared as:
struct device *dev __free(put_device) = ...
or am I missing something here ?
(also note the refcounting is not changed, this just exchanges dev with phys_dev)
Regards,
Hans
Dmitry Torokhov
Reviewed-byQuoted 49 lines · Hans de Goede
Hi,
Quoted 46 lines · Dmitry Torokhov
Quoted 7 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).Quoted 6 lines
This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
Nice find, thank you!
Quoted 16 lines
Fixes 1448c2d2ca5c ("platform/x86: x86-android-tablets: enable fwnode matching of GPIO chips")Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/x86-android-tablets/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/platform/x86/x86-android-tablets/core.c +0
-1@@ -417,9 +417,15 @@ static int gpio_secondary_fwnode_init(struct device *parent,if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode);drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 428
Quoted 10 lines
drivers/platform/x86/x86-android-tablets/core.c +8
-1+struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev)); +if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name); - ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (dev)); +set_secondary_fwnode (phys_dev, fwnode); + + ret =devm_add_action_or_reset (parent, gpio_secondary_unset,get_device (phys_dev));I am surprised that
acpi_get_first_physical_node()does not bump up refcount of the device...
Quoted 7 lines
Quoted 4 lines
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 430
Quoted 2 lines
drivers/platform/x86/x86-android-tablets/core.c +0
-0> if (ret)return ret;This leaks refcount on error though...
The
or_resetpart ofdevm_add_action_or_reset()will callgpio_secondary_unseton failure which puts the ref we take here onphys_dev.
Ah, yes, you are right. Sorry for the noise.
Thanks.
Signature · 1 line
Dmitry
A message that is not in the archive (sent off-list or not yet received): [email protected]
Ilpo Järvinen
maintainerQuoted 28 lines · Andy Shevchenko
Quoted 13 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
...
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 420
Quoted 7 lines
static int gpio_secondary_fwnode_init(struct device *parent,
drivers/platform/x86/x86-android-tablets/core.c +1
-1if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode); +struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev));It doesn't look like an auto cleaning pointer, so let's make a declaration outside of the code?
Quoted 6 lines
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 424
Quoted 4 lines
drivers/platform/x86/x86-android-tablets/core.c +4
-0+if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name);Hmm... Why not %pfwP?
Hi Hans,
I'm waiting for v2.
Signature · 1 line
i.
Hi Ilpo,
Quoted 37 lines · Ilpo Järvinen
Quoted 28 lines · Andy Shevchenko
Quoted 13 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
...
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 420
Quoted 7 lines
static int gpio_secondary_fwnode_init(struct device *parent,
drivers/platform/x86/x86-android-tablets/core.c +1
-1if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode); +struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev));It doesn't look like an auto cleaning pointer, so let's make a declaration outside of the code?
Quoted 6 lines
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 424
Quoted 4 lines
drivers/platform/x86/x86-android-tablets/core.c +4
-0+if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name);Hmm... Why not %pfwP?
Quoted 3 lines
Hi Hans,
I'm waiting for v2.
I see, thank you for quoting Andy's email since it never made the list (1), nor did it reach me.
I'll prepare a v2 addressing Andy's remarks.
Regards,
Hans
1) If you go to:
https://lore.kernel.org/platform-driver-x86/[email protected]/#r
it shows a "not found" <[email protected]> entry, which it only knows about because of this reply to it by you (Ilpo).
Quoted 55 lines · Hans de Goede
Hi Ilpo,
Quoted 37 lines · Ilpo Järvinen
Quoted 28 lines · Andy Shevchenko
Quoted 13 lines · Hans de Goede
acpi_bus_find_device_by_name()call returns a pointer to the device object on the ACPI bus, aka the ACPI companion device.
gpio_secondary_fwnode_init()then continues with setting the secondary fwnode on this device. But this is not the actual physical device for the GPIO controller (e.g. the GPIO controller platform bus device).This mismatch is causing GPIO lookups by secondary fwnode to not work.
Modify
gpio_secondary_fwnode_init()to instead set the secondary fwnode of the first physical device associated with the ACPI companion device.This fixes the GPIO lookups not working.
...
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 420
Quoted 7 lines
static int gpio_secondary_fwnode_init(struct device *parent,
drivers/platform/x86/x86-android-tablets/core.c +1
-1if (WARN_ON (!fwnode))return -ENOENT ; -set_secondary_fwnode (dev, fwnode); +struct device *phys_dev =acpi_get_first_physical_node (to_acpi_device (dev));It doesn't look like an auto cleaning pointer, so let's make a declaration outside of the code?
Quoted 6 lines
drivers/platform/x86/x86-android-tablets/core.c static int gpio_secondary_fwnode_init(struct device *parent, · line 424
Quoted 4 lines
drivers/platform/x86/x86-android-tablets/core.c +4
-0+if (!phys_dev) +return dev_err_probe (parent, + -ENODEV ,"No physical device for ACPI GPIO dev: %s\n" , + (*swnode)->name);Hmm... Why not %pfwP?
Quoted 3 lines
Hi Hans,
I'm waiting for v2.
I see, thank you for quoting Andy's email since it never made the list (1), nor did it reach me.
I'll prepare a v2 addressing Andy's remarks.
Regards,
Hans
Quoted 6 lines
1) If you go to:
https://lore.kernel.org/platform-driver-x86/[email protected]/#r
it shows a "not found" <[email protected]> entry, which it only knows about because of this reply to it by you (Ilpo).
Yeah, I noticed it didn't end up into patchwork either but figured you'd see the content from my reply if the original had failed to reach you.
I've applied v2 now, thanks.
Signature · 1 line
i.
Quoted 1 line · Hans de Goede
On 3-Sep-26 13:54, Ilpo Järvinen wrote:
...
Quoted 2 lines
I see, thank you for quoting Andy's email since it never made the list (1), nor did it reach me.
Oh, it was not intended to be not public. Thanks, Ilpo, for sharing the content.
Quoted 1 line
I'll prepare a v2 addressing Andy's remarks.
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko