Skip to contentSkip to conversation

i2c: i801: Series with improvements

PATCH Applied Heiner Kallweit 4 participants 48 messages Aug 6, 2021 – Nov 29, 2021

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

v2 cover i2c: i801: Series with improvements

This series includes a number of improvements to the i801 driver.

v2:
removed first patch from v1 series
patch 2
- include linux/mutex.h
patch 4
- avoid assigning potentially dangling pointer to *return_value
patch 8
- move definition of struct i2c_board_info info to inner loop
- add missing curly braces to outer for loop

Heiner Kallweit (9):
i2c: i801: Improve disabling runtime pm
i2c: i801: make p2sb_spinlock a mutex
i2c: i801: Remove not needed debug message
i2c: i801: Improve is_dell_system_with_lis3lv02d
i2c: i801: Remove not needed check for PCI_COMMAND_INTX_DISABLE
i2c: i801: Improve i801_acpi_probe/remove functions
i2c: i801: Improve i801_add_mux
i2c: i801: Improve register_dell_lis3lv02d_i2c_device
i2c: i801: Improve handling platform data for tco device

 drivers/i2c/busses/i2c-i801.c | 138 ++++++++++++----------------------
 1 file changed, 48 insertions(+), 90 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH v2 1/9 i2c: i801: Improve disabling runtime pm

Setting the autosuspend delay to a negative value disables runtime pm in a little bit smarter way, because we need no cleanup when removing the driver. Note that this is safe when reloading the driver, because the call to pm_runtime_set_autosuspend_delay() in probe() will reverse the effect. See update_autosuspend() for details.

---
 drivers/i2c/busses/i2c-i801.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/i2c/busses/i2c-i801.c +1 -6
index 92ec291c0..ef6dbb531 100644
@@ -1628,7 +1628,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_get_sync(&pdev->dev);
+		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
 	}
 
 	if ((function & ACPI_IO_MASK) == ACPI_READ)
@@ -1668,11 +1668,6 @@ static void i801_acpi_remove(struct i801_priv *priv)
 
 	acpi_remove_address_space_handler(adev->handle,
 		ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
-
-	mutex_lock(&priv->acpi_lock);
-	if (priv->acpi_reserved)
-		pm_runtime_put(&priv->pci_dev->dev);
-	mutex_unlock(&priv->acpi_lock);
 }
 #else
 static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
Signature · 1 line
2.32.0
Applied
#2 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 8 lines · Heiner Kallweit

Setting the autosuspend delay to a negative value disables runtime pm in a little bit smarter way, because we need no cleanup when removing the driver. Note that this is safe when reloading the driver, because the call to pm_runtime_set_autosuspend_delay() in probe() will reverse the effect. See update_autosuspend() for details.

Applied to for-next, thanks!

#3 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

In reply to Heiner Kallweit
Quoted 5 lines · Heiner Kallweit

Setting the autosuspend delay to a negative value disables runtime pm in a little bit smarter way, because we need no cleanup when removing the driver. Note that this is safe when reloading the driver, because the call to pm_runtime_set_autosuspend_delay() in probe() will reverse the effect. See update_autosuspend() for details.

...

drivers/i2c/busses/i2c-i801.c i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, · line 1631

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_get_sync(&pdev->dev);
+		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Heiner Kallweit

Setting the autosuspend delay to a negative value disables runtime pm in a little bit smarter way, because we need no cleanup when removing the driver. Note that this is safe when reloading the driver, because the call to pm_runtime_set_autosuspend_delay() in probe() will reverse the effect. See update_autosuspend() for details.

...

Quoted 9 lines

drivers/i2c/busses/i2c-i801.c i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, · line 1631

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_get_sync(&pdev->dev);
+		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

#5 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 19 lines · Heiner Kallweit
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Heiner Kallweit

Setting the autosuspend delay to a negative value disables runtime pm in a little bit smarter way, because we need no cleanup when removing the driver. Note that this is safe when reloading the driver, because the call to pm_runtime_set_autosuspend_delay() in probe() will reverse the effect. See update_autosuspend() for details.

...

Quoted 9 lines

drivers/i2c/busses/i2c-i801.c i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits, · line 1631

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +1 -1
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_get_sync(&pdev->dev);
+		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

Quoted 3 lines

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

But it will mean the side effect on this driver and typical (root-run) system application (systemd like?) should care now the knowledge about this side-effect. I do not think it is desired behaviour. But I'm not a maintainer and I commented here just to make everybody understand the consequences of the change.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

Quoted 5 lines

But it will mean the side effect on this driver and typical (root-run) system application (systemd like?) should care now the knowledge about this side-effect. I do not think it is desired behaviour. But I'm not a maintainer and I commented here just to make everybody understand the consequences of the change.

Jean, are you still fine with this patch then?

#7 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Hi Wolfram,

Quoted 6 lines · Wolfram Sang
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

This is something we hear frequently when people don't want to address problems in their code, but that's not enough to convince me ;-)

Quoted 5 lines
Quoted 5 lines

But it will mean the side effect on this driver and typical (root-run) system application (systemd like?) should care now the knowledge about this side-effect. I do not think it is desired behaviour. But I'm not a maintainer and I commented here just to make everybody understand the consequences of the change.

Is systemd going to actually make any change to that attribute? I'm no systemd expert, but I can't see any option in the configuration files that would be related to autosuspend.

Quoted 1 line

Jean, are you still fine with this patch then?

My original position was that there are a few other drivers already doing "this". It's not like we are doing something completely new and using an API in a way it had never been used before, so it can't be that bad.

On the other hand, after taking a closer look, I'm not fully certain that "this" is exactly the same in all these drivers. For example, in blk-pm.c, pm_runtime_set_autosuspend_delay() is being called with value -1 initially, but with the idea that someone else (device driver, user) may set a positive value later. It's not a permanent disable. The 8250_omap driver, however, seems to match the i2c-i801 driver here (I say "seems" because honestly I'm not sure I fully understand the comments there, but my understanding is that at least in some situations, enabling autosuspend later would cause problems).

That being said, it starts looking like a problem for the PM subsystem maintainers. Basically Heiner is trying to move away from an API which requires cleaning up on driver removal. This is definitely the direction we are collectively taking for years now (the whole devm_* family of functions is about exactly that). So it's considered a good thing.

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

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

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 1 line · Jean Delvare

On Tue, 17 Aug 2021 22:15:58 +0200, Wolfram Sang wrote:

Jean, thanks for your response. My 2 cents below.

Quoted 27 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

This is something we hear frequently when people don't want to address problems in their code, but that's not enough to convince me ;-)

Quoted 5 lines
Quoted 5 lines

But it will mean the side effect on this driver and typical (root-run) system application (systemd like?) should care now the knowledge about this side-effect. I do not think it is desired behaviour. But I'm not a maintainer and I commented here just to make everybody understand the consequences of the change.

Is systemd going to actually make any change to that attribute? I'm no systemd expert, but I can't see any option in the configuration files that would be related to autosuspend.

Quoted 1 line

Jean, are you still fine with this patch then?

My original position was that there are a few other drivers already doing "this". It's not like we are doing something completely new and using an API in a way it had never been used before, so it can't be that bad.

Quoted 5 lines

On the other hand, after taking a closer look, I'm not fully certain that "this" is exactly the same in all these drivers. For example, in blk-pm.c, pm_runtime_set_autosuspend_delay() is being called with value -1 initially, but with the idea that someone else (device driver, user) may set a positive value later. It's not a permanent disable.

Correct, it's expected that either system wide tool or user with enough privileges may enable it.

Quoted 1 line

The 8250_omap driver,

Oh, no, please, do not use that driver as an example for runtime PM. It's (somehow) broken there! I Cc'ed Tony in case you have more Q:s about it. It's on a healing curve, though.

The idea behind I believe is the same, i.e. to allow user to turn it on and off.

Quoted 21 lines

however, seems to match the i2c-i801 driver here (I say "seems" because honestly I'm not sure I fully understand the comments there, but my understanding is that at least in some situations, enabling autosuspend later would cause problems).

That being said, it starts looking like a problem for the PM subsystem maintainers. Basically Heiner is trying to move away from an API which requires cleaning up on driver removal. This is definitely the direction we are collectively taking for years now (the whole devm_* family of functions is about exactly that). So it's considered a good thing.

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

In reply to Jean Delvare
Quoted 53 lines · Jean Delvare

Hi Wolfram,

Quoted 6 lines · Wolfram Sang
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I dunno if it's being discussed, but with this you effectively allow user to override the setting. It may screw things up AFAIU the comment above.

No, this hasn't been discussed. At least not now. Thanks for the hint. This attribute is writable for the root user, so we could argue that the root user has several options to break the system anyway.

This is something we hear frequently when people don't want to address problems in their code, but that's not enough to convince me ;-)

Quoted 5 lines
Quoted 5 lines

But it will mean the side effect on this driver and typical (root-run) system application (systemd like?) should care now the knowledge about this side-effect. I do not think it is desired behaviour. But I'm not a maintainer and I commented here just to make everybody understand the consequences of the change.

Is systemd going to actually make any change to that attribute? I'm no systemd expert, but I can't see any option in the configuration files that would be related to autosuspend.

Quoted 1 line

Jean, are you still fine with this patch then?

My original position was that there are a few other drivers already doing "this". It's not like we are doing something completely new and using an API in a way it had never been used before, so it can't be that bad.

On the other hand, after taking a closer look, I'm not fully certain that "this" is exactly the same in all these drivers. For example, in blk-pm.c, pm_runtime_set_autosuspend_delay() is being called with value -1 initially, but with the idea that someone else (device driver, user) may set a positive value later. It's not a permanent disable. The 8250_omap driver, however, seems to match the i2c-i801 driver here (I say "seems" because honestly I'm not sure I fully understand the comments there, but my understanding is that at least in some situations, enabling autosuspend later would cause problems).

That being said, it starts looking like a problem for the PM subsystem maintainers. Basically Heiner is trying to move away from an API which requires cleaning up on driver removal. This is definitely the direction we are collectively taking for years now (the whole devm_* family of functions is about exactly that). So it's considered a good thing.

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

Quoted 4 lines

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

To follow-up on this: This patch has been applied already. Therefore, if decision is to not go with it, it would need to be reverted.

#10 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 7 lines · Heiner Kallweit
Quoted 6 lines · Jean Delvare

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

Quoted 6 lines
Quoted 3 lines

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

To follow-up on this: This patch has been applied already. Therefore, if decision is to not go with it, it would need to be reverted.

Technically it's not in Linus' tree yet ;-)

I'm still interested to know if pm_runtime_dont_use_autosuspend() is the right call to use in this situation.

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

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 12 lines · Jean Delvare
Quoted 11 lines · Heiner Kallweit
Quoted 9 lines · Jean Delvare

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

Quoted 8 lines
Quoted 2 lines

To follow-up on this: This patch has been applied already. Therefore, if decision is to not go with it, it would need to be reverted.

Technically it's not in Linus' tree yet ;-)

I'm still interested to know if pm_runtime_dont_use_autosuspend() is the right call to use in this situation.

I don't think so. It disable auto-suspending, but leaves "normal" runtime-suspending active. Calling pm_runtime_disable() may be an alternative.
Or we use the following to re-establish the old behavior with a little less overhead. Getting the mutex isn't needed here because the PCI core increments the rpm usage_count before calling the remove() hook.

drivers/i2c/busses/i2c-i801.c +4 -2
index 1f929e6c3..b5723d946 100644
@@ -1623,7 +1623,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
+		pm_runtime_get_sync(&pdev->dev);
 	}
 
 	if ((function & ACPI_IO_MASK) == ACPI_READ)
@@ -1891,7 +1891,9 @@ static void i801_remove(struct pci_dev *dev)
 	struct i801_priv *priv = pci_get_drvdata(dev);
 
 	pm_runtime_forbid(&dev->dev);
-	pm_runtime_get_noresume(&dev->dev);
+	/* if acpi_reserved is set then usage_count is incremented already */
+	if (!priv->acpi_reserved)
+		pm_runtime_get_noresume(&dev->dev);
 
 	i801_disable_host_notify(priv);
 	i801_del_mux(priv);
Signature · 1 line
2.33.0
#12 lore raw

Re: [PATCH v2 1/9] i2c: i801: Improve disabling runtime pm

Quoted 21 lines · Heiner Kallweit
Quoted 12 lines · Jean Delvare
Quoted 11 lines · Heiner Kallweit
Quoted 9 lines · Jean Delvare

If pm_runtime_set_autosuspend_delay() is not suitable for the task then maybe we need a better API. I will admit I'm at a loss when it comes to the many pm_runtime_* calls, I'm not going to claim I fully understand what each of them is doing exactly. But don't we want to simply call pm_runtime_dont_use_autosuspend() here?

If not and there's no suitable API for the task at the moment, then better do not apply this patch, and instead ask the PM subsystem maintainers if they would be willing to implement what we need.

Quoted 8 lines
Quoted 2 lines

To follow-up on this: This patch has been applied already. Therefore, if decision is to not go with it, it would need to be reverted.

Technically it's not in Linus' tree yet ;-)

I'm still interested to know if pm_runtime_dont_use_autosuspend() is the right call to use in this situation.

Quoted 7 lines

I don't think so. It disable auto-suspending, but leaves "normal" runtime-suspending active. Calling pm_runtime_disable() may be an alternative.
Or we use the following to re-establish the old behavior with a little less overhead. Getting the mutex isn't needed here because the PCI core increments the rpm usage_count before calling the remove() hook.

Just figured out that what I proposed wasn't fully correct. We should only access priv->acpi_reserved once we're sure the ACPI io handler can't run in parallel.
Small disclaimer: I'm not fully sure how acpi_remove_address_space_handler() behaves if it's called whilst the handler is running.
IOW: Whether we can be sure that after the call to acpi_remove_address_space_handler() the handler isn't running.

On a sidenote:
At least the call to pm_runtime_forbid() isn't needed because runtime pm is disabled anyway and the calls to pm_runtime_forbid/allow don't have to be balanced.

drivers/i2c/busses/i2c-i801.c +5 -4
index 1f929e6c3..6394c8340 100644
@@ -1623,7 +1623,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
+		pm_runtime_get_sync(&pdev->dev);
 	}
 
 	if ((function & ACPI_IO_MASK) == ACPI_READ)
@@ -1890,9 +1890,6 @@ static void i801_remove(struct pci_dev *dev)
 {
 	struct i801_priv *priv = pci_get_drvdata(dev);
 
-	pm_runtime_forbid(&dev->dev);
-	pm_runtime_get_noresume(&dev->dev);
-
 	i801_disable_host_notify(priv);
 	i801_del_mux(priv);
 	i2c_del_adapter(&priv->adapter);
@@ -1901,6 +1898,10 @@ static void i801_remove(struct pci_dev *dev)
 
 	platform_device_unregister(priv->tco_pdev);
 
+	pm_runtime_forbid(&dev->dev);
+	/* if acpi_reserved is set then usage_count is incremented already */
+	if (!priv->acpi_reserved)
+		pm_runtime_get_noresume(&dev->dev);
 	/*
 	 * do not call pci_disable_device(dev) since it can cause hard hangs on
 	 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
Signature · 1 line
2.33.0
#13 lore raw

PATCH v2 2/9 i2c: i801: make p2sb_spinlock a mutex

In reply to Heiner Kallweit

p2sb_spinlock is used in i801_add_tco_spt() only, and in process context only. Therefore a mutex is sufficient, and we can make the definition local to i801_add_tco_spt().

---
 drivers/i2c/busses/i2c-i801.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +4 -4
index ef6dbb531..12e0c2ac3 100644
@@ -110,6 +110,7 @@
 #include <linux/platform_device.h>
 #include <linux/platform_data/itco_wdt.h>
 #include <linux/pm_runtime.h>
+#include <linux/mutex.h>
 
 #if IS_ENABLED(CONFIG_I2C_MUX_GPIO) && defined CONFIG_DMI
 #include <linux/gpio/machine.h>
@@ -1492,12 +1493,11 @@ static const struct itco_wdt_platform_data spt_tco_platform_data = {
 	.version = 4,
 };
 
-static DEFINE_SPINLOCK(p2sb_spinlock);
-
 static struct platform_device *
 i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 		 struct resource *tco_res)
 {
+	static DEFINE_MUTEX(p2sb_mutex);
 	struct resource *res;
 	unsigned int devfn;
 	u64 base64_addr;
@@ -1510,7 +1510,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 	 * enumerated by the PCI subsystem, so we need to unhide/hide it
 	 * to lookup the P2SB BAR.
 	 */
-	spin_lock(&p2sb_spinlock);
+	mutex_lock(&p2sb_mutex);
 
 	devfn = PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 1);
 
@@ -1528,7 +1528,7 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 	/* Hide the P2SB device, if it was hidden before */
 	if (hidden)
 		pci_bus_write_config_byte(pci_dev->bus, devfn, 0xe1, hidden);
-	spin_unlock(&p2sb_spinlock);
+	mutex_unlock(&p2sb_mutex);
 
 	res = &tco_res[1];
 	if (pci_dev->device == PCI_DEVICE_ID_INTEL_DNV_SMBUS)
Signature · 1 line
2.32.0
Applied
#14 lore raw

Re: [PATCH v2 2/9] i2c: i801: make p2sb_spinlock a mutex

Quoted 7 lines · Heiner Kallweit

p2sb_spinlock is used in i801_add_tco_spt() only, and in process context only. Therefore a mutex is sufficient, and we can make the definition local to i801_add_tco_spt().

Applied to for-next, thanks!

Quoted 4 lines

#include <linux/platform_device.h>
#include <linux/platform_data/itco_wdt.h>
#include <linux/pm_runtime.h>
+#include <linux/mutex.h>

Can you also sort the includes while cleaning up the driver? Then, it is more obvious that mutex.h was already needed for acpi_lock. That would be great!

#15 lore raw

Re: [PATCH v2 2/9] i2c: i801: make p2sb_spinlock a mutex

In reply to Heiner Kallweit
Quoted 3 lines · Heiner Kallweit

p2sb_spinlock is used in i801_add_tco_spt() only, and in process context only. Therefore a mutex is sufficient, and we can make the definition local to i801_add_tco_spt().

The problem with either AFAICT is that it should actually hold PCI rescan lock. See the discussion with Message-ID [email protected] for the details.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH v2 2/9] i2c: i801: make p2sb_spinlock a mutex

Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit

p2sb_spinlock is used in i801_add_tco_spt() only, and in process context only. Therefore a mutex is sufficient, and we can make the definition local to i801_add_tco_spt().

The problem with either AFAICT is that it should actually hold PCI rescan lock. See the discussion with Message-ID [email protected] for the details.

Thanks for the link. I see that you use pci_lock_rescan_remove() but at a first glance didn't see this being discussed. Maybe because it's obvious ..

i801 was discussed here:
https://lore.kernel.org/linux-i2c/20210310155145.513a7165@endymion/
However discussion seems to have ended w/o result. What's the status of your p2sb series? Backgroud of the question is: Does it make sense to wait for your series to be applied, to make use of your new ps2b library functions? Or change the mutex to the rescan mutex for the time being?

#17 lore raw

Re: [PATCH v2 2/9] i2c: i801: make p2sb_spinlock a mutex

Quoted 13 lines · Heiner Kallweit
Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit

p2sb_spinlock is used in i801_add_tco_spt() only, and in process context only. Therefore a mutex is sufficient, and we can make the definition local to i801_add_tco_spt().

The problem with either AFAICT is that it should actually hold PCI rescan lock. See the discussion with Message-ID [email protected] for the details.

Thanks for the link. I see that you use pci_lock_rescan_remove() but at a first glance didn't see this being discussed. Maybe because it's obvious ..

Quoted 6 lines

i801 was discussed here:
https://lore.kernel.org/linux-i2c/20210310155145.513a7165@endymion/
However discussion seems to have ended w/o result. What's the status of your p2sb series? Backgroud of the question is: Does it make sense to wait for your series to be applied, to make use of your new ps2b library functions? Or change the mutex to the rescan mutex for the time being?

The problem with P2SB PCI device is that it's used as a holder for the firmware programmed value of the BAR which mustn't be relocated. If PCI runs rescan concurrently with this piece of code (still a probability higher than 0) then we will be in bad situation.

So, yes, rescan lock is a minimum what has to be done.

In regard to the series the idea is to unhide the P2SB in early PCI quirk and mark its resources unrelocatable. But I haven't time to research that. It's postponed currently due to lack of time on my side because higher priority tasks ongoing.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#18 lore raw

PATCH v2 3/9 i2c: i801: Remove not needed debug message

In reply to Heiner Kallweit

If a user is interested in such details he can enable smbus tracing.

---
 drivers/i2c/busses/i2c-i801.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +0 -4
index 12e0c2ac3..89ae78ef1 100644
@@ -559,10 +559,6 @@ static void i801_isr_byte_done(struct i801_priv *priv)
 					priv->len);
 				/* FIXME: Recover */
 				priv->len = I2C_SMBUS_BLOCK_MAX;
-			} else {
-				dev_dbg(&priv->pci_dev->dev,
-					"SMBus block read size is %d\n",
-					priv->len);
 			}
 			priv->data[-1] = priv->len;
 		}
Signature · 1 line
2.32.0
#20 lore raw

PATCH v2 4/9 i2c: i801: Improve is_dell_system_with_lis3lv02d

In reply to Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

---
v2:
- avoid assigning potentially dangling pointer to *return_value

---
 drivers/i2c/busses/i2c-i801.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-i801.c +5 -9
index 89ae78ef1..f56060fcf 100644
@@ -1192,7 +1192,7 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
 
 	kfree(info);
 
-	*((bool *)return_value) = true;
+	*return_value = NULL;
 	return AE_CTRL_TERMINATE;
 
 smo88xx_not_found:
@@ -1202,11 +1202,9 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
 
 static bool is_dell_system_with_lis3lv02d(void)
 {
-	bool found;
-	const char *vendor;
+	void *err = ERR_PTR(-ENOENT);
 
-	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
-	if (!vendor || strcmp(vendor, "Dell Inc."))
+	if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc."))
 		return false;
 
 	/*
@@ -1217,11 +1215,9 @@ static bool is_dell_system_with_lis3lv02d(void)
 	 * accelerometer but unfortunately ACPI does not provide any other
 	 * information (like I2C address).
 	 */
-	found = false;
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
 
-	return found;
+	return !IS_ERR(err);
 }
 
 /*
Signature · 1 line
2.32.0
#21 lore raw

Re: [PATCH v2 4/9] i2c: i801: Improve is_dell_system_with_lis3lv02d

Quoted 2 lines · Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

...

drivers/i2c/busses/i2c-i801.c static bool is_dell_system_with_lis3lv02d(void) · line 1220

Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +2 -3
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
 
-	return found;
+	return !IS_ERR(err);

Shouldn't you also check the status of acpi_get_device()?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#22 lore raw

Re: [PATCH v2 4/9] i2c: i801: Improve is_dell_system_with_lis3lv02d

Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

...

Quoted 9 lines

drivers/i2c/busses/i2c-i801.c static bool is_dell_system_with_lis3lv02d(void) · line 1220

Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +2 -3
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
 
-	return found;
+	return !IS_ERR(err);

Shouldn't you also check the status of acpi_get_device()?

This shouldn't be needed because err isn't touched if function fails.

#23 lore raw

Re: [PATCH v2 4/9] i2c: i801: Improve is_dell_system_with_lis3lv02d

Quoted 11 lines · Heiner Kallweit
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

...

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -2
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
Quoted 6 lines
Quoted 5 lines

drivers/i2c/busses/i2c-i801.c static bool is_dell_system_with_lis3lv02d(void) · line 1220

Quoted 2 lines
drivers/i2c/busses/i2c-i801.c +1 -1
-	return found;
+	return !IS_ERR(err);

Shouldn't you also check the status of acpi_get_device()?

This shouldn't be needed because err isn't touched if function fails.

For the sake of clearness of the code I would do it. But in any case what really hurt my eye is the last line here. To me sounds like

	if (IS_ERR(err))
		return false;
	return true;

is much better to read (and I bet the compiler will generate the very same code for it).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#24 lore raw

Re: [PATCH v2 4/9] i2c: i801: Improve is_dell_system_with_lis3lv02d

Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Heiner Kallweit
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

...

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -2
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

drivers/i2c/busses/i2c-i801.c static bool is_dell_system_with_lis3lv02d(void) · line 1220

Quoted 2 lines
drivers/i2c/busses/i2c-i801.c +1 -1
-	return found;
+	return !IS_ERR(err);  

Shouldn't you also check the status of acpi_get_device()?

This shouldn't be needed because err isn't touched if function fails.

For the sake of clearness of the code I would do it.

This brings us back to how awkward the API is. Most callers don't bother checking the return value of acpi_get_devices() because it's useless in practice. But I agree that in theory it could return with an error and then it would be nicer to catch that.

Quoted 9 lines

(...) But in any case what
really hurt my eye is the last line here. To me sounds like

	if (IS_ERR(err))
		return false;
	return true;

is much better to read (and I bet the compiler will generate the very same code for it).

Somehow the assembly code differs, but I'm unable to see the relation between your proposed change and the assembly code changes. That's why I hate modern compilers. They pretend to be smart, but what they are essentially is unstable, and this ruins any attempt at such trivial comparisons. Sad.

Personally I don't really care, Heiner's code did not strike me as being hard to read in the first place. I tend to avoid conditionals when possible.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
Reviewed-by on v2 4/9
#25 lore raw

Re: [PATCH v2 4/9] i2c: i801: Improve is_dell_system_with_lis3lv02d

In reply to Heiner Kallweit

Hi Heiner,

Quoted 42 lines · Heiner Kallweit

Replace the ugly cast of the return_value pointer with proper usage. In addition use dmi_match() instead of open-coding it.

---
v2:
- avoid assigning potentially dangling pointer to *return_value

---
 drivers/i2c/busses/i2c-i801.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-i801.c +3 -5
index 89ae78ef1..f56060fcf 100644
@@ -1192,7 +1192,7 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
 
 	kfree(info);
 
-	*((bool *)return_value) = true;
+	*return_value = NULL;
 	return AE_CTRL_TERMINATE;
 
 smo88xx_not_found:
@@ -1202,11 +1202,9 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
 
 static bool is_dell_system_with_lis3lv02d(void)
 {
-	bool found;
-	const char *vendor;
+	void *err = ERR_PTR(-ENOENT);
 
-	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
-	if (!vendor || strcmp(vendor, "Dell Inc."))
+	if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc."))
 		return false;
 
 	/*
@@ -1217,11 +1215,9 @@ static bool is_dell_system_with_lis3lv02d(void)
 	 * accelerometer but unfortunately ACPI does not provide any other
 	 * information (like I2C address).
 	 */

drivers/i2c/busses/i2c-i801.c static bool is_dell_system_with_lis3lv02d(void) · line 1223

Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +2 -4
-	found = false;
-	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
-			 (void **)&found);
+	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &err);
 
-	return found;
+	return !IS_ERR(err);
 }
 
 /*

OK, it's a bit different from what I proposed but it still addresses the concerns that had been raised. So fine with me.

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

PATCH v2 5/9 i2c: i801: Remove not needed check for PCI_COMMAND_INTX_DISABLE

In reply to Heiner Kallweit

do_pci_enable_device() takes care that PCI_COMMAND_INTX_DISABLE is cleared if a legacy interrupt is used.

---
 drivers/i2c/busses/i2c-i801.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/i2c/busses/i2c-i801.c +1 -8
index f56060fcf..7fa06b85f 100644
@@ -1827,19 +1827,12 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		priv->features &= ~FEATURE_IRQ;
 
 	if (priv->features & FEATURE_IRQ) {
-		u16 pcictl, pcists;
+		u16 pcists;
 
 		/* Complain if an interrupt is already pending */
 		pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
 		if (pcists & PCI_STATUS_INTERRUPT)
 			dev_warn(&dev->dev, "An interrupt is pending!\n");
-
-		/* Check if interrupts have been disabled */
-		pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pcictl);
-		if (pcictl & PCI_COMMAND_INTX_DISABLE) {
-			dev_info(&dev->dev, "Interrupts are disabled\n");
-			priv->features &= ~FEATURE_IRQ;
-		}
 	}
 
 	if (priv->features & FEATURE_IRQ) {
Signature · 1 line
2.32.0
Reviewed-by on v2 5/9
#28 lore raw

Re: [PATCH v2 5/9] i2c: i801: Remove not needed check for PCI_COMMAND_INTX_DISABLE

Quoted 2 lines · Heiner Kallweit

do_pci_enable_device() takes care that PCI_COMMAND_INTX_DISABLE is cleared if a legacy interrupt is used.

Makes sense, but needs to be tested.

Quoted 34 lines
---
 drivers/i2c/busses/i2c-i801.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/i2c/busses/i2c-i801.c +1 -8
index f56060fcf..7fa06b85f 100644
@@ -1827,19 +1827,12 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		priv->features &= ~FEATURE_IRQ;
 
 	if (priv->features & FEATURE_IRQ) {
-		u16 pcictl, pcists;
+		u16 pcists;
 
 		/* Complain if an interrupt is already pending */
 		pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
 		if (pcists & PCI_STATUS_INTERRUPT)
 			dev_warn(&dev->dev, "An interrupt is pending!\n");
-
-		/* Check if interrupts have been disabled */
-		pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pcictl);
-		if (pcictl & PCI_COMMAND_INTX_DISABLE) {
-			dev_info(&dev->dev, "Interrupts are disabled\n");
-			priv->features &= ~FEATURE_IRQ;
-		}
 	}
 
 	if (priv->features & FEATURE_IRQ) {
Signature · 1 line
2.32.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v2 5/9
#29 lore raw

Re: [PATCH v2 5/9] i2c: i801: Remove not needed check for PCI_COMMAND_INTX_DISABLE

In reply to Heiner Kallweit
Quoted 23 lines · Heiner Kallweit

do_pci_enable_device() takes care that PCI_COMMAND_INTX_DISABLE is cleared if a legacy interrupt is used.

---
 drivers/i2c/busses/i2c-i801.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/i2c/busses/i2c-i801.c +1 -1
index f56060fcf..7fa06b85f 100644
@@ -1827,19 +1827,12 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		priv->features &= ~FEATURE_IRQ;
 
 	if (priv->features & FEATURE_IRQ) {
-		u16 pcictl, pcists;
+		u16 pcists;
 
 		/* Complain if an interrupt is already pending */
 		pci_read_config_word(priv->pci_dev, PCI_STATUS, &pcists);
 		if (pcists & PCI_STATUS_INTERRUPT)
 			dev_warn(&dev->dev, "An interrupt is pending!\n");

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

Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +0 -7
-
-		/* Check if interrupts have been disabled */
-		pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pcictl);
-		if (pcictl & PCI_COMMAND_INTX_DISABLE) {
-			dev_info(&dev->dev, "Interrupts are disabled\n");
-			priv->features &= ~FEATURE_IRQ;
-		}
 	}
 
 	if (priv->features & FEATURE_IRQ) {

As said before, I'm not sure, but let's apply that and see if anybody complains.

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

PATCH v2 6/9 i2c: i801: Improve i801_acpi_probe/remove functions

In reply to Heiner Kallweit

By using ACPI_HANDLE() the handler argument can be retrieved directly. Both address space handler functions check the handler argument and return an error if it's NULL. This allows to further simplify the code.

---
 drivers/i2c/busses/i2c-i801.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/i2c/busses/i2c-i801.c +7 -16
index 7fa06b85f..bd1db0f0a 100644
@@ -1635,31 +1635,22 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
 
 static int i801_acpi_probe(struct i801_priv *priv)
 {
-	struct acpi_device *adev;
+	acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
 	acpi_status status;
 
-	adev = ACPI_COMPANION(&priv->pci_dev->dev);
-	if (adev) {
-		status = acpi_install_address_space_handler(adev->handle,
-				ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
-				NULL, priv);
-		if (ACPI_SUCCESS(status))
-			return 0;
-	}
+	status = acpi_install_address_space_handler(ah, ACPI_ADR_SPACE_SYSTEM_IO,
+						    i801_acpi_io_handler, NULL, priv);
+	if (ACPI_SUCCESS(status))
+		return 0;
 
 	return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
 }
 
 static void i801_acpi_remove(struct i801_priv *priv)
 {
-	struct acpi_device *adev;
-
-	adev = ACPI_COMPANION(&priv->pci_dev->dev);
-	if (!adev)
-		return;
+	acpi_handle ah = ACPI_HANDLE(&priv->pci_dev->dev);
 
-	acpi_remove_address_space_handler(adev->handle,
-		ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
+	acpi_remove_address_space_handler(ah, ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
 }
 #else
 static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
Signature · 1 line
2.32.0
Applied
#32 lore raw

Re: [PATCH v2 6/9] i2c: i801: Improve i801_acpi_probe/remove functions

Quoted 8 lines · Heiner Kallweit

By using ACPI_HANDLE() the handler argument can be retrieved directly. Both address space handler functions check the handler argument and return an error if it's NULL. This allows to further simplify the code.

Applied to for-next, thanks!

#33 lore raw

PATCH v2 7/9 i2c: i801: Improve i801_add_mux

In reply to Heiner Kallweit

The return value of i801_add_mux() isn't used, so let's change it to void. In addition remove the not needed cast to struct gpiod_lookup. GPIO_LOOKUP() uses GPIO_LOOKUP_IDX() that includes this cast.

---
 drivers/i2c/busses/i2c-i801.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-i801.c +7 -11
index bd1db0f0a..6e9aca81b 100644
@@ -1391,7 +1391,7 @@ static const struct dmi_system_id mux_dmi_table[] = {
 };
 
 /* Setup multiplexing if needed */
-static int i801_add_mux(struct i801_priv *priv)
+static void i801_add_mux(struct i801_priv *priv)
 {
 	struct device *dev = &priv->adapter.dev;
 	const struct i801_mux_config *mux_config;
@@ -1400,7 +1400,7 @@ static int i801_add_mux(struct i801_priv *priv)
 	int i;
 
 	if (!priv->mux_drvdata)
-		return 0;
+		return;
 	mux_config = priv->mux_drvdata;
 
 	/* Prepare the platform data */
@@ -1416,13 +1416,11 @@ static int i801_add_mux(struct i801_priv *priv)
 			      struct_size(lookup, table, mux_config->n_gpios + 1),
 			      GFP_KERNEL);
 	if (!lookup)
-		return -ENOMEM;
+		return;
 	lookup->dev_id = "i2c-mux-gpio";
-	for (i = 0; i < mux_config->n_gpios; i++) {
-		lookup->table[i] = (struct gpiod_lookup)
-			GPIO_LOOKUP(mux_config->gpio_chip,
-				    mux_config->gpios[i], "mux", 0);
-	}
+	for (i = 0; i < mux_config->n_gpios; i++)
+		lookup->table[i] = GPIO_LOOKUP(mux_config->gpio_chip,
+					       mux_config->gpios[i], "mux", 0);
 	gpiod_add_lookup_table(lookup);
 	priv->lookup = lookup;
 
@@ -1440,8 +1438,6 @@ static int i801_add_mux(struct i801_priv *priv)
 		gpiod_remove_lookup_table(lookup);
 		dev_err(dev, "Failed to register i2c-mux-gpio device\n");
 	}
-
-	return PTR_ERR_OR_ZERO(priv->mux_pdev);
 }
 
 static void i801_del_mux(struct i801_priv *priv)
@@ -1471,7 +1467,7 @@ static unsigned int i801_get_adapter_class(struct i801_priv *priv)
 	return class;
 }
 #else
-static inline int i801_add_mux(struct i801_priv *priv) { return 0; }
+static inline void i801_add_mux(struct i801_priv *priv) { }
 static inline void i801_del_mux(struct i801_priv *priv) { }
 
 static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
Signature · 1 line
2.32.0
Applied
#34 lore raw

Re: [PATCH v2 7/9] i2c: i801: Improve i801_add_mux

Quoted 7 lines · Heiner Kallweit

The return value of i801_add_mux() isn't used, so let's change it to void. In addition remove the not needed cast to struct gpiod_lookup. GPIO_LOOKUP() uses GPIO_LOOKUP_IDX() that includes this cast.

Applied to for-next, thanks!

#35 lore raw

PATCH v2 8/9 i2c: i801: Improve register_dell_lis3lv02d_i2c_device

In reply to Heiner Kallweit

- Use an initializer for struct i2c_board_info info
- Use dmi_match()
- Simplify loop logic

---
v2:
- move definition of struct i2c_board_info info to inner loop
- add missing curly braces to outer for loop

---
 drivers/i2c/busses/i2c-i801.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/i2c/busses/i2c-i801.c +11 -17
index 6e9aca81b..88745e3bc 100644
@@ -1247,28 +1247,22 @@ static const struct {
 
 static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv)
 {
-	struct i2c_board_info info;
-	const char *dmi_product_name;
 	int i;
 
-	dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
 	for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i) {
-		if (strcmp(dmi_product_name,
-			   dell_lis3lv02d_devices[i].dmi_product_name) == 0)
-			break;
-	}
-
-	if (i == ARRAY_SIZE(dell_lis3lv02d_devices)) {
-		dev_warn(&priv->pci_dev->dev,
-			 "Accelerometer lis3lv02d is present on SMBus but its"
-			 " address is unknown, skipping registration\n");
-		return;
+		if (dmi_match(DMI_PRODUCT_NAME, dell_lis3lv02d_devices[i].dmi_product_name)) {
+			struct i2c_board_info info = {
+				.type = "lis3lv02d",
+				.addr = dell_lis3lv02d_devices[i].i2c_addr,
+			};
+
+			i2c_new_client_device(&priv->adapter, &info);
+			return;
+		}
 	}
 
-	memset(&info, 0, sizeof(struct i2c_board_info));
-	info.addr = dell_lis3lv02d_devices[i].i2c_addr;
-	strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
-	i2c_new_client_device(&priv->adapter, &info);
+	pci_warn(priv->pci_dev,
+		 "Accelerometer lis3lv02d is present on SMBus but its address is unknown, skipping registration\n");
 }
 
 /* Register optional slaves */
Signature · 1 line
2.32.0
#36 lore raw

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

Quoted 3 lines · Heiner Kallweit

- Use an initializer for struct i2c_board_info info
- Use dmi_match()
- Simplify loop logic

I'm wondering if changing this to a DMI match table will give better result.

Something like
(Sorry I forgot APIs, but plenty of examples are under PDx86: drivers/platform/x86):

struct dmi_..._id *id;

id = dmi_..._match();

if (!id) {
	pci_warn();
	return;
}

i2c_new_client_device(...);

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#37 lore raw

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit

- Use an initializer for struct i2c_board_info info
- Use dmi_match()
- Simplify loop logic

I'm wondering if changing this to a DMI match table will give better result.

Something like
(Sorry I forgot APIs, but plenty of examples are under PDx86: drivers/platform/x86):

struct dmi_..._id *id;

Quoted 9 lines

id = dmi_..._match();

if (!id) {
	pci_warn();
	return;
}

i2c_new_client_device(...);

We could do something like the following. Whether it's better may be a question of personal taste. I have no strong opinion here and would leave it to Jean.

const struct dmi_system_id lis3_id_table[] = {
        {
                .driver_data = (void *)0x29,
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5550"),
                },
        },
	...

dmi_system_id *id = dmi_first_match(lis3_id_table); if (id)

	i2c_new_client_device(..., (unsigned int)id->driver_data;

else
lament()

#38 lore raw

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

Quoted 34 lines · Heiner Kallweit
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit

- Use an initializer for struct i2c_board_info info
- Use dmi_match()
- Simplify loop logic

I'm wondering if changing this to a DMI match table will give better result.

Something like
(Sorry I forgot APIs, but plenty of examples are under PDx86: drivers/platform/x86):

struct dmi_..._id *id;

Quoted 8 lines

id = dmi_..._match();

if (!id) {
	pci_warn();
	return;
}

i2c_new_client_device(...);

We could do something like the following. Whether it's better may be a question of personal taste. I have no strong opinion here and would leave it to Jean.

const struct dmi_system_id lis3_id_table[] = {
        {
                .driver_data = (void *)0x29,
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5550"),
                },
        },
	...
Quoted 5 lines

dmi_system_id *id = dmi_first_match(lis3_id_table); if (id)

	i2c_new_client_device(..., (unsigned int)id->driver_data;

else
lament()

Yep, my point here that this has less indentation of the code, no unneeded for-loop (which will be inside DMI APIs, etc).

But yes, I agree that this is rather matter of taste.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#39 lore raw

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

In reply to Heiner Kallweit

Hi Heiner, Andy,

Quoted 34 lines · Heiner Kallweit
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit

- Use an initializer for struct i2c_board_info info
- Use dmi_match()
- Simplify loop logic

I'm wondering if changing this to a DMI match table will give better result.

Something like
(Sorry I forgot APIs, but plenty of examples are under PDx86: drivers/platform/x86):

struct dmi_..._id *id;

Quoted 7 lines

id = dmi_..._match();

if (!id) {
	pci_warn();
	return;
}

i2c_new_client_device(...);

We could do something like the following. Whether it's better may be a question of personal taste. I have no strong opinion here and would leave it to Jean.

const struct dmi_system_id lis3_id_table[] = {
        {
                .driver_data = (void *)0x29,
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5550"),
                },
        },
	...
Quoted 6 lines

dmi_system_id *id = dmi_first_match(lis3_id_table); if (id)

	i2c_new_client_device(..., (unsigned int)id->driver_data;

else
lament()

I gave it an actual try, and must say I'm not convinced. Heiner's patch is -6 lines of source code and +1 byte on the binary (according to scripts/bloat-o-meter - ls -l disagrees, don't ask me why). My suggested alternative (as discussed in the v1 of this patch set, basically Heiner's patch minus the removal of dmi_product_name) is -3 lines of source code and +17 bytes on the binary, but should be faster than Heiner's version.

Andy's approach results in an overall increase of the source code by 29 lines and +2582 bytes on the binary. Sure, if you break it down, it's +2624 data and -42 code, so it does "simplify the code", but that's too high a price to pay for a marginal code simplification. It also has the downside of reintroducing a cast from int to pointer and back, something we were trying to get rid of in another patch of this series. This could of course be avoided but this would make the patch even larger.

So thanks, but no thanks. Just because an API exists does not mean you have to use it in all cases.

I stand on my original position, let's stick to dmi_get_system_info() + strcmp() as the driver did originally. In other words, don't change code that has been working for years when the alternatives bring no clear benefit.

Thanks,

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

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

Quoted 5 lines

I stand on my original position, let's stick to dmi_get_system_info() + strcmp() as the driver did originally. In other words, don't change code that has been working for years when the alternatives bring no clear benefit.

So, I can skip this patch and continue with patch 9?

#41 lore raw

Re: [PATCH v2 8/9] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

Quoted 6 lines · Wolfram Sang
Quoted 4 lines

I stand on my original position, let's stick to dmi_get_system_info() + strcmp() as the driver did originally. In other words, don't change code that has been working for years when the alternatives bring no clear benefit.

So, I can skip this patch and continue with patch 9?

Yes please. There may be a subset of it that can still be applied, we can look into it once the dust has settled.

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

PATCH v2 9/9 i2c: i801: Improve handling platform data for tco device

In reply to Heiner Kallweit

The platform data structures are used in the respective i801_add_tco functions only. Therefore we can make the definitions local to these functions.

---
 drivers/i2c/busses/i2c-i801.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/i2c/busses/i2c-i801.c +12 -15
index 88745e3bc..242bdd2ae 100644
@@ -1470,15 +1470,14 @@ static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
 }
 #endif
 
-static const struct itco_wdt_platform_data spt_tco_platform_data = {
-	.name = "Intel PCH",
-	.version = 4,
-};
-
 static struct platform_device *
 i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 		 struct resource *tco_res)
 {
+	static const struct itco_wdt_platform_data pldata = {
+		.name = "Intel PCH",
+		.version = 4,
+	};
 	static DEFINE_MUTEX(p2sb_mutex);
 	struct resource *res;
 	unsigned int devfn;
@@ -1522,22 +1521,20 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 	res->flags = IORESOURCE_MEM;
 
 	return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
-					tco_res, 2, &spt_tco_platform_data,
-					sizeof(spt_tco_platform_data));
+					tco_res, 2, &pldata, sizeof(pldata));
 }
 
-static const struct itco_wdt_platform_data cnl_tco_platform_data = {
-	.name = "Intel PCH",
-	.version = 6,
-};
-
 static struct platform_device *
 i801_add_tco_cnl(struct i801_priv *priv, struct pci_dev *pci_dev,
 		 struct resource *tco_res)
 {
-	return platform_device_register_resndata(&pci_dev->dev,
-			"iTCO_wdt", -1, tco_res, 1, &cnl_tco_platform_data,
-			sizeof(cnl_tco_platform_data));
+	static const struct itco_wdt_platform_data pldata = {
+		.name = "Intel PCH",
+		.version = 6,
+	};
+
+	return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
+						 tco_res, 1, &pldata, sizeof(pldata));
 }
 
 static void i801_add_tco(struct i801_priv *priv)
Signature · 1 line
2.32.0
#43 lore raw

Re: [PATCH v2 9/9] i2c: i801: Improve handling platform data for tco device

Quoted 3 lines · Heiner Kallweit

The platform data structures are used in the respective i801_add_tco functions only. Therefore we can make the definitions local to these functions.

Side note: usually we refer to the functions like "i801_add_tco()" (w/o quotes).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#45 lore raw

Re: [PATCH v2 9/9] i2c: i801: Improve handling platform data for tco device

Quoted 9 lines · Wolfram Sang
Quoted 6 lines · Heiner Kallweit

The platform data structures are used in the respective i801_add_tco functions only. Therefore we can make the definitions local to these functions.

Hmm, this doesn't apply on i2c/for-mergewindow. Did I miss a patch?

Since a lot of other i801 patches have been merged meanwhile, I'd need this patch rebased if you still want it to be applied. Thanks for all your i801 work!

#46 lore raw

Re: [PATCH v2 9/9] i2c: i801: Improve handling platform data for tco device

Quoted 6 lines · Wolfram Sang
Quoted 5 lines · Wolfram Sang
Quoted 4 lines · Heiner Kallweit

The platform data structures are used in the respective i801_add_tco functions only. Therefore we can make the definitions local to these functions.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Hmm, this doesn't apply on i2c/for-mergewindow. Did I miss a patch?

Since a lot of other i801 patches have been merged meanwhile, I'd need this patch rebased if you still want it to be applied. Thanks for all your i801 work!

I just sent a rebased version.

#47 lore raw

PATCH v3 1/1 i2c: i801: Improve handling platform data for tco device

In reply to Heiner Kallweit

The platform data structures are used in the respective i801_add_tco functions only. Therefore we can make the definitions local to these functions.

---
v3:
- rebased

---
 drivers/i2c/busses/i2c-i801.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/i2c/busses/i2c-i801.c +12 -15
index 8c0695956..cb6e55758 100644
@@ -1463,15 +1463,14 @@ static inline unsigned int i801_get_adapter_class(struct i801_priv *priv)
 }
 #endif
 
-static const struct itco_wdt_platform_data spt_tco_platform_data = {
-	.name = "Intel PCH",
-	.version = 4,
-};
-
 static struct platform_device *
 i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 		 struct resource *tco_res)
 {
+	static const struct itco_wdt_platform_data pldata = {
+		.name = "Intel PCH",
+		.version = 4,
+	};
 	struct resource *res;
 	unsigned int devfn;
 	u64 base64_addr;
@@ -1514,22 +1513,20 @@ i801_add_tco_spt(struct i801_priv *priv, struct pci_dev *pci_dev,
 	res->flags = IORESOURCE_MEM;
 
 	return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
-					tco_res, 2, &spt_tco_platform_data,
-					sizeof(spt_tco_platform_data));
+					tco_res, 2, &pldata, sizeof(pldata));
 }
 
-static const struct itco_wdt_platform_data cnl_tco_platform_data = {
-	.name = "Intel PCH",
-	.version = 6,
-};
-
 static struct platform_device *
 i801_add_tco_cnl(struct i801_priv *priv, struct pci_dev *pci_dev,
 		 struct resource *tco_res)
 {
-	return platform_device_register_resndata(&pci_dev->dev,
-			"iTCO_wdt", -1, tco_res, 1, &cnl_tco_platform_data,
-			sizeof(cnl_tco_platform_data));
+	static const struct itco_wdt_platform_data pldata = {
+		.name = "Intel PCH",
+		.version = 6,
+	};
+
+	return platform_device_register_resndata(&pci_dev->dev, "iTCO_wdt", -1,
+						 tco_res, 1, &pldata, sizeof(pldata));
 }
 
 static void i801_add_tco(struct i801_priv *priv)
Signature · 1 line
2.34.1