* [PATCH 0/8] i2c: core: adapter registration fixes
@ 2026-05-05 14:25 Johan Hovold
2026-05-05 14:25 ` [PATCH 1/8] i2c: core: fix hang on adapter registration failure Johan Hovold
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold
This series fixes a number of bugs related to adapter registration found
through inspection (when looking into addressing i2c lifetime issues).
Included are also two related cleanups.
Johan
Johan Hovold (8):
i2c: core: fix hang on adapter registration failure
i2c: core: fix adapter probe deferral loop
i2c: core: fix adapter debugfs creation
i2c: core: disable runtime PM on adapter registration failure
i2c: core: fix adapter registration race
i2c: core: fix adapter deregistration race
i2c: core: clean up bus id allocation
i2c: core: clean up adapter registration error label
drivers/i2c/i2c-core-base.c | 164 ++++++++++++++++++++----------------
1 file changed, 90 insertions(+), 74 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/8] i2c: core: fix hang on adapter registration failure
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 2/8] i2c: core: fix adapter probe deferral loop Johan Hovold
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang
Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold, stable,
Phil Reid
Clients may be registered from bus notifier callbacks when the adapter
is registered. On a subsequent error during registration, the adapter
references taken by such clients prevent the wait for the references to
be released from ever completing.
Fix this by refactoring client deregistration and deregistering also on
late adapter registration failures.
Fixes: f8756c67b3de ("i2c: core: call of_i2c_setup_smbus_alert in i2c_register_adapter")
Cc: stable@vger.kernel.org # 4.15
Cc: Phil Reid <preid@electromag.com.au>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 49 ++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9c46147e3506..7cec3f276e13 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -63,6 +63,7 @@
static DEFINE_MUTEX(core_lock);
static DEFINE_IDR(i2c_adapter_idr);
+static void i2c_deregister_clients(struct i2c_adapter *adap);
static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
static DEFINE_STATIC_KEY_FALSE(i2c_trace_msg_key);
@@ -1605,6 +1606,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
return 0;
out_reg:
+ i2c_deregister_clients(adap);
debugfs_remove_recursive(adap->debugfs);
init_completion(&adap->dev_released);
device_unregister(&adap->dev);
@@ -1744,29 +1746,10 @@ static int __process_removed_adapter(struct device_driver *d, void *data)
return 0;
}
-/**
- * i2c_del_adapter - unregister I2C adapter
- * @adap: the adapter being unregistered
- * Context: can sleep
- *
- * This unregisters an I2C adapter which was previously registered
- * by @i2c_add_adapter or @i2c_add_numbered_adapter.
- */
-void i2c_del_adapter(struct i2c_adapter *adap)
+static void i2c_deregister_clients(struct i2c_adapter *adap)
{
- struct i2c_adapter *found;
struct i2c_client *client, *next;
- /* First make sure that this adapter was ever added */
- mutex_lock(&core_lock);
- found = idr_find(&i2c_adapter_idr, adap->nr);
- mutex_unlock(&core_lock);
- if (found != adap) {
- pr_debug("attempting to delete unregistered adapter [%s]\n", adap->name);
- return;
- }
-
- i2c_acpi_remove_space_handler(adap);
/* Tell drivers about this removal */
mutex_lock(&core_lock);
bus_for_each_drv(&i2c_bus_type, NULL, adap,
@@ -1792,6 +1775,32 @@ void i2c_del_adapter(struct i2c_adapter *adap)
* them up properly, so we give them a chance to do that first. */
device_for_each_child(&adap->dev, NULL, __unregister_client);
device_for_each_child(&adap->dev, NULL, __unregister_dummy);
+}
+
+/**
+ * i2c_del_adapter - unregister I2C adapter
+ * @adap: the adapter being unregistered
+ * Context: can sleep
+ *
+ * This unregisters an I2C adapter which was previously registered
+ * by @i2c_add_adapter or @i2c_add_numbered_adapter.
+ */
+void i2c_del_adapter(struct i2c_adapter *adap)
+{
+ struct i2c_adapter *found;
+
+ /* First make sure that this adapter was ever added */
+ mutex_lock(&core_lock);
+ found = idr_find(&i2c_adapter_idr, adap->nr);
+ mutex_unlock(&core_lock);
+ if (found != adap) {
+ pr_debug("attempting to delete unregistered adapter [%s]\n", adap->name);
+ return;
+ }
+
+ i2c_acpi_remove_space_handler(adap);
+
+ i2c_deregister_clients(adap);
/* device name is gone after device_unregister */
dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/8] i2c: core: fix adapter probe deferral loop
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
2026-05-05 14:25 ` [PATCH 1/8] i2c: core: fix hang on adapter registration failure Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 3/8] i2c: core: fix adapter debugfs creation Johan Hovold
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang
Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold, stable,
Codrin Ciubotariu
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
fbc35b45f9f6 ("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: 75820314de26 ("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>
---
drivers/i2c/i2c-core-base.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 7cec3f276e13..2832e1aa0ca3 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -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.
@@ -1574,8 +1578,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
res = device_add(&adap->dev);
if (res) {
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
- put_device(&adap->dev);
- goto out_list;
+ goto err_put_adap;
}
adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
@@ -1584,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 */
@@ -1608,8 +1607,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
out_reg:
i2c_deregister_clients(adap);
debugfs_remove_recursive(adap->debugfs);
+ device_del(&adap->dev);
+err_put_adap:
init_completion(&adap->dev_released);
- device_unregister(&adap->dev);
+ put_device(&adap->dev);
wait_for_completion(&adap->dev_released);
out_list:
mutex_lock(&core_lock);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/8] i2c: core: fix adapter debugfs creation
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
2026-05-05 14:25 ` [PATCH 1/8] i2c: core: fix hang on adapter registration failure Johan Hovold
2026-05-05 14:25 ` [PATCH 2/8] i2c: core: fix adapter probe deferral loop Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 4/8] i2c: core: disable runtime PM on adapter registration failure Johan Hovold
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold, stable
Clients can be registered from bus notifier callbacks so the debugfs
directory needs to be created before registering the adapter as clients
use that directory as their debugfs parent.
Move debugfs creation before adapter registration to avoid having
clients create their debugfs directories in the debugfs root (which is
also more likely to fail due to name collisions).
Fixes: 73febd775bdb ("i2c: create debugfs entry per adapter")
Cc: stable@vger.kernel.org # 6.8
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 2832e1aa0ca3..6f198d1325a6 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1575,14 +1575,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
pm_suspend_ignore_children(&adap->dev, true);
pm_runtime_enable(&adap->dev);
+ adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
+
res = device_add(&adap->dev);
if (res) {
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
- goto err_put_adap;
+ goto err_remove_debugfs;
}
- adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
-
res = i2c_setup_smbus_alert(adap);
if (res)
goto out_reg;
@@ -1606,8 +1606,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
out_reg:
i2c_deregister_clients(adap);
- debugfs_remove_recursive(adap->debugfs);
device_del(&adap->dev);
+err_remove_debugfs:
+ debugfs_remove_recursive(adap->debugfs);
err_put_adap:
init_completion(&adap->dev_released);
put_device(&adap->dev);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/8] i2c: core: disable runtime PM on adapter registration failure
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
` (2 preceding siblings ...)
2026-05-05 14:25 ` [PATCH 3/8] i2c: core: fix adapter debugfs creation Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 5/8] i2c: core: fix adapter registration race Johan Hovold
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang
Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold,
Codrin Ciubotariu
Runtime PM is disabled by driver core when deregistering a device (and
on registration failure) but add an explicit disable to balance the
enable call when adapter registration fails for symmetry.
Fixes: 23a698fe65ec ("i2c: core: treat EPROBE_DEFER when acquiring SCL/SDA GPIOs")
Cc: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 6f198d1325a6..31f7d43e4ab5 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1609,6 +1609,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
device_del(&adap->dev);
err_remove_debugfs:
debugfs_remove_recursive(adap->debugfs);
+ pm_runtime_disable(&adap->dev);
err_put_adap:
init_completion(&adap->dev_released);
put_device(&adap->dev);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/8] i2c: core: fix adapter registration race
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
` (3 preceding siblings ...)
2026-05-05 14:25 ` [PATCH 4/8] i2c: core: disable runtime PM on adapter registration failure Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 6/8] i2c: core: fix adapter deregistration race Johan Hovold
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold, stable
Adapters can be looked up based on their id using i2c_get_adapter()
which takes a reference to the embedded struct device.
Make sure that the adapter (including its struct device) has been
initialised before adding it to the IDR to avoid accessing uninitialised
data which could, for example, lead to NULL-pointer dereferences or
use-after-free.
Fixes: 6e13e6418418 ("i2c: Add i2c_add_numbered_adapter()")
Cc: stable@vger.kernel.org # 2.6.22
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 31f7d43e4ab5..be909d6bc776 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1587,6 +1587,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
if (res)
goto out_reg;
+ mutex_lock(&core_lock);
+ idr_replace(&i2c_adapter_idr, adap, adap->nr);
+ mutex_unlock(&core_lock);
+
dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
/* create pre-declared device nodes */
@@ -1633,7 +1637,7 @@ static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
int id;
mutex_lock(&core_lock);
- id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, GFP_KERNEL);
+ id = idr_alloc(&i2c_adapter_idr, NULL, adap->nr, adap->nr + 1, GFP_KERNEL);
mutex_unlock(&core_lock);
if (WARN(id < 0, "couldn't get idr"))
return id == -ENOSPC ? -EBUSY : id;
@@ -1667,7 +1671,7 @@ int i2c_add_adapter(struct i2c_adapter *adapter)
}
mutex_lock(&core_lock);
- id = idr_alloc(&i2c_adapter_idr, adapter,
+ 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"))
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/8] i2c: core: fix adapter deregistration race
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
` (4 preceding siblings ...)
2026-05-05 14:25 ` [PATCH 5/8] i2c: core: fix adapter registration race Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 7/8] i2c: core: clean up bus id allocation Johan Hovold
2026-05-05 14:25 ` [PATCH 8/8] i2c: core: clean up adapter registration error label Johan Hovold
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang
Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold, stable,
Jean Delvare
Adapters can be looked up by their id using i2c_get_adapter() which
takes a reference to the embedded struct device.
Remove the adapter from the IDR before tearing it down during
deregistration to make sure its resources are not accessed after having
been freed (e.g. the device name).
Fixes: 35fc37f81881 ("i2c: Limit core locking to the necessary sections")
Cc: stable@vger.kernel.org # 2.6.31
Cc: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index be909d6bc776..6209c5587e99 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1799,6 +1799,8 @@ void i2c_del_adapter(struct i2c_adapter *adap)
/* First make sure that this adapter was ever added */
mutex_lock(&core_lock);
found = idr_find(&i2c_adapter_idr, adap->nr);
+ if (found == adap)
+ idr_replace(&i2c_adapter_idr, NULL, adap->nr);
mutex_unlock(&core_lock);
if (found != adap) {
pr_debug("attempting to delete unregistered adapter [%s]\n", adap->name);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/8] i2c: core: clean up bus id allocation
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
` (5 preceding siblings ...)
2026-05-05 14:25 ` [PATCH 6/8] i2c: core: fix adapter deregistration race Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
2026-05-05 14:25 ` [PATCH 8/8] i2c: core: clean up adapter registration error label Johan Hovold
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold
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@kernel.org>
---
drivers/i2c/i2c-core-base.c | 86 ++++++++++++++++++-------------------
1 file changed, 42 insertions(+), 44 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 6209c5587e99..27cd9ca0ae81 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1517,23 +1517,48 @@ int i2c_handle_smbus_host_notify(struct i2c_adapter *adap, unsigned short addr)
}
EXPORT_SYMBOL_GPL(i2c_handle_smbus_host_notify);
+static int i2c_allocate_adapter_id(struct i2c_adapter *adap)
+{
+ int id, start, end;
+
+ if (adap->nr == -1) {
+ start = __i2c_first_dynamic_bus_num;
+ end = 0;
+ } else {
+ start = adap->nr;
+ end = adap->nr + 1;
+ }
+
+ mutex_lock(&core_lock);
+ id = idr_alloc(&i2c_adapter_idr, NULL, start, end, GFP_KERNEL);
+ mutex_unlock(&core_lock);
+ if (id < 0) {
+ if (adap->nr != -1 && id == -ENOSPC)
+ id = -EBUSY;
+ pr_err("adapter '%s': failed to allocate id: %d\n", adap->name, id);
+ return id;
+ }
+
+ adap->nr = id;
+
+ return 0;
+}
+
static int i2c_register_adapter(struct i2c_adapter *adap)
{
- int res = -EINVAL;
+ int res;
/* Can't register until after driver model init */
- if (WARN_ON(!is_registered)) {
- res = -EAGAIN;
- goto out_list;
- }
+ if (WARN_ON(!is_registered))
+ return -EAGAIN;
/* Sanity checks */
if (WARN(!adap->name[0], "i2c adapter has no name"))
- goto out_list;
+ return -EINVAL;
if (!adap->algo) {
pr_err("adapter '%s': no algo supplied!\n", adap->name);
- goto out_list;
+ return -EINVAL;
}
if (!adap->lock_ops)
@@ -1554,9 +1579,13 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
if (res) {
pr_err("adapter '%s': can't create Host Notify IRQs (%d)\n",
adap->name, res);
- goto out_list;
+ return res;
}
+ res = i2c_allocate_adapter_id(adap);
+ if (res)
+ return res;
+
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
adap->dev.bus = &i2c_bus_type;
adap->dev.type = &i2c_adapter_type;
@@ -1618,31 +1647,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
init_completion(&adap->dev_released);
put_device(&adap->dev);
wait_for_completion(&adap->dev_released);
-out_list:
- mutex_lock(&core_lock);
- idr_remove(&i2c_adapter_idr, adap->nr);
- mutex_unlock(&core_lock);
- return res;
-}
-
-/**
- * __i2c_add_numbered_adapter - i2c_add_numbered_adapter where nr is never -1
- * @adap: the adapter to register (with adap->nr initialized)
- * Context: can sleep
- *
- * See i2c_add_numbered_adapter() for details.
- */
-static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
-{
- int id;
mutex_lock(&core_lock);
- id = idr_alloc(&i2c_adapter_idr, NULL, adap->nr, adap->nr + 1, GFP_KERNEL);
+ idr_remove(&i2c_adapter_idr, adap->nr);
mutex_unlock(&core_lock);
- if (WARN(id < 0, "couldn't get idr"))
- return id == -ENOSPC ? -EBUSY : id;
- return i2c_register_adapter(adap);
+ return res;
}
/**
@@ -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);
-
- return __i2c_add_numbered_adapter(adap);
+ return i2c_register_adapter(adap);
}
EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/8] i2c: core: clean up adapter registration error label
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
` (6 preceding siblings ...)
2026-05-05 14:25 ` [PATCH 7/8] i2c: core: clean up bus id allocation Johan Hovold
@ 2026-05-05 14:25 ` Johan Hovold
7 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2026-05-05 14:25 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Andi Shyti, linux-i2c, linux-kernel, Johan Hovold
Clean up the adapter registration error labels by making sure that also
the last one is named after what it does.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/i2c/i2c-core-base.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 27cd9ca0ae81..8139e1531734 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1614,7 +1614,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
res = i2c_setup_smbus_alert(adap);
if (res)
- goto out_reg;
+ goto err_deregister_clients;
mutex_lock(&core_lock);
idr_replace(&i2c_adapter_idr, adap, adap->nr);
@@ -1637,7 +1637,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
return 0;
-out_reg:
+err_deregister_clients:
i2c_deregister_clients(adap);
device_del(&adap->dev);
err_remove_debugfs:
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-05 14:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-05 14:25 [PATCH 0/8] i2c: core: adapter registration fixes Johan Hovold
2026-05-05 14:25 ` [PATCH 1/8] i2c: core: fix hang on adapter registration failure Johan Hovold
2026-05-05 14:25 ` [PATCH 2/8] i2c: core: fix adapter probe deferral loop Johan Hovold
2026-05-05 14:25 ` [PATCH 3/8] i2c: core: fix adapter debugfs creation Johan Hovold
2026-05-05 14:25 ` [PATCH 4/8] i2c: core: disable runtime PM on adapter registration failure Johan Hovold
2026-05-05 14:25 ` [PATCH 5/8] i2c: core: fix adapter registration race Johan Hovold
2026-05-05 14:25 ` [PATCH 6/8] i2c: core: fix adapter deregistration race Johan Hovold
2026-05-05 14:25 ` [PATCH 7/8] i2c: core: clean up bus id allocation Johan Hovold
2026-05-05 14:25 ` [PATCH 8/8] i2c: core: clean up adapter registration error label Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox