Add and use new helper acpi_use_parent_companion
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
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
@@ -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
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
@@ -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
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_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/busses/i2c-i801.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-i801.c +0
-0
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
-0priv->adapter.retries =3 ; priv->pci_dev = dev;
Rafael J. Wysocki
maintainerRe: [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_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>--- 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@@ -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
-0priv->adapter.retries =3 ; priv->pci_dev = dev;
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_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>--- 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@@ -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
-0priv->adapter.retries =3 ; priv->pci_dev = dev;
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_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>--- 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@@ -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
-1priv->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
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_SETto 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?
Re: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion
In reply to Heiner KallweitHi Heiner,
Quoted 12 lines · Heiner Kallweit
Use new helper
acpi_use_parent_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>--- drivers/i2c/busses/i2c-i801.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-i801.c +0
-0
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
Wolfram Sang
AppliedRe: [PATCH 2/2] i2c: i801: Use new helper acpi_use_parent_companion
In reply to Heiner KallweitQuoted 3 lines · Heiner Kallweit
Use new helper
acpi_use_parent_companionto simplify the code.Signed-off-by Heiner Kallweit <[email protected]>
Applied to for-next, thanks!
Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion
In reply to Heiner KallweitQuoted 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.
Signed-off-by Heiner Kallweit <[email protected]>
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@@ -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
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.
Signed-off-by Heiner Kallweit <[email protected]>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@@ -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
Re: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion
In reply to Heiner KallweitHi 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.
Signed-off-by Heiner Kallweit <[email protected]>
Wolfram, can we take this in i2c? Otherwise this will take two release rounds to get in.
Andi
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.
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.
Wolfram Sang
AppliedRe: [PATCH 1/2] ACPI: Add helper acpi_use_parent_companion
In reply to Heiner KallweitQuoted 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.
Signed-off-by Heiner Kallweit <[email protected]>
Applied to for-next, thanks!