diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 3ec04787a737..b7f5dbca9fac 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1815,6 +1815,13 @@ void i2c_del_adapter(struct i2c_adapter *adap) return; } + /* + * Prevent new clients from being instantiated via sysfs while the + * adapter is torn down. This drains any in-flight writers, so all + * clients will be caught by i2c_deregister_clients() below. + */ + device_remove_file(&adap->dev, &dev_attr_new_device); + i2c_acpi_remove_space_handler(adap); i2c_deregister_clients(adap); @@ -1826,8 +1833,6 @@ void i2c_del_adapter(struct i2c_adapter *adap) i2c_host_notify_irq_teardown(adap); - debugfs_remove_recursive(adap->debugfs); - /* wait until all references to the device are gone * * FIXME: This is old code and should ideally be replaced by an @@ -1839,6 +1844,9 @@ void i2c_del_adapter(struct i2c_adapter *adap) device_unregister(&adap->dev); wait_for_completion(&adap->dev_released); + /* clients use this directory as their debugfs parent */ + debugfs_remove_recursive(adap->debugfs); + /* free bus id */ mutex_lock(&core_lock); idr_remove(&i2c_adapter_idr, adap->nr);