Skip to content

Commit 4a00347

Browse files
jhovoldgregkh
authored andcommitted
i2c: core: fix adapter debugfs creation
[ Upstream commit 07d5fb5 ] 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). Note that failure to allocate the adapter name must now be handled explicitly as debugfs_create_dir() cannot handle a NULL name (unlike device_add() which returns an error). Fixes: 73febd7 ("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> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Stable-dep-of: ba14d7c ("i2c: core: fix adapter registration race") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ad4322d commit 4a00347

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

drivers/i2c/i2c-core-base.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,17 +1546,22 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15461546
goto out_list;
15471547
}
15481548

1549-
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
1549+
res = dev_set_name(&adap->dev, "i2c-%d", adap->nr);
1550+
if (res)
1551+
goto err_remove_irq_domain;
1552+
15501553
adap->dev.bus = &i2c_bus_type;
15511554
adap->dev.type = &i2c_adapter_type;
1552-
res = device_register(&adap->dev);
1555+
device_initialize(&adap->dev);
1556+
1557+
adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
1558+
1559+
res = device_add(&adap->dev);
15531560
if (res) {
15541561
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
1555-
goto err_put_adap;
1562+
goto err_remove_debugfs;
15561563
}
15571564

1558-
adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
1559-
15601565
res = i2c_setup_smbus_alert(adap);
15611566
if (res)
15621567
goto out_reg;
@@ -1597,13 +1602,13 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15971602

15981603
out_reg:
15991604
i2c_deregister_clients(adap);
1600-
debugfs_remove_recursive(adap->debugfs);
16011605
device_del(&adap->dev);
1602-
err_put_adap:
1606+
err_remove_debugfs:
1607+
debugfs_remove_recursive(adap->debugfs);
16031608
init_completion(&adap->dev_released);
16041609
put_device(&adap->dev);
16051610
wait_for_completion(&adap->dev_released);
1606-
1611+
err_remove_irq_domain:
16071612
i2c_host_notify_irq_teardown(adap);
16081613
out_list:
16091614
mutex_lock(&core_lock);

0 commit comments

Comments
 (0)