Skip to content

Commit 6f68f0a

Browse files
Binoy JayanJiri Kosina
authored andcommitted
HID: Remove the semaphore driver_lock
The semaphore 'driver_lock' is used as a simple mutex, and also unnecessary as suggested by Arnd. Hence removing it, as the concurrency between the probe and remove is already handled in the driver core. Suggested-by: Arnd Bergmann <[email protected]> Signed-off-by: Binoy Jayan <[email protected]> Acked-by: Benjamin Tissoires <[email protected]> Reviewed-by: David Herrmann <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent a9d0683 commit 6f68f0a

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

drivers/hid/hid-core.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,11 +2487,9 @@ static int hid_device_probe(struct device *dev)
24872487
const struct hid_device_id *id;
24882488
int ret = 0;
24892489

2490-
if (down_interruptible(&hdev->driver_lock))
2491-
return -EINTR;
24922490
if (down_interruptible(&hdev->driver_input_lock)) {
24932491
ret = -EINTR;
2494-
goto unlock_driver_lock;
2492+
goto end;
24952493
}
24962494
hdev->io_started = false;
24972495

@@ -2518,8 +2516,7 @@ static int hid_device_probe(struct device *dev)
25182516
unlock:
25192517
if (!hdev->io_started)
25202518
up(&hdev->driver_input_lock);
2521-
unlock_driver_lock:
2522-
up(&hdev->driver_lock);
2519+
end:
25232520
return ret;
25242521
}
25252522

@@ -2529,11 +2526,9 @@ static int hid_device_remove(struct device *dev)
25292526
struct hid_driver *hdrv;
25302527
int ret = 0;
25312528

2532-
if (down_interruptible(&hdev->driver_lock))
2533-
return -EINTR;
25342529
if (down_interruptible(&hdev->driver_input_lock)) {
25352530
ret = -EINTR;
2536-
goto unlock_driver_lock;
2531+
goto end;
25372532
}
25382533
hdev->io_started = false;
25392534

@@ -2549,8 +2544,7 @@ static int hid_device_remove(struct device *dev)
25492544

25502545
if (!hdev->io_started)
25512546
up(&hdev->driver_input_lock);
2552-
unlock_driver_lock:
2553-
up(&hdev->driver_lock);
2547+
end:
25542548
return ret;
25552549
}
25562550

@@ -3008,7 +3002,6 @@ struct hid_device *hid_allocate_device(void)
30083002
init_waitqueue_head(&hdev->debug_wait);
30093003
INIT_LIST_HEAD(&hdev->debug_list);
30103004
spin_lock_init(&hdev->debug_list_lock);
3011-
sema_init(&hdev->driver_lock, 1);
30123005
sema_init(&hdev->driver_input_lock, 1);
30133006
mutex_init(&hdev->ll_open_lock);
30143007

include/linux/hid.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ struct hid_device { /* device report descriptor */
526526
struct hid_report_enum report_enum[HID_REPORT_TYPES];
527527
struct work_struct led_work; /* delayed LED worker */
528528

529-
struct semaphore driver_lock; /* protects the current driver, except during input */
530529
struct semaphore driver_input_lock; /* protects the current driver */
531530
struct device dev; /* device */
532531
struct hid_driver *driver;
@@ -551,7 +550,7 @@ struct hid_device { /* device report descriptor */
551550
unsigned int status; /* see STAT flags above */
552551
unsigned claimed; /* Claimed by hidinput, hiddev? */
553552
unsigned quirks; /* Various quirks the device can pull on us */
554-
bool io_started; /* Protected by driver_lock. If IO has started */
553+
bool io_started; /* If IO has started */
555554

556555
struct list_head inputs; /* The list of inputs */
557556
void *hiddev; /* The hiddev structure */

0 commit comments

Comments
 (0)