i2c: acpi: put device when verifying client fails
Subsystems (4)
RFC PATCH 1/1 i2c: acpi: put device when verifying client fails
From: Wolfram Sang <[email protected]>
i2c_verify_client() can fail, so we need to put the device when that happens.
---
RFC because I don't know if it can be that the returned dev is not an i2c_client. Yet, since it can happen theoretically, I think we should have the checks.
drivers/i2c/i2c-core-acpi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/i2c/i2c-core-acpi.c +9 -1
@@ -394,9 +394,17 @@ EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);static struct i2c_client *i2c_acpi_find_client_by_adev (struct acpi_device *adev) {struct device *dev; +struct i2c_client *client; dev =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); -return dev ?i2c_verify_client (dev) :NULL ; +if (!dev) +return NULL ; + + client =i2c_verify_client (dev); +if (!client) +put_device (dev); + +return client; } static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,
Signature · 1 line
2.20.1
Quoted 8 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")Reported-by Geert Uytterhoeven <[email protected]>Signed-off-by Wolfram Sang <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Andy Shevchenko
NAKQuoted 4 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.
NAK, this will do double put and messing up with reference counters. Besides the fact, that device may disappear after looking up which leads us to even more problems.
See how i2c_acpi_find_client_by_adev() is used in callers.
Quoted 39 lines
Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")Reported-by Geert Uytterhoeven <[email protected]>Signed-off-by Wolfram Sang <[email protected]>---
RFC because I don't know if it can be that the returned dev is not an
i2c_client. Yet, since it can happen theoretically, I think we should have the checks.drivers/i2c/i2c-core-acpi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/i2c/i2c-core-acpi.c +9
-1@@ -394,9 +394,17 @@ EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);static struct i2c_client *i2c_acpi_find_client_by_adev (struct acpi_device *adev) {struct device *dev; +struct i2c_client *client; dev =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); -return dev ?i2c_verify_client (dev) :NULL ; +if (!dev) +return NULL ; + + client =i2c_verify_client (dev); +if (!client) +put_device (dev); + +return client; } static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,Signature · 1 line
2.20.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.NAK, this will do double put and messing up with reference counters. Besides the fact, that device may disappear after looking up which leads us to even more problems.
See how
i2c_acpi_find_client_by_adev()is used in callers.
Perhaps proper "fix" is to add the explanation to a comment in the code to prevent false positive reports in the future?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.
Quoted 8 lines
Quoted 5 lines
NAK, this will do double put and messing up with reference counters. Besides the fact, that device may disappear after looking up which leads us to even more problems.
See how
i2c_acpi_find_client_by_adev()is used in callers.Perhaps proper "fix" is to add the explanation to a comment in the code to prevent false positive reports in the future?
Ah, sorry, I need to read it more carefully...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.
I hope it's not a CoVID-19 makes me mistakenly commented in the first place. :-)
So, theoretically below is possible, but practically it's doubtful.
The I2CSerialBusV2() ACPI resource can be present solely in I²C slave device nodes according to the specification. However, we might have two possible cases
a) screwed up ACPI table;
b) I²C master which in turn is I²C slave.
While a) has been so far unseen, b) case sounds like plasible for I²C muxes IIUC.
So, I agree with the patch, and sorry for the first reaction.
Quoted 38 lines
Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")Reported-by Geert Uytterhoeven <[email protected]>Signed-off-by Wolfram Sang <[email protected]>---
RFC because I don't know if it can be that the returned dev is not an
i2c_client. Yet, since it can happen theoretically, I think we should have the checks.drivers/i2c/i2c-core-acpi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/i2c/i2c-core-acpi.c +9
-1@@ -394,9 +394,17 @@ EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);static struct i2c_client *i2c_acpi_find_client_by_adev (struct acpi_device *adev) {struct device *dev; +struct i2c_client *client; dev =bus_find_device_by_acpi_dev (&i2c_bus_type, adev); -return dev ?i2c_verify_client (dev) :NULL ; +if (!dev) +return NULL ; + + client =i2c_verify_client (dev); +if (!client) +put_device (dev); + +return client; } static int i2c_acpi_notify(struct notifier_block *nb, unsigned long value,Signature · 1 line
2.20.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.
Quoted 8 lines
Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")Reported-by Geert Uytterhoeven <[email protected]>Signed-off-by Wolfram Sang <[email protected]>---
RFC because I don't know if it can be that the returned dev is not an
i2c_client. Yet, since it can happen theoretically, I think we should have the checks.
I agree,
Wolfram Sang
AppliedQuoted 8 lines · Wolfram Sang
From: Wolfram Sang <[email protected]>
i2c_verify_client()can fail, so we need to put the device when that happens.Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")Reported-by Geert Uytterhoeven <[email protected]>Signed-off-by Wolfram Sang <[email protected]>
Applied to for-current, thanks!