Skip to content

Commit c2f3d51

Browse files
Jiangshan Yigregkh
authored andcommitted
HID: nintendo: stop device IO before hid_hw_stop on probe failure
[ Upstream commit 1f74d3b ] nintendo_hid_probe() calls hid_device_io_start() before joycon_init() and joycon_leds_create(). If either fails, the error path jumps to err_close which calls hid_hw_close()/hid_hw_stop() without first calling hid_device_io_stop(). hid_hw_stop() does not stop device IO, so hid_input_report() may still run and access driver data that is being torn down, resulting in a use-after-free. Add an err_io_stop label that calls hid_device_io_stop() before hid_hw_close(), and point the two post-io_start error paths at it. Fixes: 2af16c1 ("HID: nintendo: add nintendo switch controller driver") Cc: stable@vger.kernel.org Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn> Signed-off-by: Jiri Kosina <jkosina@suse.com> [ dropped the absent `err_ida:`/`ida_free()` context and retargeted all five `goto err_close` paths to the new `err_io_stop` label ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0952541 commit c2f3d51

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

drivers/hid/hid-nintendo.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,42 +2273,43 @@ static int nintendo_hid_probe(struct hid_device *hdev,
22732273
ret = joycon_init(hdev);
22742274
if (ret) {
22752275
hid_err(hdev, "Failed to initialize controller; ret=%d\n", ret);
2276-
goto err_close;
2276+
goto err_io_stop;
22772277
}
22782278

22792279
ret = joycon_read_info(ctlr);
22802280
if (ret) {
22812281
hid_err(hdev, "Failed to retrieve controller info; ret=%d\n",
22822282
ret);
2283-
goto err_close;
2283+
goto err_io_stop;
22842284
}
22852285

22862286
/* Initialize the leds */
22872287
ret = joycon_leds_create(ctlr);
22882288
if (ret) {
22892289
hid_err(hdev, "Failed to create leds; ret=%d\n", ret);
2290-
goto err_close;
2290+
goto err_io_stop;
22912291
}
22922292

22932293
/* Initialize the battery power supply */
22942294
ret = joycon_power_supply_create(ctlr);
22952295
if (ret) {
22962296
hid_err(hdev, "Failed to create power_supply; ret=%d\n", ret);
2297-
goto err_close;
2297+
goto err_io_stop;
22982298
}
22992299

23002300
ret = joycon_input_create(ctlr);
23012301
if (ret) {
23022302
hid_err(hdev, "Failed to create input device; ret=%d\n", ret);
2303-
goto err_close;
2303+
goto err_io_stop;
23042304
}
23052305

23062306
ctlr->ctlr_state = JOYCON_CTLR_STATE_READ;
23072307

23082308
hid_dbg(hdev, "probe - success\n");
23092309
return 0;
23102310

2311-
err_close:
2311+
err_io_stop:
2312+
hid_device_io_stop(hdev);
23122313
hid_hw_close(hdev);
23132314
err_stop:
23142315
hid_hw_stop(hdev);

0 commit comments

Comments
 (0)