drv-hidpp**: check if the device accepts the HID++ reports

Removes the broken pipe on invalid nodes

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
This commit is contained in:
Benjamin Tissoires
2015-09-12 10:17:34 -04:00
parent 84cfedbf5f
commit 90fa2251fa
4 changed files with 34 additions and 0 deletions

View File

@@ -208,6 +208,11 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id)
goto err;
}
if (!ratbag_hidraw_has_report(device, REPORT_ID_SHORT)) {
ratbag_close_hidraw(device);
return -ENODEV;
}
drv_data = zalloc(sizeof(*drv_data));
/* We can treat all devices as wired devices here. If we talk to the

View File

@@ -446,6 +446,11 @@ hidpp20drv_probe(struct ratbag_device *device, const struct ratbag_id id)
return -ENODEV;
}
if (!ratbag_hidraw_has_report(device, REPORT_ID_LONG)) {
ratbag_close_hidraw(device);
return -ENODEV;
}
drv_data = zalloc(sizeof(*drv_data));
ratbag_set_drv_data(device, drv_data);

View File

@@ -137,6 +137,19 @@ err:
return -errno;
}
int
ratbag_hidraw_has_report(struct ratbag_device *device, uint8_t report_id)
{
unsigned i;
for (i = 0; i < device->hidraw.num_report_ids; i++) {
if (device->hidraw.report_ids[i] == report_id)
return 1;
}
return 0;
}
void
ratbag_close_hidraw(struct ratbag_device *device)
{

View File

@@ -96,4 +96,15 @@ int ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size
*/
int ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size_t len);
/**
* Tells if a given device has the specified report ID.
*
* @param device the ratbag device which hidraw node is opened
* @param report_id the report ID we inquire about
*
* @return 1 if the device has the given report id, 0 otherwise
*/
int
ratbag_hidraw_has_report(struct ratbag_device *device, uint8_t report_id);
#endif /* LIBRATBAG_HIDRAW_H */