Re: [PATCH 7/8] i2c: core: clean up bus id allocation
From: Johan Hovold
Date: Wed May 06 2026 - 08:39:29 EST
On Tue, May 05, 2026 at 04:25:46PM +0200, Johan Hovold wrote:
> Clean up bus id allocation by using a common helper and deferring it
> until it is needed during adapter registration.
>
> Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
> @@ -1665,17 +1675,8 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
> int id;
>
> id = of_alias_get_id(dev->of_node, "i2c");
> - if (id >= 0) {
> - adapter->nr = id;
> - return __i2c_add_numbered_adapter(adapter);
> - }
> -
> - mutex_lock(&core_lock);
> - id = idr_alloc(&i2c_adapter_idr, NULL,
> - __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
> - mutex_unlock(&core_lock);
> - if (WARN(id < 0, "couldn't get idr"))
> - return id;
> + if (id < 0)
> + id = -1;
>
> adapter->nr = id;
>
> @@ -1708,10 +1709,7 @@ EXPORT_SYMBOL(i2c_add_adapter);
> */
> int i2c_add_numbered_adapter(struct i2c_adapter *adap)
> {
> - if (adap->nr == -1) /* -1 means dynamically assign bus id */
> - return i2c_add_adapter(adap);
Sashiko also flagged this a potential issue -- needs to be kept for the
alias lookup.
> -
> - return __i2c_add_numbered_adapter(adap);
> + return i2c_register_adapter(adap);
Johan