i2c: core: fix adapter probe deferral loop

Drivers must not probe defer after having registered devices as that
will trigger a probe loop if the devices bind to a driver (cf. commit
fbc35b45f9 ("Add documentation on meaning of -EPROBE_DEFER")).

Move the recovery initialisation, where the GPIO lookup may fail, before
registering the adapter to prevent this.

Fixes: 75820314de ("i2c: core: add generic I2C GPIO recovery")
Cc: stable@vger.kernel.org	# 5.9
Cc: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
This commit is contained in:
Johan Hovold 2026-05-11 16:37:09 +02:00 committed by Wolfram Sang
parent 2295d2bb10
commit 158efa411c

View File

@ -1562,6 +1562,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
adap->dev.type = &i2c_adapter_type;
device_initialize(&adap->dev);
res = i2c_init_recovery(adap);
if (res == -EPROBE_DEFER)
goto err_put_adap;
/*
* This adapter can be used as a parent immediately after device_add(),
* setup runtime-pm (especially ignore-children) before hand.
@ -1583,10 +1587,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
if (res)
goto out_reg;
res = i2c_init_recovery(adap);
if (res == -EPROBE_DEFER)
goto out_reg;
dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
/* create pre-declared device nodes */