mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
HID: roccat: fix locking in roccat_connect() and roccat_disconnect()
Extend critical section in roccat_connect() to ensure that partially initialized 'struct roccat_device' is never exposed in 'devices' list, and do the same in roccat_disconnect() to avoid racy 'devices' access against roccat_release(). Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Signed-off-by: Jiri Kosina <jkosina@suse.com>
This commit is contained in:
parent
7e749a7972
commit
d76994443e
|
|
@ -344,8 +344,6 @@ int roccat_connect(const struct class *klass, struct hid_device *hid, int report
|
|||
return temp;
|
||||
}
|
||||
|
||||
mutex_unlock(&devices_lock);
|
||||
|
||||
init_waitqueue_head(&device->wait);
|
||||
INIT_LIST_HEAD(&device->readers);
|
||||
mutex_init(&device->readers_lock);
|
||||
|
|
@ -356,6 +354,7 @@ int roccat_connect(const struct class *klass, struct hid_device *hid, int report
|
|||
device->cbuf_end = 0;
|
||||
device->report_size = report_size;
|
||||
|
||||
mutex_unlock(&devices_lock);
|
||||
return minor;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(roccat_connect);
|
||||
|
|
@ -369,15 +368,12 @@ void roccat_disconnect(int minor)
|
|||
|
||||
mutex_lock(&devices_lock);
|
||||
device = devices[minor];
|
||||
mutex_unlock(&devices_lock);
|
||||
|
||||
device->exist = 0; /* TODO exist maybe not needed */
|
||||
|
||||
device_destroy(device->dev->class, MKDEV(roccat_major, minor));
|
||||
|
||||
mutex_lock(&devices_lock);
|
||||
devices[minor] = NULL;
|
||||
mutex_unlock(&devices_lock);
|
||||
|
||||
if (device->open) {
|
||||
hid_hw_close(device->hid);
|
||||
|
|
@ -385,6 +381,8 @@ void roccat_disconnect(int minor)
|
|||
} else {
|
||||
roccat_free_device(device);
|
||||
}
|
||||
|
||||
mutex_unlock(&devices_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(roccat_disconnect);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user