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

i2c: Use the driver model reference counting

Don't implement our own reference counting mechanism for i2c clients
when the driver model already has one.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: David Brownell <david-b@pacbell.net>

authored by

Jean Delvare and committed by
Jean Delvare
bdc511f4 0f79b72e

+2 -48
+2 -44
drivers/i2c/i2c-core.c
··· 696 696 } 697 697 list_add_tail(&client->list,&adapter->clients); 698 698 699 - client->usage_count = 0; 700 - 701 699 client->dev.parent = &client->adapter->dev; 702 700 client->dev.bus = &i2c_bus_type; 703 701 ··· 742 744 struct i2c_adapter *adapter = client->adapter; 743 745 int res = 0; 744 746 745 - if (client->usage_count > 0) { 746 - dev_warn(&client->dev, "Client [%s] still busy, " 747 - "can't detach\n", client->name); 748 - return -EBUSY; 749 - } 750 - 751 747 if (adapter->client_unregister) { 752 748 res = adapter->client_unregister(client); 753 749 if (res) { ··· 764 772 } 765 773 EXPORT_SYMBOL(i2c_detach_client); 766 774 767 - static int i2c_inc_use_client(struct i2c_client *client) 768 - { 769 - 770 - if (!try_module_get(client->driver->driver.owner)) 771 - return -ENODEV; 772 - if (!try_module_get(client->adapter->owner)) { 773 - module_put(client->driver->driver.owner); 774 - return -ENODEV; 775 - } 776 - 777 - return 0; 778 - } 779 - 780 - static void i2c_dec_use_client(struct i2c_client *client) 781 - { 782 - module_put(client->driver->driver.owner); 783 - module_put(client->adapter->owner); 784 - } 785 - 786 775 int i2c_use_client(struct i2c_client *client) 787 776 { 788 - int ret; 789 - 790 - ret = i2c_inc_use_client(client); 791 - if (ret) 792 - return ret; 793 - 794 - client->usage_count++; 795 - 777 + get_device(&client->dev); 796 778 return 0; 797 779 } 798 780 EXPORT_SYMBOL(i2c_use_client); 799 781 800 782 int i2c_release_client(struct i2c_client *client) 801 783 { 802 - if (!client->usage_count) { 803 - pr_debug("i2c-core: %s used one too many times\n", 804 - __FUNCTION__); 805 - return -EPERM; 806 - } 807 - 808 - client->usage_count--; 809 - i2c_dec_use_client(client); 810 - 784 + put_device(&client->dev); 811 785 return 0; 812 786 } 813 787 EXPORT_SYMBOL(i2c_release_client);
-1
drivers/media/video/ks0127.c
··· 764 764 .addr = 0, 765 765 .adapter = NULL, 766 766 .driver = &i2c_driver_ks0127, 767 - .usage_count = 0 768 767 }; 769 768 770 769 static int ks0127_found_proc(struct i2c_adapter *adapter, int addr, int kind)
-3
include/linux/i2c.h
··· 155 155 * generic enough to hide second-sourcing and compatible revisions. 156 156 * @adapter: manages the bus segment hosting this I2C device 157 157 * @driver: device's driver, hence pointer to access routines 158 - * @usage_count: counts current number of users of this client 159 158 * @dev: Driver model device node for the slave. 160 159 * @irq: indicates the IRQ generated by this device (if any) 161 160 * @driver_name: Identifies new-style driver used with this device; also ··· 174 175 char name[I2C_NAME_SIZE]; 175 176 struct i2c_adapter *adapter; /* the adapter we sit on */ 176 177 struct i2c_driver *driver; /* and our access routines */ 177 - int usage_count; /* How many accesses currently */ 178 - /* to the client */ 179 178 struct device dev; /* the device structure */ 180 179 int irq; /* irq issued by device (or -1) */ 181 180 char driver_name[KOBJ_NAME_LEN];