Skip to content

Commit 1d1b564

Browse files
hkallweitJiri Kosina
authored andcommitted
hid: thingm: reorder calls in thingm_probe
When reviewing another thingm patch Benjamin Tissoires pointed out the following: "The problem here is that hid_hw_start() is called before thingm_version() which allows user space to briefly introduce races between thingm_version() and any hidraw requests. The mutex will not help here as it is initialized after hid_hw_start() and only used for protecting the concurrent access of the rgb." Avoid this possible issue by calling hid_hw_start() later in the probe function. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 43a4a04 commit 1d1b564

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

drivers/hid/hid-thingm.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,13 @@ static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
216216

217217
err = hid_parse(hdev);
218218
if (err)
219-
goto error;
220-
221-
err = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
222-
if (err)
223-
goto error;
219+
return err;
224220

225221
mutex_init(&tdev->lock);
226222

227223
err = thingm_version(tdev);
228224
if (err)
229-
goto stop;
225+
return err;
230226

231227
hid_dbg(hdev, "firmware version: %c.%c\n",
232228
tdev->version.major, tdev->version.minor);
@@ -237,33 +233,32 @@ static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
237233

238234
if (!tdev->fwinfo) {
239235
hid_err(hdev, "unsupported firmware %c\n", tdev->version.major);
240-
err = -ENODEV;
241-
goto stop;
236+
return -ENODEV;
242237
}
243238

244239
tdev->rgb = devm_kzalloc(&hdev->dev,
245240
sizeof(struct thingm_rgb) * tdev->fwinfo->numrgb,
246241
GFP_KERNEL);
247-
if (!tdev->rgb) {
248-
err = -ENOMEM;
249-
goto stop;
250-
}
242+
if (!tdev->rgb)
243+
return -ENOMEM;
244+
245+
err = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
246+
if (err)
247+
return err;
251248

252249
for (i = 0; i < tdev->fwinfo->numrgb; ++i) {
253250
struct thingm_rgb *rgb = tdev->rgb + i;
254251

255252
rgb->tdev = tdev;
256253
rgb->num = tdev->fwinfo->first + i;
257254
err = thingm_init_rgb(rgb);
258-
if (err)
259-
goto stop;
255+
if (err) {
256+
hid_hw_stop(hdev);
257+
return err;
258+
}
260259
}
261260

262261
return 0;
263-
stop:
264-
hid_hw_stop(hdev);
265-
error:
266-
return err;
267262
}
268263

269264
static const struct hid_device_id thingm_table[] = {

0 commit comments

Comments
 (0)