Commit f9bcca40 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina

HID: usbhid: remove duplicated code

Well, no use to keep twice the same code.
Reviewed-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent e9d5da97
...@@ -915,19 +915,14 @@ static int usbhid_set_raw_report(struct hid_device *hid, unsigned int reportnum, ...@@ -915,19 +915,14 @@ static int usbhid_set_raw_report(struct hid_device *hid, unsigned int reportnum,
return ret; return ret;
} }
static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count)
static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count,
unsigned char report_type)
{ {
struct usbhid_device *usbhid = hid->driver_data; struct usbhid_device *usbhid = hid->driver_data;
struct usb_device *dev = hid_to_usb_dev(hid); struct usb_device *dev = hid_to_usb_dev(hid);
struct usb_interface *intf = usbhid->intf; int actual_length, skipped_report_id = 0, ret;
struct usb_host_interface *interface = intf->cur_altsetting;
int ret;
if (usbhid->urbout && report_type != HID_FEATURE_REPORT) { if (!usbhid->urbout)
int actual_length; return -EIO;
int skipped_report_id = 0;
if (buf[0] == 0x0) { if (buf[0] == 0x0) {
/* Don't send the Report ID */ /* Don't send the Report ID */
...@@ -935,6 +930,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co ...@@ -935,6 +930,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
count--; count--;
skipped_report_id = 1; skipped_report_id = 1;
} }
ret = usb_interrupt_msg(dev, usbhid->urbout->pipe, ret = usb_interrupt_msg(dev, usbhid->urbout->pipe,
buf, count, &actual_length, buf, count, &actual_length,
USB_CTRL_SET_TIMEOUT); USB_CTRL_SET_TIMEOUT);
...@@ -945,57 +941,19 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co ...@@ -945,57 +941,19 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
if (skipped_report_id) if (skipped_report_id)
ret++; ret++;
} }
} else {
int skipped_report_id = 0;
int report_id = buf[0];
if (buf[0] == 0x0) {
/* Don't send the Report ID */
buf++;
count--;
skipped_report_id = 1;
}
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
HID_REQ_SET_REPORT,
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
((report_type + 1) << 8) | report_id,
interface->desc.bInterfaceNumber, buf, count,
USB_CTRL_SET_TIMEOUT);
/* count also the report id, if this was a numbered report. */
if (ret > 0 && skipped_report_id)
ret++;
}
return ret; return ret;
} }
static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count) static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf,
size_t count, unsigned char report_type)
{ {
struct usbhid_device *usbhid = hid->driver_data; struct usbhid_device *usbhid = hid->driver_data;
struct usb_device *dev = hid_to_usb_dev(hid);
int actual_length, skipped_report_id = 0, ret;
if (!usbhid->urbout)
return -EIO;
if (buf[0] == 0x0) {
/* Don't send the Report ID */
buf++;
count--;
skipped_report_id = 1;
}
ret = usb_interrupt_msg(dev, usbhid->urbout->pipe, if (usbhid->urbout && report_type != HID_FEATURE_REPORT)
buf, count, &actual_length, return usbhid_output_report(hid, buf, count);
USB_CTRL_SET_TIMEOUT);
/* return the number of bytes transferred */
if (ret == 0) {
ret = actual_length;
/* count also the report id */
if (skipped_report_id)
ret++;
}
return ret; return usbhid_set_raw_report(hid, buf[0], buf, count, report_type);
} }
static void usbhid_restart_queues(struct usbhid_device *usbhid) static void usbhid_restart_queues(struct usbhid_device *usbhid)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment