Skip to contentSkip to conversation

i2c: core: Propagate all possible errors when requesting recovery GPIOs

PATCH In review Andy Shevchenko 1 participant 4 messages Feb 12, 2025 – Jan 19

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

PATCH 1/1 i2c: core: Propagate all possible errors when requesting recovery GPIOs

If GPIO is available but we can't get it by some other, than deferred probe, reason, propagate it to the caller.

No functional change since i2c_register_adapter() still cares only about deferred probe.

---
 drivers/i2c/i2c-core-base.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/i2c/i2c-core-base.c +16 -12
index 35a221e2c11c..8c0d8793a2c2 100644
@@ -374,19 +374,20 @@ static int i2c_gpio_init_generic_recovery(struct i2c_adapter *adap)
 	 * GPIO recovery is available
 	 */
 	if (!bri->scl_gpiod) {
-		gpiod = devm_gpiod_get(dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN);
-		if (PTR_ERR(gpiod) == -EPROBE_DEFER) {
-			ret  = -EPROBE_DEFER;
+		gpiod = devm_gpiod_get_optional(dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN);
+		if (IS_ERR(gpiod)) {
+			ret = PTR_ERR(gpiod);
 			goto cleanup_pinctrl_state;
 		}
-		if (!IS_ERR(gpiod)) {
+
+		if (gpiod) {
 			bri->scl_gpiod = gpiod;
 			bri->recover_bus = i2c_generic_scl_recovery;
 			dev_info(dev, "using generic GPIOs for recovery\n");
 		}
 	}
 
-	/* SDA GPIOD line is optional, so we care about DEFER only */
+	/* SDA GPIO line is optional */
 	if (!bri->sda_gpiod) {
 		/*
 		 * We have SCL. Pull SCL low and wait a bit so that SDA glitches
@@ -394,18 +395,19 @@ static int i2c_gpio_init_generic_recovery(struct i2c_adapter *adap)
 		 */
 		gpiod_direction_output(bri->scl_gpiod, 0);
 		udelay(10);
-		gpiod = devm_gpiod_get(dev, "sda", GPIOD_IN);
+
+		gpiod = devm_gpiod_get_optional(dev, "sda", GPIOD_IN);
 
 		/* Wait a bit in case of a SDA glitch, and then release SCL. */
 		udelay(10);
 		gpiod_direction_output(bri->scl_gpiod, 1);
 
-		if (PTR_ERR(gpiod) == -EPROBE_DEFER) {
-			ret = -EPROBE_DEFER;
+		if (IS_ERR(gpiod)) {
+			ret = PTR_ERR(gpiod);
 			goto cleanup_pinctrl_state;
 		}
-		if (!IS_ERR(gpiod))
-			bri->sda_gpiod = gpiod;
+
+		bri->sda_gpiod = gpiod;
 	}
 
 cleanup_pinctrl_state:
@@ -427,12 +429,14 @@ static int i2c_init_recovery(struct i2c_adapter *adap)
 	struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
 	bool is_error_level = true;
 	char *err_str;
+	int ret;
 
 	if (!bri)
 		return 0;
 
-	if (i2c_gpio_init_recovery(adap) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
+	ret = i2c_gpio_init_recovery(adap);
+	if (ret)
+		return ret;
 
 	if (!bri->recover_bus) {
 		err_str = "no suitable method provided";
Signature · 1 line
2.45.1.3035.g276e886db78b
#1 lore raw
Quoted 5 lines · Andy Shevchenko

If GPIO is available but we can't get it by some other, than deferred probe, reason, propagate it to the caller.

No functional change since i2c_register_adapter() still cares only about deferred probe.

Any comment on this? It's a month passed without any reaction...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

If GPIO is available but we can't get it by some other, than deferred probe, reason, propagate it to the caller.

No functional change since i2c_register_adapter() still cares only about deferred probe.

Any comment on this? It's a month passed without any reaction...

Yet another ping...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

If GPIO is available but we can't get it by some other, than deferred probe, reason, propagate it to the caller.

No functional change since i2c_register_adapter() still cares only about deferred probe.

Any comment on this? It's a month passed without any reaction...

Yet another ping...

So, can this be applied or should I do something about it?

Signature · 2 lines
With Best Regards,
Andy Shevchenko