Skip to contentSkip to conversation

Add and use new helper acpi_use_parent_companion

PATCH Applied Heiner Kallweit 6 participants 16 messages Oct 15, 2023 – Oct 28, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add and use new helper acpi_use_parent_companion

In several drivers devices use the ACPI companion of the parent. Add a helper for this use case to avoid code duplication.

Heiner Kallweit (2):
ACPI: Add helper acpi_use_parent_companion
i2c: i801: Use new helper acpi_use_parent_companion

 drivers/i2c/busses/i2c-i801.c | 2 +-
 include/linux/acpi.h          | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/2 ACPI: Add helper acpi_use_parent_companion

In several drivers devices use the ACPI companion of the parent. Add a helper for this use case to avoid code duplication.

---
 include/linux/acpi.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/acpi.h +5 -0
index ba3f601b6..89efb1658 100644
@@ -1541,4 +1541,9 @@ static inline void acpi_device_notify(struct device *dev) { }
 static inline void acpi_device_notify_remove(struct device *dev) { }
 #endif
 
+static inline void acpi_use_parent_companion(struct device *dev)
+{
+	ACPI_COMPANION_SET(dev, ACPI_COMPANION(dev->parent));
+}
+
 #endif	/*_LINUX_ACPI_H*/
Signature · 1 line
2.42.0
#2 lore raw

PATCH 2/2 i2c: i801: Use new helper acpi_use_parent_companion

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +1 -1
index a41f5349a..ac223146c 100644
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	priv->adapter.class = I2C_CLASS_HWMON;
 	priv->adapter.algo = &smbus_algorithm;
 	priv->adapter.dev.parent = &dev->dev;
-	ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+	acpi_use_parent_companion(&priv->adapter.dev);
 	priv->adapter.retries = 3;
 
 	priv->pci_dev = dev;
Signature · 1 line
2.42.0
#3 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

Hi,

Quoted 12 lines · Heiner Kallweit

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index a41f5349a..ac223146c 100644

drivers/i2c/busses/i2c-i801.c static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 1623

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	priv->adapter.class = I2C_CLASS_HWMON;
 	priv->adapter.algo = &smbus_algorithm;
 	priv->adapter.dev.parent = &dev->dev;
-	ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+	acpi_use_parent_companion(&priv->adapter.dev);

I think this case is a bit too trivial for a helper, it's one line before, and one line after, so it doesn't really save much.

Quoted 3 lines
drivers/i2c/busses/i2c-i801.c +0 -0
 	priv->adapter.retries = 3;
 
 	priv->pci_dev = dev;
#4 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

Quoted 11 lines · Michal

Hi,

Quoted 7 lines · Heiner Kallweit

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/i2c/busses/i2c-i801.c static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 1623

Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +1 -1
index a41f5349a..ac223146c 100644
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
      priv->adapter.class = I2C_CLASS_HWMON;
      priv->adapter.algo = &smbus_algorithm;
      priv->adapter.dev.parent = &dev->dev;
-     ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+     acpi_use_parent_companion(&priv->adapter.dev);

I think this case is a bit too trivial for a helper, it's one line before, and one line after, so it doesn't really save much.

If this pattern is repeated in multiple places, the helper makes sense IMO.

Quoted 5 lines
Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +0 -0
      priv->adapter.retries = 3;
 
      priv->pci_dev = dev;
#5 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

Quoted 27 lines · Rafael J. Wysocki
Quoted 11 lines · Michal

Hi,

Quoted 7 lines · Heiner Kallweit

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/i2c/busses/i2c-i801.c static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 1623

Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +1 -1
index a41f5349a..ac223146c 100644
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
      priv->adapter.class = I2C_CLASS_HWMON;
      priv->adapter.algo = &smbus_algorithm;
      priv->adapter.dev.parent = &dev->dev;
-     ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+     acpi_use_parent_companion(&priv->adapter.dev);

I think this case is a bit too trivial for a helper, it's one line before, and one line after, so it doesn't really save much.

Quoted 2 lines

If this pattern is repeated in multiple places, the helper makes sense IMO.

I didn't check each usage in detail, but this should be the places where the new helper can be used.
Another advantage IMO is that the helper, being a function instead of a macro, is type-safe.

drivers/usb/common/ulpi.c:      ACPI_COMPANION_SET(&ulpi->dev, ACPI_COMPANION(dev));
drivers/usb/dwc3/dwc3-pci.c:    ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
drivers/usb/core/message.c:             ACPI_COMPANION_SET(&intf->dev, ACPI_COMPANION(&dev->dev));
drivers/tty/serial/8250/8250_exar.c:    ACPI_COMPANION_SET(&pdev->dev, ACPI_COMPANION(&pcidev->dev));
drivers/i2c/busses/i2c-imx.c:   ACPI_COMPANION_SET(&i2c_imx->adapter.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-kempld.c:        ACPI_COMPANION_SET(&i2c->adap.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-virtio.c:        ACPI_COMPANION_SET(&vi->adap.dev, ACPI_COMPANION(vdev->dev.parent));
drivers/i2c/busses/i2c-dln2.c:  ACPI_COMPANION_SET(&dln2->adapter.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-i801.c:     ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
drivers/i2c/busses/i2c-ismt.c:  ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&pdev->dev));

drivers/i2c/busses/i2c-cros-ec-tunnel.c: ACPI_COMPANION_SET(&bus->adap.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-synquacer.c: ACPI_COMPANION_SET(&i2c->adapter.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-designware-pcidrv.c: ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-qup.c: ACPI_COMPANION_SET(&qup->adap.dev, ACPI_COMPANION(qup->dev));
drivers/i2c/busses/i2c-designware-platdrv.c: ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-qcom-geni.c: ACPI_COMPANION_SET(&gi2c->adap.dev, ACPI_COMPANION(dev));
drivers/i2c/busses/i2c-amd-mp2-plat.c: ACPI_COMPANION_SET(&i2c_dev->adap.dev, ACPI_COMPANION(&pdev->dev)); drivers/i2c/busses/i2c-xgene-slimpro.c: ACPI_COMPANION_SET(&adapter->dev, ACPI_COMPANION(&pdev->dev)); drivers/i2c/busses/i2c-tegra.c: ACPI_COMPANION_SET(&i2c_dev->adapter.dev, ACPI_COMPANION(&pdev->dev));
drivers/i2c/busses/i2c-xlp9xx.c: ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&pdev->dev));

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +0 -0
      priv->adapter.retries = 3;
 
      priv->pci_dev = dev;
#6 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

Hi Heiner and all,

Quoted 11 lines · Heiner Kallweit
Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · Michal
Quoted 7 lines · Heiner Kallweit

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +0 -0
index a41f5349a..ac223146c 100644
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
Quoted 8 lines
Quoted 8 lines

drivers/i2c/busses/i2c-i801.c static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 1623

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
      priv->adapter.class = I2C_CLASS_HWMON;
      priv->adapter.algo = &smbus_algorithm;
      priv->adapter.dev.parent = &dev->dev;
-     ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+     acpi_use_parent_companion(&priv->adapter.dev);  

I think this case is a bit too trivial for a helper, it's one line before, and one line after, so it doesn't really save much.

I must say I share Michal's skepticism.

Quoted 6 lines
Quoted 1 line

If this pattern is repeated in multiple places, the helper makes sense IMO.

I didn't check each usage in detail, but this should be the places where the new helper can be used.
Another advantage IMO is that the helper, being a function instead of a macro, is type-safe.

If type safety is a concern then I'd rather turn ACPI_COMPANION_SET to an inline function (which would make more sense than a macro anyway IMHO, as it has an intended side effect).

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#7 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I think this case is a bit too trivial for a helper, it's one line before, and one line after, so it doesn't really save much.

I must say I share Michal's skepticism.

Because Rafael likes it, I will pick it up.

Quoted 10 lines
Quoted 6 lines
Quoted 1 line

If this pattern is repeated in multiple places, the helper makes sense IMO.

I didn't check each usage in detail, but this should be the places where the new helper can be used.
Another advantage IMO is that the helper, being a function instead of a macro, is type-safe.

If type safety is a concern then I'd rather turn ACPI_COMPANION_SET to an inline function (which would make more sense than a macro anyway IMHO, as it has an intended side effect).

I guess this can still be done seperately?

maintainer Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion

In reply to Heiner Kallweit

Hi Heiner,

Quoted 12 lines · Heiner Kallweit

Use new helper acpi_use_parent_companion to simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index a41f5349a..ac223146c 100644

drivers/i2c/busses/i2c-i801.c static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) · line 1623

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
@@ -1620,7 +1620,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	priv->adapter.class = I2C_CLASS_HWMON;
 	priv->adapter.algo = &smbus_algorithm;
 	priv->adapter.dev.parent = &dev->dev;
-	ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
+	acpi_use_parent_companion(&priv->adapter.dev);

I find this neater.

Andi

maintainer Acked-by on v1 1/2
#10 lore raw

Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion

In reply to Heiner Kallweit
Quoted 5 lines · Heiner Kallweit

In several drivers devices use the ACPI companion of the parent. Add a helper for this use case to avoid code duplication.

or do you want me to apply it?

Quoted 22 lines
---
 include/linux/acpi.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/acpi.h +5 -1
index ba3f601b6..89efb1658 100644
@@ -1541,4 +1541,9 @@ static inline void acpi_device_notify(struct device *dev) { }
 static inline void acpi_device_notify_remove(struct device *dev) { }
 #endif
 
+static inline void acpi_use_parent_companion(struct device *dev)
+{
+       ACPI_COMPANION_SET(dev, ACPI_COMPANION(dev->parent));
+}
+
 #endif /*_LINUX_ACPI_H*/
--

2.42.0

#11 lore raw

Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion

Quoted 11 lines · Rafael J. Wysocki
Quoted 5 lines · Heiner Kallweit

In several drivers devices use the ACPI companion of the parent. Add a helper for this use case to avoid code duplication.

or do you want me to apply it?

Patch 2 of the series will apply cleanly only after the following patch that has been reviewed/acked, but not applied yet.
https://patchwork.ozlabs.org/project/linux-i2c/patch/[email protected]/
So my preference is to apply the series through the i2c tree. +Wolfram

Quoted 22 lines
Quoted 22 lines
---
 include/linux/acpi.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/acpi.h +5 -1
index ba3f601b6..89efb1658 100644
@@ -1541,4 +1541,9 @@ static inline void acpi_device_notify(struct device *dev) { }
 static inline void acpi_device_notify_remove(struct device *dev) { }
 #endif
 
+static inline void acpi_use_parent_companion(struct device *dev)
+{
+       ACPI_COMPANION_SET(dev, ACPI_COMPANION(dev->parent));
+}
+
 #endif /*_LINUX_ACPI_H*/
--

2.42.0

maintainer Reviewed-by on v1 1/2
#12 lore raw

Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion

In reply to Heiner Kallweit

Hi Heiner,

Quoted 4 lines · Heiner Kallweit

In several drivers devices use the ACPI companion of the parent. Add a helper for this use case to avoid code duplication.

Wolfram, can we take this in i2c? Otherwise this will take two release rounds to get in.

Andi

#13 lore raw

Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion

Quoted 3 lines

Wolfram, can we take this in i2c? Otherwise this will take two release rounds to get in.

In general, I can, no problem. But there is still on-going discussion regarding patch 2. So, I will wait for a conclusion there. I am not familiar enough with ACPI to have an own opinion about that topic.

#14 lore raw

Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion

Quoted 8 lines · Wolfram Sang
Quoted 3 lines

Wolfram, can we take this in i2c? Otherwise this will take two release rounds to get in.

In general, I can, no problem. But there is still on-going discussion regarding patch 2. So, I will wait for a conclusion there. I am not familiar enough with ACPI to have an own opinion about that topic.

Not sure whether the discussion is ongoing, my impression is it stalled. Rafael as ACPI maintainer thinks the helper makes sense and therefore acked it. Andi shares this opinion, and others like Jean have doubts. For sure I won't receive a Turing award for this helper, but it's IMO better than the cascaded macros.