diff options
author | Jonathan Corbet <corbet@lwn.net> | 2008-05-15 11:21:02 -0400 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2008-05-18 17:43:40 -0400 |
commit | 3db633ee352bfe20d4a2b0c3c8a46ce31a6c7149 (patch) | |
tree | ccd435c2fae8933abf809d7cecd838f520258257 | |
parent | 5119e92efc733d730b34f9605a5ae61fdc4bf649 (diff) |
i2c: cdev lock_kernel() pushdown
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
-rw-r--r-- | drivers/i2c/i2c-dev.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index d34c14c81c29..006a5857256a 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/list.h> | 34 | #include <linux/list.h> |
35 | #include <linux/i2c.h> | 35 | #include <linux/i2c.h> |
36 | #include <linux/i2c-dev.h> | 36 | #include <linux/i2c-dev.h> |
37 | #include <linux/smp_lock.h> | ||
37 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
38 | 39 | ||
39 | static struct i2c_driver i2cdev_driver; | 40 | static struct i2c_driver i2cdev_driver; |
@@ -441,14 +442,20 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
441 | struct i2c_client *client; | 442 | struct i2c_client *client; |
442 | struct i2c_adapter *adap; | 443 | struct i2c_adapter *adap; |
443 | struct i2c_dev *i2c_dev; | 444 | struct i2c_dev *i2c_dev; |
445 | int ret = 0; | ||
444 | 446 | ||
447 | lock_kernel(); | ||
445 | i2c_dev = i2c_dev_get_by_minor(minor); | 448 | i2c_dev = i2c_dev_get_by_minor(minor); |
446 | if (!i2c_dev) | 449 | if (!i2c_dev) { |
447 | return -ENODEV; | 450 | ret = -ENODEV; |
451 | goto out; | ||
452 | } | ||
448 | 453 | ||
449 | adap = i2c_get_adapter(i2c_dev->adap->nr); | 454 | adap = i2c_get_adapter(i2c_dev->adap->nr); |
450 | if (!adap) | 455 | if (!adap) { |
451 | return -ENODEV; | 456 | ret = -ENODEV; |
457 | goto out; | ||
458 | } | ||
452 | 459 | ||
453 | /* This creates an anonymous i2c_client, which may later be | 460 | /* This creates an anonymous i2c_client, which may later be |
454 | * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. | 461 | * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. |
@@ -460,7 +467,8 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
460 | client = kzalloc(sizeof(*client), GFP_KERNEL); | 467 | client = kzalloc(sizeof(*client), GFP_KERNEL); |
461 | if (!client) { | 468 | if (!client) { |
462 | i2c_put_adapter(adap); | 469 | i2c_put_adapter(adap); |
463 | return -ENOMEM; | 470 | ret = -ENOMEM; |
471 | goto out; | ||
464 | } | 472 | } |
465 | snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); | 473 | snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); |
466 | client->driver = &i2cdev_driver; | 474 | client->driver = &i2cdev_driver; |
@@ -468,7 +476,9 @@ static int i2cdev_open(struct inode *inode, struct file *file) | |||
468 | client->adapter = adap; | 476 | client->adapter = adap; |
469 | file->private_data = client; | 477 | file->private_data = client; |
470 | 478 | ||
471 | return 0; | 479 | out: |
480 | unlock_kernel(); | ||
481 | return ret; | ||
472 | } | 482 | } |
473 | 483 | ||
474 | static int i2cdev_release(struct inode *inode, struct file *file) | 484 | static int i2cdev_release(struct inode *inode, struct file *file) |