Skip to content

Commit a9f1da0

Browse files
Dan CarpenterBenjamin Tissoires
authored andcommitted
HID: hid-steam: Fix cleanup in probe()
There are a number of issues in this code. First of all if steam_create_client_hid() fails then it leads to an error pointer dereference when we call hid_destroy_device(steam->client_hdev). Also there are a number of leaks. hid_hw_stop() is not called if hid_hw_open() fails for example. And it doesn't call steam_unregister() or hid_hw_close(). Fixes: 691ead1 ("HID: hid-steam: Clean up locking") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Vicki Pfau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent a966816 commit a9f1da0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

drivers/hid/hid-steam.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,14 +1128,14 @@ static int steam_probe(struct hid_device *hdev,
11281128
*/
11291129
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDRAW);
11301130
if (ret)
1131-
goto hid_hw_start_fail;
1131+
goto err_cancel_work;
11321132

11331133
ret = hid_hw_open(hdev);
11341134
if (ret) {
11351135
hid_err(hdev,
11361136
"%s:hid_hw_open\n",
11371137
__func__);
1138-
goto hid_hw_open_fail;
1138+
goto err_hw_stop;
11391139
}
11401140

11411141
if (steam->quirks & STEAM_QUIRK_WIRELESS) {
@@ -1151,33 +1151,37 @@ static int steam_probe(struct hid_device *hdev,
11511151
hid_err(hdev,
11521152
"%s:steam_register failed with error %d\n",
11531153
__func__, ret);
1154-
goto input_register_fail;
1154+
goto err_hw_close;
11551155
}
11561156
}
11571157

11581158
steam->client_hdev = steam_create_client_hid(hdev);
11591159
if (IS_ERR(steam->client_hdev)) {
11601160
ret = PTR_ERR(steam->client_hdev);
1161-
goto client_hdev_fail;
1161+
goto err_stream_unregister;
11621162
}
11631163
steam->client_hdev->driver_data = steam;
11641164

11651165
ret = hid_add_device(steam->client_hdev);
11661166
if (ret)
1167-
goto client_hdev_add_fail;
1167+
goto err_destroy;
11681168

11691169
return 0;
11701170

1171-
client_hdev_add_fail:
1172-
hid_hw_stop(hdev);
1173-
client_hdev_fail:
1171+
err_destroy:
11741172
hid_destroy_device(steam->client_hdev);
1175-
input_register_fail:
1176-
hid_hw_open_fail:
1177-
hid_hw_start_fail:
1173+
err_stream_unregister:
1174+
if (steam->connected)
1175+
steam_unregister(steam);
1176+
err_hw_close:
1177+
hid_hw_close(hdev);
1178+
err_hw_stop:
1179+
hid_hw_stop(hdev);
1180+
err_cancel_work:
11781181
cancel_work_sync(&steam->work_connect);
11791182
cancel_delayed_work_sync(&steam->mode_switch);
11801183
cancel_work_sync(&steam->rumble_work);
1184+
11811185
return ret;
11821186
}
11831187

0 commit comments

Comments
 (0)