aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/i2c-dev.c')
-rw-r--r--drivers/i2c/i2c-dev.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index df540d5dfaf4..393e679d9faa 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -182,27 +182,22 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
182 return ret; 182 return ret;
183} 183}
184 184
185static int i2cdev_check(struct device *dev, void *addrp)
186{
187 struct i2c_client *client = i2c_verify_client(dev);
188
189 if (!client || client->addr != *(unsigned int *)addrp)
190 return 0;
191
192 return dev->driver ? -EBUSY : 0;
193}
194
185/* This address checking function differs from the one in i2c-core 195/* This address checking function differs from the one in i2c-core
186 in that it considers an address with a registered device, but no 196 in that it considers an address with a registered device, but no
187 bound driver, as NOT busy. */ 197 driver bound to it, as NOT busy. */
188static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 198static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
189{ 199{
190 struct list_head *item; 200 return device_for_each_child(&adapter->dev, &addr, i2cdev_check);
191 struct i2c_client *client;
192 int res = 0;
193
194 mutex_lock(&adapter->clist_lock);
195 list_for_each(item, &adapter->clients) {
196 client = list_entry(item, struct i2c_client, list);
197 if (client->addr == addr) {
198 if (client->driver)
199 res = -EBUSY;
200 break;
201 }
202 }
203 mutex_unlock(&adapter->clist_lock);
204
205 return res;
206} 201}
207 202
208static int i2cdev_ioctl(struct inode *inode, struct file *file, 203static int i2cdev_ioctl(struct inode *inode, struct file *file,