Skip to contentSkip to conversation

i2c: i801: fix cleanup code in remove() and error path of probe()

PATCH In review Heiner Kallweit 3 participants 7 messages Sep 2, 2023 – Sep 14, 2023

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

PATCH v2 1/1 i2c: i801: fix cleanup code in remove() and error path of probe()

Jean pointed out that the referenced patch resulted in the remove() path not having the reverse order of calls in probe(). I think there's more to be done to ensure proper cleanup.
Especially cleanup in the probe() error path has to be extended. Not every step there may be strictly needed, but it's in line with remove() now.

Fixes 9b5bf5878138 ("i2c: i801: Restore INTREN on unload")
Fixes 9424693035a5 ("i2c: i801: Create iTCO device on newer Intel PCHs")

---
v2:
- add Fixes tag for 9424693035a5
- remove restoring SMBHSTCNT from probe error path
- move restoring SMBHSTCNT to the end in remove/shutdown

---
 drivers/i2c/busses/i2c-i801.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-i801.c +7 -6
index 73ae06432..d4f59aecc 100644
@@ -1754,6 +1754,8 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		"SMBus I801 adapter at %04lx", priv->smba);
 	err = i2c_add_adapter(&priv->adapter);
 	if (err) {
+		platform_device_unregister(priv->tco_pdev);
+		pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
 		i801_acpi_remove(priv);
 		return err;
 	}
@@ -1779,14 +1781,13 @@ static void i801_remove(struct pci_dev *dev)
 {
 	struct i801_priv *priv = pci_get_drvdata(dev);
 
-	outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
-	i801_disable_host_notify(priv);
 	i801_del_mux(priv);
+	i801_disable_host_notify(priv);
 	i2c_del_adapter(&priv->adapter);
-	i801_acpi_remove(priv);
-	pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
-
 	platform_device_unregister(priv->tco_pdev);
+	pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
+	i801_acpi_remove(priv);
+	outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
 
 	/* if acpi_reserved is set then usage_count is incremented already */
 	if (!priv->acpi_reserved)
@@ -1803,9 +1804,9 @@ static void i801_shutdown(struct pci_dev *dev)
 	struct i801_priv *priv = pci_get_drvdata(dev);
 
 	/* Restore config registers to avoid hard hang on some systems */
-	outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
 	i801_disable_host_notify(priv);
 	pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
+	outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
 }
 
 static int i801_suspend(struct device *dev)
Signature · 1 line
2.42.0
Reviewed-by Tested-by on v2 1/1
#1 lore raw

Hi Heiner, Wolfram,

Quoted 6 lines · Heiner Kallweit

Jean pointed out that the referenced patch resulted in the remove() path not having the reverse order of calls in probe(). I think there's more to be done to ensure proper cleanup.
Especially cleanup in the probe() error path has to be extended. Not every step there may be strictly needed, but it's in line with remove() now.

This last sentence no longer applies to this version of the patch.

Quoted 3 lines
Fixes 9b5bf5878138 ("i2c: i801: Restore INTREN on unload")
Fixes 9424693035a5 ("i2c: i801: Create iTCO device on newer Intel PCHs")

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

For another, this patch is a mix of 2 bug fixes (SMBHSTCNT being restored too early in i801_remove, resource leak in error path of i801_probe) which have been added in very different kernel versions (v5.16 and v4.3, respectively), and tidying up (the reordering of some of the statements in i801_remove is nice for consistency but is not actually fixing any bug).

If you really want to push the fixes to stable, you'd have to split the patch in 3 pieces, one for each fix (going to stable), and one for the remainder (not going to stable). Otherwise it makes backporting to older kernels error-prone and time-consuming. Considering how harmless the bugs are in the first place, my position is that the extra work is simply not worth it.

Quoted 10 lines

---
v2:
- add Fixes tag for 9424693035a5
- remove restoring SMBHSTCNT from probe error path
- move restoring SMBHSTCNT to the end in remove/shutdown

---
 drivers/i2c/busses/i2c-i801.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(...)

That being said, the patch itself looks good to me, and I have tested it too.

Thanks,

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

Hi Jean,

Quoted 16 lines · Jean Delvare

Hi Heiner, Wolfram,

Quoted 6 lines · Heiner Kallweit

Jean pointed out that the referenced patch resulted in the remove() path not having the reverse order of calls in probe(). I think there's more to be done to ensure proper cleanup.
Especially cleanup in the probe() error path has to be extended. Not every step there may be strictly needed, but it's in line with remove() now.

This last sentence no longer applies to this version of the patch.

Quoted 3 lines
Fixes 9b5bf5878138 ("i2c: i801: Restore INTREN on unload")
Fixes 9424693035a5 ("i2c: i801: Create iTCO device on newer Intel PCHs")
Quoted 5 lines

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

we are having this same discussion in another thread: if a bug is unlikely to happen, doesn't mean that there is no bug. A fix is a fix and should be backported to stable kernels.

Sometimes bugs are reported some other times bugs are discovered by reading the code (like in the other thread). In the latter case bugs are just waiting for their time of glory.

I'm OK if this set of fixes have the Fixes tag or, like in the other case, we find a way to get it backported anyway.

Quoted 7 lines

For another, this patch is a mix of 2 bug fixes (SMBHSTCNT being restored too early in i801_remove, resource leak in error path of i801_probe) which have been added in very different kernel versions (v5.16 and v4.3, respectively), and tidying up (the reordering of some of the statements in i801_remove is nice for consistency but is not actually fixing any bug).

Quoted 6 lines

If you really want to push the fixes to stable, you'd have to split the patch in 3 pieces, one for each fix (going to stable), and one for the remainder (not going to stable). Otherwise it makes backporting to older kernels error-prone and time-consuming. Considering how harmless the bugs are in the first place, my position is that the extra work is simply not worth it.

In my opinion, Heiner, you should split this patch in the two logical changes that Jean was suggesting, add the tags from Jean and have them backported.

Thanks Jean for your review and inputs.

Andi

Quoted 21 lines
Quoted 10 lines

---
v2:
- add Fixes tag for 9424693035a5
- remove restoring SMBHSTCNT from probe error path
- move restoring SMBHSTCNT to the end in remove/shutdown

---
 drivers/i2c/busses/i2c-i801.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(...)

That being said, the patch itself looks good to me, and I have tested it too.

Thanks,

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

Hi Andi,

Quoted 10 lines · Andi Shyti
Quoted 8 lines · Jean Delvare
Quoted 1 line · Heiner Kallweit

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

Quoted 3 lines

we are having this same discussion in another thread: if a bug is unlikely to happen, doesn't mean that there is no bug. A fix is a fix and should be backported to stable kernels.

No. Please read:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

There is clearly a list of conditions for a commit to be eligible for stable kernel trees. It's not "every fix".

Quoted 3 lines

Sometimes bugs are reported some other times bugs are discovered by reading the code (like in the other thread). In the latter case bugs are just waiting for their time of glory.

I'm not saying otherwise. But that's clearly one of the factor to decide whether a fix should go to stable. A bug which has been reported by a user who is affected by it is clearly a better candidate to backport. The other factor is how bad things are if the bug happens. I fully agree that a bug which is found by code review but would have dramatic consequences should also have its fix backported to stable kernel trees, even if it never happened before and is unlikely to happen in the future.

My point is that the bugs being discussed here do not match any of these criteria. They have not been reported, they most likely never happened, they most likely never will, and if they would, consequences would be pretty benign.

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

Hi Jean,

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

we are having this same discussion in another thread: if a bug is unlikely to happen, doesn't mean that there is no bug. A fix is a fix and should be backported to stable kernels.

Quoted 6 lines

No. Please read:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

There is clearly a list of conditions for a commit to be eligible for stable kernel trees. It's not "every fix".

I think you are putting these fixes into the ""This could be a problem..." type of things".

But as I see these fixes don't belong to this category, as they are clearing the exit path. This is a kind of fixes I want to see going to stable.

Which means that if we exit through that path, do we exit cleanly, e.g., without leaking? If the answer is "no", then this is a fix and should go to stable.

It belongs to "This could be a problem..." type, things like dev_err/dev_warn (first thing coming to my mind) or other non functional fixes.

Maybe this is a matter of opinion and different background. For the i2c side I'm in peace :-)

For the stable backport I'd love to hear another opinion.

Thanks, Jean!
Andi

#5 lore raw
Quoted 34 lines · Andi Shyti

Hi Jean,

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

we are having this same discussion in another thread: if a bug is unlikely to happen, doesn't mean that there is no bug. A fix is a fix and should be backported to stable kernels.

Quoted 6 lines

No. Please read:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

There is clearly a list of conditions for a commit to be eligible for stable kernel trees. It's not "every fix".

I think you are putting these fixes into the ""This could be a problem..." type of things".

But as I see these fixes don't belong to this category, as they are clearing the exit path. This is a kind of fixes I want to see going to stable.

Which means that if we exit through that path, do we exit cleanly, e.g., without leaking? If the answer is "no", then this is a fix and should go to stable.

It belongs to "This could be a problem..." type, things like dev_err/dev_warn (first thing coming to my mind) or other non functional fixes.

Quoted 7 lines

Maybe this is a matter of opinion and different background. For the i2c side I'm in peace :-)

For the stable backport I'd love to hear another opinion.

Thanks, Jean!
Andi

Please let me know once you come to an agreement, then I'll submit a (hopefully) final version.

#6 lore raw
Quoted 38 lines · Heiner Kallweit
Quoted 37 lines · Andi Shyti

Hi Jean,

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

I wouldn't cc stable. For one thing, this patch doesn't fix a bug that actually bothers people. Error paths are rarely taken, and driver removal isn't that frequent either. Consequences are also rather harmless (one-time resource leak, race condition which is quite unlikely to trigger).

we are having this same discussion in another thread: if a bug is unlikely to happen, doesn't mean that there is no bug. A fix is a fix and should be backported to stable kernels.

Quoted 6 lines

No. Please read:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

There is clearly a list of conditions for a commit to be eligible for stable kernel trees. It's not "every fix".

I think you are putting these fixes into the ""This could be a problem..." type of things".

But as I see these fixes don't belong to this category, as they are clearing the exit path. This is a kind of fixes I want to see going to stable.

Which means that if we exit through that path, do we exit cleanly, e.g., without leaking? If the answer is "no", then this is a fix and should go to stable.

It belongs to "This could be a problem..." type, things like dev_err/dev_warn (first thing coming to my mind) or other non functional fixes.

Maybe this is a matter of opinion and different background. For the i2c side I'm in peace :-)

Quoted 8 lines
Quoted 4 lines

For the stable backport I'd love to hear another opinion.

Thanks, Jean!
Andi

Please let me know once you come to an agreement, then I'll submit a (hopefully) final version.

I think I'll split the patch, that should make dealing with it easier.