OSDN Git Service

USB: Proper handling of Race Condition when two USB class drivers try to call init_us...
authorAjay Kaher <ajay.kaher@samsung.com>
Tue, 28 Mar 2017 12:09:32 +0000 (08:09 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 May 2017 12:28:34 +0000 (14:28 +0200)
commit5ffe717f351ddf63161b6390b1ea90a5c3733994
treeacfde2241f73fe309735d10ab37fe3649178e709
parentc31ff3ceb32616145d16862c7e897a59dc919882
USB: Proper handling of Race Condition when two USB class drivers try to call init_usb_class simultaneously

commit 2f86a96be0ccb1302b7eee7855dbee5ce4dc5dfb upstream.

There is race condition when two USB class drivers try to call
init_usb_class at the same time and leads to crash.
code path: probe->usb_register_dev->init_usb_class

To solve this, mutex locking has been added in init_usb_class() and
destroy_usb_class().

As pointed by Alan, removed "if (usb_class)" test from destroy_usb_class()
because usb_class can never be NULL there.

Signed-off-by: Ajay Kaher <ajay.kaher@samsung.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/file.c