Skip to contentSkip to conversation

I2C: Make return value check more accurate and explicit for devm_pinctrl_get()

PATCH Applied Jinjie Ruan 4 participants 4 messages Aug 21, 2023 – Aug 25, 2023

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

PATCH v3 1/1 I2C: Make return value check more accurate and explicit for devm_pinctrl_get()

If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then recovery can't work, because we can't switch the I2C pins between the I2C controller and GPIO. So, it is quite correct to print "can't get pinctrl, bus recovery not supported" because the I2C bus can't be recovered without pinctrl.

The PTR_ERR() is also fine - because if pinctrl is not present and returns NULL, we'll end up returning zero, which is exactly what we want.

However, open code that with a more accurate message will be more explicit for NULL case when CONFIG_PINCTRL is not defined.

---
v3:
- Split into two if() statements instead of removing the NULL checks.
- Remove the fix tags.
- Update the commit title and message.
- Update to bring the author's name before.
v2:
- Remove NULL check instead of using IS_ERR_OR_NULL() to avoid leaving them behind.
- Update the commit title and message.

---
 drivers/i2c/busses/i2c-at91-master.c | 6 +++++-
 drivers/i2c/busses/i2c-imx.c         | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-at91-master.c +5 -1
index 94cff1cd527e..d311981d3e60 100644
@@ -831,7 +831,11 @@ static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
 	struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
 
 	rinfo->pinctrl = devm_pinctrl_get(&pdev->dev);
-	if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) {
+	if (!rinfo->pinctrl) {
+		dev_info(dev->dev, "pinctrl unavailable, bus recovery not supported\n");
+		return 0;
+	}
+	if (IS_ERR(rinfo->pinctrl)) {
 		dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n");
 		return PTR_ERR(rinfo->pinctrl);
 	}
drivers/i2c/busses/i2c-imx.c +5 -1
index 10e89586ca72..1775a79aeba2 100644
@@ -1388,7 +1388,11 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
 	struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo;
 
 	i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev);
-	if (!i2c_imx->pinctrl || IS_ERR(i2c_imx->pinctrl)) {
+	if (!i2c_imx->pinctrl) {
+		dev_info(&pdev->dev, "pinctrl unavailable, bus recovery not supported\n");
+		return 0;
+	}
+	if (IS_ERR(i2c_imx->pinctrl)) {
 		dev_info(&pdev->dev, "can't get pinctrl, bus recovery not supported\n");
 		return PTR_ERR(i2c_imx->pinctrl);
 	}
Signature · 1 line
2.34.1
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 27 lines · Jinjie Ruan

If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then recovery can't work, because we can't switch the I2C pins between the I2C controller and GPIO. So, it is quite correct to print "can't get pinctrl, bus recovery not supported" because the I2C bus can't be recovered without pinctrl.

The PTR_ERR() is also fine - because if pinctrl is not present and returns NULL, we'll end up returning zero, which is exactly what we want.

However, open code that with a more accurate message will be more explicit for NULL case when CONFIG_PINCTRL is not defined.

---
v3:
- Split into two if() statements instead of removing the NULL checks.
- Remove the fix tags.
- Update the commit title and message.
- Update to bring the author's name before.
v2:
- Remove NULL check instead of using IS_ERR_OR_NULL() to avoid leaving them behind.
- Update the commit title and message.

Quoted 4 lines
---
 drivers/i2c/busses/i2c-at91-master.c | 6 +++++-
 drivers/i2c/busses/i2c-imx.c         | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

for the i2c-imx.c

Thank you!

Regards,
Oleksij

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Reviewed-by
#2 lore raw

Hi,

Quoted 33 lines · Oleksij Rempel
Quoted 27 lines · Jinjie Ruan

If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then recovery can't work, because we can't switch the I2C pins between the I2C controller and GPIO. So, it is quite correct to print "can't get pinctrl, bus recovery not supported" because the I2C bus can't be recovered without pinctrl.

The PTR_ERR() is also fine - because if pinctrl is not present and returns NULL, we'll end up returning zero, which is exactly what we want.

However, open code that with a more accurate message will be more explicit for NULL case when CONFIG_PINCTRL is not defined.

---
v3:
- Split into two if() statements instead of removing the NULL checks.
- Remove the fix tags.
- Update the commit title and message.
- Update to bring the author's name before.
v2:
- Remove NULL check instead of using IS_ERR_OR_NULL() to avoid leaving them behind.
- Update the commit title and message.

Quoted 4 lines
---
 drivers/i2c/busses/i2c-at91-master.c | 6 +++++-
 drivers/i2c/busses/i2c-imx.c         | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
Quoted 3 lines

for the i2c-imx.c

For some reason lore+lei failed to deliver this message to my inbox :/

Anyway, looks good!

Thank you, Jinjie for following up.
Andi

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Applied
#3 lore raw
In reply to Jinjie Ruan
Quoted 10 lines · Jinjie Ruan

If pinctrl is not available (thus devm_pinctrl_get() returns NULL) then recovery can't work, because we can't switch the I2C pins between the I2C controller and GPIO. So, it is quite correct to print "can't get pinctrl, bus recovery not supported" because the I2C bus can't be recovered without pinctrl.

The PTR_ERR() is also fine - because if pinctrl is not present and returns NULL, we'll end up returning zero, which is exactly what we want.

Quoted 8 lines

However, open code that with a more accurate message will be more explicit for NULL case when CONFIG_PINCTRL is not defined.

Applied to for-next, thanks!