Skip to contentSkip to conversation

i2c: acpi: put device when verifying client fails

RFC PATCH Applied Wolfram Sang 4 participants 8 messages Mar 12, 2020 – Mar 13, 2020

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

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.

Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")

---

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
index 8f3dbc97a057..8b0ff780919b 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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")

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
#2 lore raw
In reply to Wolfram Sang
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.

Quoted 39 lines
Fixes 525e6fabeae2 ("i2c / ACPI: add support for ACPI reconfigure notifications")

---

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
index 8f3dbc97a057..8b0ff780919b 100644
@@ -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
#3 lore raw
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
#4 lore raw
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
Reviewed-by on v1 1/1
#5 lore raw
In reply to Wolfram Sang
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")

---

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
index 8f3dbc97a057..8b0ff780919b 100644
@@ -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
Acked-by on v1 1/1
#6 lore raw
In reply to Wolfram Sang
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")

---

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,