Skip to content

Commit 3d48d0f

Browse files
vittyvkgregkh
authored andcommitted
HID: hyperv: streamline driver probe to avoid devres issues
[ Upstream commit 66ef47f ] It was found that unloading 'hid_hyperv' module results in a devres complaint: ... hv_vmbus: unregistering driver hid_hyperv ------------[ cut here ]------------ WARNING: CPU: 2 PID: 3983 at drivers/base/devres.c:691 devres_release_group+0x1f2/0x2c0 ... Call Trace: <TASK> ? devres_release_group+0x1f2/0x2c0 ? __warn+0xd1/0x1c0 ? devres_release_group+0x1f2/0x2c0 ? report_bug+0x32a/0x3c0 ? handle_bug+0x53/0xa0 ? exc_invalid_op+0x18/0x50 ? asm_exc_invalid_op+0x1a/0x20 ? devres_release_group+0x1f2/0x2c0 ? devres_release_group+0x90/0x2c0 ? rcu_is_watching+0x15/0xb0 ? __pfx_devres_release_group+0x10/0x10 hid_device_remove+0xf5/0x220 device_release_driver_internal+0x371/0x540 ? klist_put+0xf3/0x170 bus_remove_device+0x1f1/0x3f0 device_del+0x33f/0x8c0 ? __pfx_device_del+0x10/0x10 ? cleanup_srcu_struct+0x337/0x500 hid_destroy_device+0xc8/0x130 mousevsc_remove+0xd2/0x1d0 [hid_hyperv] device_release_driver_internal+0x371/0x540 driver_detach+0xc5/0x180 bus_remove_driver+0x11e/0x2a0 ? __mutex_unlock_slowpath+0x160/0x5e0 vmbus_driver_unregister+0x62/0x2b0 [hv_vmbus] ... And the issue seems to be that the corresponding devres group is not allocated. Normally, devres_open_group() is called from __hid_device_probe() but Hyper-V HID driver overrides 'hid_dev->driver' with 'mousevsc_hid_driver' stub and basically re-implements __hid_device_probe() by calling hid_parse() and hid_hw_start() but not devres_open_group(). hid_device_probe() does not call __hid_device_probe() for it. Later, when the driver is removed, hid_device_remove() calls devres_release_group() as it doesn't check whether hdev->driver was initially overridden or not. The issue seems to be related to the commit 62c68e7 ("HID: ensure timely release of driver-allocated resources") but the commit itself seems to be correct. Fix the issue by dropping the 'hid_dev->driver' override and using hid_register_driver()/hid_unregister_driver() instead. Alternatively, it would have been possible to rely on the default handling but HID_CONNECT_DEFAULT implies HID_CONNECT_HIDRAW and it doesn't seem to work for mousevsc as-is. Fixes: 62c68e7 ("HID: ensure timely release of driver-allocated resources") Suggested-by: Michael Kelley <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Tested-by: Saurabh Sengar <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent acf588f commit 3d48d0f

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

drivers/hid/hid-hyperv.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ static int mousevsc_hid_raw_request(struct hid_device *hid,
422422
return 0;
423423
}
424424

425+
static int mousevsc_hid_probe(struct hid_device *hid_dev, const struct hid_device_id *id)
426+
{
427+
int ret;
428+
429+
ret = hid_parse(hid_dev);
430+
if (ret) {
431+
hid_err(hid_dev, "parse failed\n");
432+
return ret;
433+
}
434+
435+
ret = hid_hw_start(hid_dev, HID_CONNECT_HIDINPUT | HID_CONNECT_HIDDEV);
436+
if (ret) {
437+
hid_err(hid_dev, "hw start failed\n");
438+
return ret;
439+
}
440+
441+
return 0;
442+
}
443+
425444
static const struct hid_ll_driver mousevsc_ll_driver = {
426445
.parse = mousevsc_hid_parse,
427446
.open = mousevsc_hid_open,
@@ -431,7 +450,16 @@ static const struct hid_ll_driver mousevsc_ll_driver = {
431450
.raw_request = mousevsc_hid_raw_request,
432451
};
433452

434-
static struct hid_driver mousevsc_hid_driver;
453+
static const struct hid_device_id mousevsc_devices[] = {
454+
{ HID_DEVICE(BUS_VIRTUAL, HID_GROUP_ANY, 0x045E, 0x0621) },
455+
{ }
456+
};
457+
458+
static struct hid_driver mousevsc_hid_driver = {
459+
.name = "hid-hyperv",
460+
.id_table = mousevsc_devices,
461+
.probe = mousevsc_hid_probe,
462+
};
435463

436464
static int mousevsc_probe(struct hv_device *device,
437465
const struct hv_vmbus_device_id *dev_id)
@@ -473,7 +501,6 @@ static int mousevsc_probe(struct hv_device *device,
473501
}
474502

475503
hid_dev->ll_driver = &mousevsc_ll_driver;
476-
hid_dev->driver = &mousevsc_hid_driver;
477504
hid_dev->bus = BUS_VIRTUAL;
478505
hid_dev->vendor = input_dev->hid_dev_info.vendor;
479506
hid_dev->product = input_dev->hid_dev_info.product;
@@ -488,20 +515,6 @@ static int mousevsc_probe(struct hv_device *device,
488515
if (ret)
489516
goto probe_err2;
490517

491-
492-
ret = hid_parse(hid_dev);
493-
if (ret) {
494-
hid_err(hid_dev, "parse failed\n");
495-
goto probe_err2;
496-
}
497-
498-
ret = hid_hw_start(hid_dev, HID_CONNECT_HIDINPUT | HID_CONNECT_HIDDEV);
499-
500-
if (ret) {
501-
hid_err(hid_dev, "hw start failed\n");
502-
goto probe_err2;
503-
}
504-
505518
device_init_wakeup(&device->device, true);
506519

507520
input_dev->connected = true;
@@ -579,12 +592,23 @@ static struct hv_driver mousevsc_drv = {
579592

580593
static int __init mousevsc_init(void)
581594
{
582-
return vmbus_driver_register(&mousevsc_drv);
595+
int ret;
596+
597+
ret = hid_register_driver(&mousevsc_hid_driver);
598+
if (ret)
599+
return ret;
600+
601+
ret = vmbus_driver_register(&mousevsc_drv);
602+
if (ret)
603+
hid_unregister_driver(&mousevsc_hid_driver);
604+
605+
return ret;
583606
}
584607

585608
static void __exit mousevsc_exit(void)
586609
{
587610
vmbus_driver_unregister(&mousevsc_drv);
611+
hid_unregister_driver(&mousevsc_hid_driver);
588612
}
589613

590614
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)