diff options
Diffstat (limited to 'drivers/hid/hid-roccat.c')
-rw-r--r-- | drivers/hid/hid-roccat.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c index 5666e7587b18..b685b04dbf9d 100644 --- a/drivers/hid/hid-roccat.c +++ b/drivers/hid/hid-roccat.c @@ -27,6 +27,7 @@ #include <linux/poll.h> #include <linux/sched.h> #include <linux/hid-roccat.h> +#include <linux/module.h> #define ROCCAT_FIRST_MINOR 0 #define ROCCAT_MAX_DEVICES 8 @@ -162,27 +163,27 @@ static int roccat_open(struct inode *inode, struct file *file) device = devices[minor]; - mutex_lock(&device->readers_lock); - if (!device) { pr_emerg("roccat device with minor %d doesn't exist\n", minor); error = -ENODEV; - goto exit_err; + goto exit_err_devices; } + mutex_lock(&device->readers_lock); + if (!device->open++) { /* power on device on adding first reader */ error = hid_hw_power(device->hid, PM_HINT_FULLON); if (error < 0) { --device->open; - goto exit_err; + goto exit_err_readers; } error = hid_hw_open(device->hid); if (error < 0) { hid_hw_power(device->hid, PM_HINT_NORMAL); --device->open; - goto exit_err; + goto exit_err_readers; } } @@ -193,13 +194,13 @@ static int roccat_open(struct inode *inode, struct file *file) list_add_tail(&reader->node, &device->readers); file->private_data = reader; -exit_unlock: +exit_err_readers: mutex_unlock(&device->readers_lock); +exit_err_devices: mutex_unlock(&devices_lock); + if (error) + kfree(reader); return error; -exit_err: - kfree(reader); - goto exit_unlock; } static int roccat_release(struct inode *inode, struct file *file) |