Skip to contentSkip to conversation

platform/x86: x86-android-tablets: fix gpio_secondary_fwnode_init() not working

PATCH Applied Hans de Goede 4 participants 8 messages Aug 31 – Sep 9 1 message not in the archive

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Fixes 1448c2d2ca5c ("platform/x86: x86-android-tablets: enable fwnode matching of GPIO chips")
---
 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
index b028af1c9942..1706287fd136 100644
@@ -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
#1 lore raw
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")
---
 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
index b028af1c9942..1706287fd136 100644
@@ -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 -0
 		if (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
#2 lore raw

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")
---
 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
index b028af1c9942..1706287fd136 100644
@@ -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

Reviewed-by
#3 lore raw
Quoted 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")
---
 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
index b028af1c9942..1706287fd136 100644
@@ -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_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.

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]

maintainer
#5 lore raw
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 -1
 		if (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.
#6 lore raw

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 -1
 		if (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).

maintainer Applied
#7 lore raw
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 -1
 		if (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.
#8 lore raw
In reply to Hans de Goede
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