@@ -1696,23 +1696,6 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adap)
16961696}
16971697EXPORT_SYMBOL_GPL (i2c_add_numbered_adapter );
16981698
1699- static void i2c_do_del_adapter (struct i2c_driver * driver ,
1700- struct i2c_adapter * adapter )
1701- {
1702- struct i2c_client * client , * _n ;
1703-
1704- /* Remove the devices we created ourselves as the result of hardware
1705- * probing (using a driver's detect method) */
1706- list_for_each_entry_safe (client , _n , & driver -> clients , detected ) {
1707- if (client -> adapter == adapter ) {
1708- dev_dbg (& adapter -> dev , "Removing %s at 0x%x\n" ,
1709- client -> name , client -> addr );
1710- list_del (& client -> detected );
1711- i2c_unregister_device (client );
1712- }
1713- }
1714- }
1715-
17161699static int __unregister_client (struct device * dev , void * dummy )
17171700{
17181701 struct i2c_client * client = i2c_verify_client (dev );
@@ -1728,12 +1711,6 @@ static int __unregister_dummy(struct device *dev, void *dummy)
17281711 return 0 ;
17291712}
17301713
1731- static int __process_removed_adapter (struct device_driver * d , void * data )
1732- {
1733- i2c_do_del_adapter (to_i2c_driver (d ), data );
1734- return 0 ;
1735- }
1736-
17371714/**
17381715 * i2c_del_adapter - unregister I2C adapter
17391716 * @adap: the adapter being unregistered
@@ -1757,11 +1734,6 @@ void i2c_del_adapter(struct i2c_adapter *adap)
17571734 }
17581735
17591736 i2c_acpi_remove_space_handler (adap );
1760- /* Tell drivers about this removal */
1761- mutex_lock (& core_lock );
1762- bus_for_each_drv (& i2c_bus_type , NULL , adap ,
1763- __process_removed_adapter );
1764- mutex_unlock (& core_lock );
17651737
17661738 /* Remove devices instantiated from sysfs */
17671739 mutex_lock_nested (& adap -> userspace_clients_lock ,
@@ -1780,8 +1752,10 @@ void i2c_del_adapter(struct i2c_adapter *adap)
17801752 * we can't remove the dummy devices during the first pass: they
17811753 * could have been instantiated by real devices wishing to clean
17821754 * them up properly, so we give them a chance to do that first. */
1755+ mutex_lock (& core_lock );
17831756 device_for_each_child (& adap -> dev , NULL , __unregister_client );
17841757 device_for_each_child (& adap -> dev , NULL , __unregister_dummy );
1758+ mutex_unlock (& core_lock );
17851759
17861760 /* device name is gone after device_unregister */
17871761 dev_dbg (& adap -> dev , "adapter [%s] unregistered\n" , adap -> name );
@@ -2001,7 +1975,6 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
20011975 /* add the driver to the list of i2c drivers in the driver core */
20021976 driver -> driver .owner = owner ;
20031977 driver -> driver .bus = & i2c_bus_type ;
2004- INIT_LIST_HEAD (& driver -> clients );
20051978
20061979 /* When registration returns, the driver core
20071980 * will have called probe() for all matching-but-unbound devices.
@@ -2019,10 +1992,13 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
20191992}
20201993EXPORT_SYMBOL (i2c_register_driver );
20211994
2022- static int __process_removed_driver (struct device * dev , void * data )
1995+ static int __i2c_unregister_detected_client (struct device * dev , void * argp )
20231996{
2024- if (dev -> type == & i2c_adapter_type )
2025- i2c_do_del_adapter (data , to_i2c_adapter (dev ));
1997+ struct i2c_client * client = i2c_verify_client (dev );
1998+
1999+ if (client && client -> flags & I2C_CLIENT_AUTO )
2000+ i2c_unregister_device (client );
2001+
20262002 return 0 ;
20272003}
20282004
@@ -2033,7 +2009,12 @@ static int __process_removed_driver(struct device *dev, void *data)
20332009 */
20342010void i2c_del_driver (struct i2c_driver * driver )
20352011{
2036- i2c_for_each_dev (driver , __process_removed_driver );
2012+ mutex_lock (& core_lock );
2013+ /* Satisfy __must_check, function can't fail */
2014+ if (driver_for_each_device (& driver -> driver , NULL , NULL ,
2015+ __i2c_unregister_detected_client )) {
2016+ }
2017+ mutex_unlock (& core_lock );
20372018
20382019 driver_unregister (& driver -> driver );
20392020 pr_debug ("driver [%s] unregistered\n" , driver -> driver .name );
@@ -2460,6 +2441,7 @@ static int i2c_detect_address(struct i2c_client *temp_client,
24602441 /* Finally call the custom detection function */
24612442 memset (& info , 0 , sizeof (struct i2c_board_info ));
24622443 info .addr = addr ;
2444+ info .flags = I2C_CLIENT_AUTO ;
24632445 err = driver -> detect (temp_client , & info );
24642446 if (err ) {
24652447 /* -ENODEV is returned if the detection fails. We catch it
@@ -2486,9 +2468,7 @@ static int i2c_detect_address(struct i2c_client *temp_client,
24862468 dev_dbg (& adapter -> dev , "Creating %s at 0x%02x\n" ,
24872469 info .type , info .addr );
24882470 client = i2c_new_client_device (adapter , & info );
2489- if (!IS_ERR (client ))
2490- list_add_tail (& client -> detected , & driver -> clients );
2491- else
2471+ if (IS_ERR (client ))
24922472 dev_err (& adapter -> dev , "Failed creating %s at 0x%02x\n" ,
24932473 info .type , info .addr );
24942474 }
0 commit comments