I found that continuing without the check on null results in a kernel panic for a dereferenced null pointer.Why?!My logic here was that if the gpio is optional return null we return+static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev,This is wrong. You should not use this macro in most cases. And
+ struct i2c_adapter *adap)
+{
+ struct i2c_bus_recovery_info *rinfo = &dev->rinfo;
+
+ dev->gpio_scl = devm_gpiod_get_optional(dev->dev,
+ "scl",
+ GPIOD_OUT_HIGH);
+ if (IS_ERR_OR_NULL(dev->gpio_scl))
especially it breaks the logic behind _optional().
0.
_optional()*implies* that all rest calls will go fine and do nothing.
which is an okay status.You need something like
But this breaks if !CONFIG_GPIOLIB, which I keep forgetting. I've
never
quite wrapped my head around why that's the case.
But the probe function only bails out if this returns EPROBE_DEFER.
Not sure that's the best approach
desc = devm_gpiod_get_optional(...);
if (IS_ERR(desc))
return PTR_ERR(desc);