Skip to content

Commit c58ac3a

Browse files
bentissJiri Kosina
authored andcommitted
HID: wacom: break out parsing of device and registering of input
Simplifies the .probe() and will allow to reuse this path in the future. Few things are reshuffled in .probe(): - init wacom struct earlier - then retrieve the report descriptor - then parse it and allocate/register inputs. Signed-off-by: Benjamin Tissoires <[email protected]> Acked-by: Ping Cheng <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7e12978 commit c58ac3a

File tree

1 file changed

+75
-61
lines changed

1 file changed

+75
-61
lines changed

drivers/hid/wacom_sys.c

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,61 +1685,21 @@ static void wacom_update_name(struct wacom *wacom)
16851685
"%s Pad", name);
16861686
}
16871687

1688-
static int wacom_probe(struct hid_device *hdev,
1689-
const struct hid_device_id *id)
1688+
static int wacom_parse_and_register(struct wacom *wacom)
16901689
{
1691-
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1692-
struct usb_device *dev = interface_to_usbdev(intf);
1693-
struct wacom *wacom;
1694-
struct wacom_wac *wacom_wac;
1695-
struct wacom_features *features;
1690+
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1691+
struct wacom_features *features = &wacom_wac->features;
1692+
struct hid_device *hdev = wacom->hdev;
16961693
int error;
16971694
unsigned int connect_mask = HID_CONNECT_HIDRAW;
16981695

1699-
if (!id->driver_data)
1700-
return -EINVAL;
1701-
1702-
hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1703-
1704-
/* hid-core sets this quirk for the boot interface */
1705-
hdev->quirks &= ~HID_QUIRK_NOGET;
1706-
1707-
wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1708-
if (!wacom)
1709-
return -ENOMEM;
1710-
1711-
hid_set_drvdata(hdev, wacom);
1712-
wacom->hdev = hdev;
1713-
1714-
/* ask for the report descriptor to be loaded by HID */
1715-
error = hid_parse(hdev);
1716-
if (error) {
1717-
hid_err(hdev, "parse failed\n");
1718-
goto fail_parse;
1719-
}
1720-
1721-
wacom_wac = &wacom->wacom_wac;
1722-
wacom_wac->features = *((struct wacom_features *)id->driver_data);
1723-
features = &wacom_wac->features;
17241696
features->pktlen = wacom_compute_pktlen(hdev);
1725-
if (features->pktlen > WACOM_PKGLEN_MAX) {
1726-
error = -EINVAL;
1727-
goto fail_pktlen;
1728-
}
1729-
1730-
if (features->check_for_hid_type && features->hid_type != hdev->type) {
1731-
error = -ENODEV;
1732-
goto fail_type;
1733-
}
1734-
1735-
wacom->usbdev = dev;
1736-
wacom->intf = intf;
1737-
mutex_init(&wacom->lock);
1738-
INIT_WORK(&wacom->work, wacom_wireless_work);
1697+
if (features->pktlen > WACOM_PKGLEN_MAX)
1698+
return -EINVAL;
17391699

17401700
error = wacom_allocate_inputs(wacom);
17411701
if (error)
1742-
goto fail_allocate_inputs;
1702+
return error;
17431703

17441704
/*
17451705
* Bamboo Pad has a generic hid handling for the Pen, and we switch it
@@ -1752,7 +1712,7 @@ static int wacom_probe(struct hid_device *hdev,
17521712
} else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
17531713
(features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
17541714
error = -ENODEV;
1755-
goto fail_shared_data;
1715+
goto fail_allocate_inputs;
17561716
}
17571717
}
17581718

@@ -1772,7 +1732,7 @@ static int wacom_probe(struct hid_device *hdev,
17721732
error ? "Ignoring" : "Assuming pen");
17731733

17741734
if (error)
1775-
goto fail_shared_data;
1735+
goto fail_parsed;
17761736

17771737
features->device_type |= WACOM_DEVICETYPE_PEN;
17781738
}
@@ -1796,14 +1756,6 @@ static int wacom_probe(struct hid_device *hdev,
17961756
if (error)
17971757
goto fail_register_inputs;
17981758

1799-
if (hdev->bus == BUS_BLUETOOTH) {
1800-
error = device_create_file(&hdev->dev, &dev_attr_speed);
1801-
if (error)
1802-
hid_warn(hdev,
1803-
"can't create sysfs speed attribute err: %d\n",
1804-
error);
1805-
}
1806-
18071759
if (features->type == HID_GENERIC)
18081760
connect_mask |= HID_CONNECT_DRIVER;
18091761

@@ -1844,18 +1796,80 @@ static int wacom_probe(struct hid_device *hdev,
18441796
return 0;
18451797

18461798
fail_hw_start:
1847-
if (hdev->bus == BUS_BLUETOOTH)
1848-
device_remove_file(&hdev->dev, &dev_attr_speed);
1799+
hid_hw_stop(hdev);
18491800
fail_register_inputs:
18501801
wacom_clean_inputs(wacom);
18511802
wacom_destroy_battery(wacom);
18521803
fail_battery:
18531804
wacom_remove_shared_data(wacom);
18541805
fail_shared_data:
1855-
wacom_clean_inputs(wacom);
1806+
fail_parsed:
18561807
fail_allocate_inputs:
1808+
wacom_clean_inputs(wacom);
1809+
return error;
1810+
}
1811+
1812+
static int wacom_probe(struct hid_device *hdev,
1813+
const struct hid_device_id *id)
1814+
{
1815+
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
1816+
struct usb_device *dev = interface_to_usbdev(intf);
1817+
struct wacom *wacom;
1818+
struct wacom_wac *wacom_wac;
1819+
struct wacom_features *features;
1820+
int error;
1821+
1822+
if (!id->driver_data)
1823+
return -EINVAL;
1824+
1825+
hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1826+
1827+
/* hid-core sets this quirk for the boot interface */
1828+
hdev->quirks &= ~HID_QUIRK_NOGET;
1829+
1830+
wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1831+
if (!wacom)
1832+
return -ENOMEM;
1833+
1834+
hid_set_drvdata(hdev, wacom);
1835+
wacom->hdev = hdev;
1836+
1837+
wacom_wac = &wacom->wacom_wac;
1838+
wacom_wac->features = *((struct wacom_features *)id->driver_data);
1839+
features = &wacom_wac->features;
1840+
1841+
if (features->check_for_hid_type && features->hid_type != hdev->type) {
1842+
error = -ENODEV;
1843+
goto fail_type;
1844+
}
1845+
1846+
wacom->usbdev = dev;
1847+
wacom->intf = intf;
1848+
mutex_init(&wacom->lock);
1849+
INIT_WORK(&wacom->work, wacom_wireless_work);
1850+
1851+
/* ask for the report descriptor to be loaded by HID */
1852+
error = hid_parse(hdev);
1853+
if (error) {
1854+
hid_err(hdev, "parse failed\n");
1855+
goto fail_parse;
1856+
}
1857+
1858+
error = wacom_parse_and_register(wacom);
1859+
if (error)
1860+
goto fail_parse;
1861+
1862+
if (hdev->bus == BUS_BLUETOOTH) {
1863+
error = device_create_file(&hdev->dev, &dev_attr_speed);
1864+
if (error)
1865+
hid_warn(hdev,
1866+
"can't create sysfs speed attribute err: %d\n",
1867+
error);
1868+
}
1869+
1870+
return 0;
1871+
18571872
fail_type:
1858-
fail_pktlen:
18591873
fail_parse:
18601874
kfree(wacom);
18611875
hid_set_drvdata(hdev, NULL);

0 commit comments

Comments
 (0)