Skip to content

Commit b764459

Browse files
jigpuJiri Kosina
authored andcommitted
HID: wacom: Shrink critical section in wacom_add_shared_data
The size of the critical section in this function appears to be larger than necessary. The `wacom_udev_list_lock` exists to ensure that one interface cannot begin checking if a shared object exists while a second interface is doing the same (otherwise both could determine that no object exists yet and create their own independent objects rather than sharing just one). It should be safe for the critical section to end once a fresly-allocated shared object would be found by other threads (i.e., once it has been added to `wacom_udev_list`, which is looped over by `wacom_get_hdev_data`). This commit is a necessary pre-requisite for a later change to swap the use of `devm_add_action` with `devm_add_action_or_reset`, which would otherwise deadlock in its error case. Signed-off-by: Jason Gerecke <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 42d43c9 commit b764459

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/hid/wacom_sys.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,20 +881,21 @@ static int wacom_add_shared_data(struct hid_device *hdev)
881881
if (!data) {
882882
data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
883883
if (!data) {
884-
retval = -ENOMEM;
885-
goto out;
884+
mutex_unlock(&wacom_udev_list_lock);
885+
return -ENOMEM;
886886
}
887887

888888
kref_init(&data->kref);
889889
data->dev = hdev;
890890
list_add_tail(&data->list, &wacom_udev_list);
891891
}
892892

893+
mutex_unlock(&wacom_udev_list_lock);
894+
893895
wacom_wac->shared = &data->shared;
894896

895897
retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom);
896898
if (retval) {
897-
mutex_unlock(&wacom_udev_list_lock);
898899
wacom_remove_shared_data(wacom);
899900
return retval;
900901
}
@@ -904,8 +905,6 @@ static int wacom_add_shared_data(struct hid_device *hdev)
904905
else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN)
905906
wacom_wac->shared->pen = hdev;
906907

907-
out:
908-
mutex_unlock(&wacom_udev_list_lock);
909908
return retval;
910909
}
911910

0 commit comments

Comments
 (0)