Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 100268
b: refs/heads/master
c: 3db633e
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Corbet committed May 18, 2008
1 parent 5269d6e commit c6bef3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5119e92efc733d730b34f9605a5ae61fdc4bf649
refs/heads/master: 3db633ee352bfe20d4a2b0c3c8a46ce31a6c7149
22 changes: 16 additions & 6 deletions trunk/drivers/i2c/i2c-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <linux/list.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>

static struct i2c_driver i2cdev_driver;
Expand Down Expand Up @@ -441,14 +442,20 @@ static int i2cdev_open(struct inode *inode, struct file *file)
struct i2c_client *client;
struct i2c_adapter *adap;
struct i2c_dev *i2c_dev;
int ret = 0;

lock_kernel();
i2c_dev = i2c_dev_get_by_minor(minor);
if (!i2c_dev)
return -ENODEV;
if (!i2c_dev) {
ret = -ENODEV;
goto out;
}

adap = i2c_get_adapter(i2c_dev->adap->nr);
if (!adap)
return -ENODEV;
if (!adap) {
ret = -ENODEV;
goto out;
}

/* This creates an anonymous i2c_client, which may later be
* pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
Expand All @@ -460,15 +467,18 @@ static int i2cdev_open(struct inode *inode, struct file *file)
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client) {
i2c_put_adapter(adap);
return -ENOMEM;
ret = -ENOMEM;
goto out;
}
snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
client->driver = &i2cdev_driver;

client->adapter = adap;
file->private_data = client;

return 0;
out:
unlock_kernel();
return ret;
}

static int i2cdev_release(struct inode *inode, struct file *file)
Expand Down

0 comments on commit c6bef3f

Please sign in to comment.