Skip to content

Commit

Permalink
HID: core: move the dynamic quirks handling in core
Browse files Browse the repository at this point in the history
usbhid has a list of dynamic quirks in addition to a list of static quirks.
There is not much USB specific in that, so move this part of the module
in core so we can have one central place for quirks.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Benjamin Tissoires authored and Jiri Kosina committed Nov 21, 2017
1 parent 20df157 commit d5d3e20
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 417 deletions.
2 changes: 1 addition & 1 deletion drivers/hid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Makefile for the HID driver
#
hid-y := hid-core.o hid-input.o
hid-y := hid-core.o hid-input.o hid-quirks.o
hid-$(CONFIG_DEBUG_FS) += hid-debug.o

obj-$(CONFIG_HID) += hid.o
Expand Down
10 changes: 7 additions & 3 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,16 +1597,16 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
}
EXPORT_SYMBOL_GPL(hid_input_report);

static bool hid_match_one_id(struct hid_device *hdev,
const struct hid_device_id *id)
bool hid_match_one_id(const struct hid_device *hdev,
const struct hid_device_id *id)
{
return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
(id->group == HID_GROUP_ANY || id->group == hdev->group) &&
(id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
(id->product == HID_ANY_ID || id->product == hdev->product);
}

const struct hid_device_id *hid_match_id(struct hid_device *hdev,
const struct hid_device_id *hid_match_id(const struct hid_device *hdev,
const struct hid_device_id *id)
{
for (; id->bus; id++)
Expand Down Expand Up @@ -2613,6 +2613,7 @@ static struct bus_type hid_bus_type = {
.remove = hid_device_remove,
.uevent = hid_uevent,
};
EXPORT_SYMBOL(hid_bus_type);

/* a list of devices that shouldn't be handled by HID core at all */
static const struct hid_device_id hid_ignore_list[] = {
Expand Down Expand Up @@ -2931,6 +2932,8 @@ int hid_add_device(struct hid_device *hdev)
if (WARN_ON(hdev->status & HID_STAT_ADDED))
return -EBUSY;

hdev->quirks = hid_lookup_quirk(hdev);

/* we need to kill them here, otherwise they will stay allocated to
* wait for coming driver */
if (hid_ignore(hdev))
Expand Down Expand Up @@ -3117,6 +3120,7 @@ static void __exit hid_exit(void)
hid_debug_exit();
hidraw_exit();
bus_unregister(&hid_bus_type);
hid_quirks_exit(HID_BUS_ANY);
}

module_init(hid_init);
Expand Down
399 changes: 399 additions & 0 deletions drivers/hid/hid-quirks.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion drivers/hid/usbhid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Makefile for the USB input drivers
#

usbhid-y := hid-core.o hid-quirks.o
usbhid-y := hid-core.o
usbhid-$(CONFIG_USB_HIDDEV) += hiddev.o
usbhid-$(CONFIG_HID_PID) += hid-pidff.o

Expand Down
10 changes: 4 additions & 6 deletions drivers/hid/usbhid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,7 @@ static int usbhid_parse(struct hid_device *hid)
int num_descriptors;
size_t offset = offsetof(struct hid_descriptor, desc);

quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));
quirks = hid_lookup_quirk(hid);

if (quirks & HID_QUIRK_IGNORE)
return -ENODEV;
Expand Down Expand Up @@ -1329,7 +1328,6 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
hid->product = le16_to_cpu(dev->descriptor.idProduct);
hid->name[0] = 0;
hid->quirks = usbhid_lookup_quirk(hid->vendor, hid->product);
if (intf->cur_altsetting->desc.bInterfaceProtocol ==
USB_INTERFACE_PROTOCOL_MOUSE)
hid->type = HID_TYPE_USBMOUSE;
Expand Down Expand Up @@ -1641,7 +1639,7 @@ static int __init hid_init(void)
{
int retval = -ENOMEM;

retval = usbhid_quirks_init(quirks_param);
retval = hid_quirks_init(quirks_param, BUS_USB, MAX_USBHID_BOOT_QUIRKS);
if (retval)
goto usbhid_quirks_init_fail;
retval = usb_register(&hid_driver);
Expand All @@ -1651,15 +1649,15 @@ static int __init hid_init(void)

return 0;
usb_register_fail:
usbhid_quirks_exit();
hid_quirks_exit(BUS_USB);
usbhid_quirks_init_fail:
return retval;
}

static void __exit hid_exit(void)
{
usb_deregister(&hid_driver);
usbhid_quirks_exit();
hid_quirks_exit(BUS_USB);
}

module_init(hid_init);
Expand Down
Loading

0 comments on commit d5d3e20

Please sign in to comment.