Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'i2c-for-6.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux

Pull i2c reverts from Wolfram Sang:
"It turned out the new mechanism for handling created devices does not
handle all muxing cases.

Revert the changes to give a proper solution more time"

* tag 'i2c-for-6.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux:
Revert "i2c: Replace list-based mechanism for handling auto-detected clients"
Revert "i2c: Replace list-based mechanism for handling userspace-created clients"

+84 -41
+76 -39
drivers/i2c/i2c-core-base.c
··· 1300 1300 info.flags |= I2C_CLIENT_SLAVE; 1301 1301 } 1302 1302 1303 - info.flags |= I2C_CLIENT_USER; 1304 - 1305 1303 client = i2c_new_client_device(adap, &info); 1306 1304 if (IS_ERR(client)) 1307 1305 return PTR_ERR(client); 1308 1306 1307 + /* Keep track of the added device */ 1308 + mutex_lock(&adap->userspace_clients_lock); 1309 + list_add_tail(&client->detected, &adap->userspace_clients); 1310 + mutex_unlock(&adap->userspace_clients_lock); 1309 1311 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", 1310 1312 info.type, info.addr); 1311 1313 1312 1314 return count; 1313 1315 } 1314 1316 static DEVICE_ATTR_WO(new_device); 1315 - 1316 - static int __i2c_find_user_addr(struct device *dev, const void *addrp) 1317 - { 1318 - struct i2c_client *client = i2c_verify_client(dev); 1319 - unsigned short addr = *(unsigned short *)addrp; 1320 - 1321 - return client && client->flags & I2C_CLIENT_USER && 1322 - i2c_encode_flags_to_addr(client) == addr; 1323 - } 1324 1317 1325 1318 /* 1326 1319 * And of course let the users delete the devices they instantiated, if ··· 1329 1336 const char *buf, size_t count) 1330 1337 { 1331 1338 struct i2c_adapter *adap = to_i2c_adapter(dev); 1332 - struct device *child_dev; 1339 + struct i2c_client *client, *next; 1333 1340 unsigned short addr; 1334 1341 char end; 1335 1342 int res; ··· 1345 1352 return -EINVAL; 1346 1353 } 1347 1354 1348 - mutex_lock(&core_lock); 1349 1355 /* Make sure the device was added through sysfs */ 1350 - child_dev = device_find_child(&adap->dev, &addr, __i2c_find_user_addr); 1351 - if (child_dev) { 1352 - i2c_unregister_device(i2c_verify_client(child_dev)); 1353 - put_device(child_dev); 1354 - } else { 1355 - dev_err(dev, "Can't find userspace-created device at %#x\n", addr); 1356 - count = -ENOENT; 1357 - } 1358 - mutex_unlock(&core_lock); 1356 + res = -ENOENT; 1357 + mutex_lock_nested(&adap->userspace_clients_lock, 1358 + i2c_adapter_depth(adap)); 1359 + list_for_each_entry_safe(client, next, &adap->userspace_clients, 1360 + detected) { 1361 + if (i2c_encode_flags_to_addr(client) == addr) { 1362 + dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", 1363 + "delete_device", client->name, client->addr); 1359 1364 1360 - return count; 1365 + list_del(&client->detected); 1366 + i2c_unregister_device(client); 1367 + res = count; 1368 + break; 1369 + } 1370 + } 1371 + mutex_unlock(&adap->userspace_clients_lock); 1372 + 1373 + if (res < 0) 1374 + dev_err(dev, "%s: Can't find device in list\n", 1375 + "delete_device"); 1376 + return res; 1361 1377 } 1362 1378 static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL, 1363 1379 delete_device_store); ··· 1537 1535 adap->locked_flags = 0; 1538 1536 rt_mutex_init(&adap->bus_lock); 1539 1537 rt_mutex_init(&adap->mux_lock); 1538 + mutex_init(&adap->userspace_clients_lock); 1539 + INIT_LIST_HEAD(&adap->userspace_clients); 1540 1540 1541 1541 /* Set default timeout to 1 second if not already set */ 1542 1542 if (adap->timeout == 0) ··· 1704 1700 } 1705 1701 EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); 1706 1702 1703 + static void i2c_do_del_adapter(struct i2c_driver *driver, 1704 + struct i2c_adapter *adapter) 1705 + { 1706 + struct i2c_client *client, *_n; 1707 + 1708 + /* Remove the devices we created ourselves as the result of hardware 1709 + * probing (using a driver's detect method) */ 1710 + list_for_each_entry_safe(client, _n, &driver->clients, detected) { 1711 + if (client->adapter == adapter) { 1712 + dev_dbg(&adapter->dev, "Removing %s at 0x%x\n", 1713 + client->name, client->addr); 1714 + list_del(&client->detected); 1715 + i2c_unregister_device(client); 1716 + } 1717 + } 1718 + } 1719 + 1707 1720 static int __unregister_client(struct device *dev, void *dummy) 1708 1721 { 1709 1722 struct i2c_client *client = i2c_verify_client(dev); ··· 1736 1715 return 0; 1737 1716 } 1738 1717 1718 + static int __process_removed_adapter(struct device_driver *d, void *data) 1719 + { 1720 + i2c_do_del_adapter(to_i2c_driver(d), data); 1721 + return 0; 1722 + } 1723 + 1739 1724 /** 1740 1725 * i2c_del_adapter - unregister I2C adapter 1741 1726 * @adap: the adapter being unregistered ··· 1753 1726 void i2c_del_adapter(struct i2c_adapter *adap) 1754 1727 { 1755 1728 struct i2c_adapter *found; 1729 + struct i2c_client *client, *next; 1756 1730 1757 1731 /* First make sure that this adapter was ever added */ 1758 1732 mutex_lock(&core_lock); ··· 1765 1737 } 1766 1738 1767 1739 i2c_acpi_remove_space_handler(adap); 1740 + /* Tell drivers about this removal */ 1741 + mutex_lock(&core_lock); 1742 + bus_for_each_drv(&i2c_bus_type, NULL, adap, 1743 + __process_removed_adapter); 1744 + mutex_unlock(&core_lock); 1745 + 1746 + /* Remove devices instantiated from sysfs */ 1747 + mutex_lock_nested(&adap->userspace_clients_lock, 1748 + i2c_adapter_depth(adap)); 1749 + list_for_each_entry_safe(client, next, &adap->userspace_clients, 1750 + detected) { 1751 + dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, 1752 + client->addr); 1753 + list_del(&client->detected); 1754 + i2c_unregister_device(client); 1755 + } 1756 + mutex_unlock(&adap->userspace_clients_lock); 1768 1757 1769 1758 /* Detach any active clients. This can't fail, thus we do not 1770 1759 * check the returned value. This is a two-pass process, because 1771 1760 * we can't remove the dummy devices during the first pass: they 1772 1761 * could have been instantiated by real devices wishing to clean 1773 1762 * them up properly, so we give them a chance to do that first. */ 1774 - mutex_lock(&core_lock); 1775 1763 device_for_each_child(&adap->dev, NULL, __unregister_client); 1776 1764 device_for_each_child(&adap->dev, NULL, __unregister_dummy); 1777 - mutex_unlock(&core_lock); 1778 1765 1779 1766 /* device name is gone after device_unregister */ 1780 1767 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); ··· 2009 1966 /* add the driver to the list of i2c drivers in the driver core */ 2010 1967 driver->driver.owner = owner; 2011 1968 driver->driver.bus = &i2c_bus_type; 1969 + INIT_LIST_HEAD(&driver->clients); 2012 1970 2013 1971 /* When registration returns, the driver core 2014 1972 * will have called probe() for all matching-but-unbound devices. ··· 2027 1983 } 2028 1984 EXPORT_SYMBOL(i2c_register_driver); 2029 1985 2030 - static int __i2c_unregister_detected_client(struct device *dev, void *argp) 1986 + static int __process_removed_driver(struct device *dev, void *data) 2031 1987 { 2032 - struct i2c_client *client = i2c_verify_client(dev); 2033 - 2034 - if (client && client->flags & I2C_CLIENT_AUTO) 2035 - i2c_unregister_device(client); 2036 - 1988 + if (dev->type == &i2c_adapter_type) 1989 + i2c_do_del_adapter(data, to_i2c_adapter(dev)); 2037 1990 return 0; 2038 1991 } 2039 1992 ··· 2041 2000 */ 2042 2001 void i2c_del_driver(struct i2c_driver *driver) 2043 2002 { 2044 - mutex_lock(&core_lock); 2045 - /* Satisfy __must_check, function can't fail */ 2046 - if (driver_for_each_device(&driver->driver, NULL, NULL, 2047 - __i2c_unregister_detected_client)) { 2048 - } 2049 - mutex_unlock(&core_lock); 2003 + i2c_for_each_dev(driver, __process_removed_driver); 2050 2004 2051 2005 driver_unregister(&driver->driver); 2052 2006 pr_debug("driver [%s] unregistered\n", driver->driver.name); ··· 2468 2432 /* Finally call the custom detection function */ 2469 2433 memset(&info, 0, sizeof(struct i2c_board_info)); 2470 2434 info.addr = addr; 2471 - info.flags = I2C_CLIENT_AUTO; 2472 2435 err = driver->detect(temp_client, &info); 2473 2436 if (err) { 2474 2437 /* -ENODEV is returned if the detection fails. We catch it ··· 2494 2459 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n", 2495 2460 info.type, info.addr); 2496 2461 client = i2c_new_client_device(adapter, &info); 2497 - if (IS_ERR(client)) 2462 + if (!IS_ERR(client)) 2463 + list_add_tail(&client->detected, &driver->clients); 2464 + else 2498 2465 dev_err(&adapter->dev, "Failed creating %s at 0x%02x\n", 2499 2466 info.type, info.addr); 2500 2467 }
+8 -2
include/linux/i2c.h
··· 244 244 * @id_table: List of I2C devices supported by this driver 245 245 * @detect: Callback for device detection 246 246 * @address_list: The I2C addresses to probe (for detect) 247 + * @clients: List of detected clients we created (for i2c-core use only) 247 248 * @flags: A bitmask of flags defined in &enum i2c_driver_flags 248 249 * 249 250 * The driver.owner field should be set to the module owner of this driver. ··· 299 298 /* Device detection callback for automatic device creation */ 300 299 int (*detect)(struct i2c_client *client, struct i2c_board_info *info); 301 300 const unsigned short *address_list; 301 + struct list_head clients; 302 302 303 303 u32 flags; 304 304 }; ··· 315 313 * @dev: Driver model device node for the slave. 316 314 * @init_irq: IRQ that was set at initialization 317 315 * @irq: indicates the IRQ generated by this device (if any) 316 + * @detected: member of an i2c_driver.clients list or i2c-core's 317 + * userspace_devices list 318 318 * @slave_cb: Callback when I2C slave mode of an adapter is used. The adapter 319 319 * calls it to pass on slave events to the slave driver. 320 320 * @devres_group_id: id of the devres group that will be created for resources ··· 336 332 #define I2C_CLIENT_SLAVE 0x20 /* we are the slave */ 337 333 #define I2C_CLIENT_HOST_NOTIFY 0x40 /* We want to use I2C host notify */ 338 334 #define I2C_CLIENT_WAKE 0x80 /* for board_info; true iff can wake */ 339 - #define I2C_CLIENT_AUTO 0x100 /* client was auto-detected */ 340 - #define I2C_CLIENT_USER 0x200 /* client was userspace-created */ 341 335 #define I2C_CLIENT_SCCB 0x9000 /* Use Omnivision SCCB protocol */ 342 336 /* Must match I2C_M_STOP|IGNORE_NAK */ 343 337 ··· 347 345 struct device dev; /* the device structure */ 348 346 int init_irq; /* irq set at initialization */ 349 347 int irq; /* irq issued by device */ 348 + struct list_head detected; 350 349 #if IS_ENABLED(CONFIG_I2C_SLAVE) 351 350 i2c_slave_cb_t slave_cb; /* callback for slave mode */ 352 351 #endif ··· 753 750 int nr; 754 751 char name[48]; 755 752 struct completion dev_released; 753 + 754 + struct mutex userspace_clients_lock; 755 + struct list_head userspace_clients; 756 756 757 757 struct i2c_bus_recovery_info *bus_recovery_info; 758 758 const struct i2c_adapter_quirks *quirks;