HID: make hid_report_len as a static inline function in hid.h
authorMathieu Magnaudet <mathieu.magnaudet@gmail.com>
Thu, 27 Nov 2014 15:02:36 +0000 (16:02 +0100)
committerJiri Kosina <jkosina@suse.cz>
Mon, 1 Dec 2014 20:34:17 +0000 (21:34 +0100)
In several hid drivers it is necessary to calculate the length of an
hid_report. This patch exports the existing static function hid_report_len of
hid-core.c as an inline function in hid.h

Signed-off-by: Mathieu Magnaudet <mathieu.magnaudet@enac.fr>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-core.c
drivers/hid/hid-input.c
drivers/hid/hid-multitouch.c
drivers/hid/usbhid/hid-core.c
drivers/hid/wacom_sys.c
include/linux/hid.h

index 3402033fa52a7225c0a91846eba5237af8d08142..ee6ba7625e776d804f7ef1d5bb1d5be36a21f4f0 100644 (file)
@@ -1280,12 +1280,6 @@ void hid_output_report(struct hid_report *report, __u8 *data)
 }
 EXPORT_SYMBOL_GPL(hid_output_report);
 
-static int hid_report_len(struct hid_report *report)
-{
-       /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
-       return ((report->size - 1) >> 3) + 1 + (report->id > 0);
-}
-
 /*
  * Allocator for buffer that is going to be passed to hid_output_report()
  */
index 725f22ca47fcb808401dc08120ad0366bb9d9d69..1e95f4df414618420c5745a99b85ef9afb502e44 100644 (file)
@@ -1215,7 +1215,7 @@ static void hidinput_led_worker(struct work_struct *work)
                return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT);
 
        /* fall back to generic raw-output-report */
-       len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
+       len = hid_report_len(report);
        buf = hid_alloc_report_buf(report, GFP_KERNEL);
        if (!buf)
                return;
index 683cda6c60cebbba5e6ea8befa584cfd14fd6ecd..f65e78b46999999bc8320240cf1adea51547a9b1 100644 (file)
@@ -827,7 +827,7 @@ static void mt_set_input_mode(struct hid_device *hdev)
        r = re->report_id_hash[td->inputmode];
        if (r) {
                if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) {
-                       report_len = ((r->size - 1) >> 3) + 1 + (r->id > 0);
+                       report_len = hid_report_len(r);
                        buf = hid_alloc_report_buf(r, GFP_KERNEL);
                        if (!buf) {
                                hid_err(hdev, "failed to allocate buffer for report\n");
index ca6849a0121e7bee62b23740f52c0a66bddde5e8..b6cb7a5e4b2700d38542e687656c04e53ac8684e 100644 (file)
@@ -338,8 +338,7 @@ static int hid_submit_out(struct hid_device *hid)
        report = usbhid->out[usbhid->outtail].report;
        raw_report = usbhid->out[usbhid->outtail].raw_report;
 
-       usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) +
-                                                1 + (report->id > 0);
+       usbhid->urbout->transfer_buffer_length = hid_report_len(report);
        usbhid->urbout->dev = hid_to_usb_dev(hid);
        if (raw_report) {
                memcpy(usbhid->outbuf, raw_report,
index 8593047bb726cb1046ebbdba7a48a5802d1dc764..8e02a4a6fde0c1f35547c3c1a2f73893dc83a063 100644 (file)
@@ -1321,12 +1321,6 @@ static void wacom_calculate_res(struct wacom_features *features)
                                                    features->unitExpo);
 }
 
-static int wacom_hid_report_len(struct hid_report *report)
-{
-       /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
-       return ((report->size - 1) >> 3) + 1 + (report->id > 0);
-}
-
 static size_t wacom_compute_pktlen(struct hid_device *hdev)
 {
        struct hid_report_enum *report_enum;
@@ -1336,7 +1330,7 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev)
        report_enum = hdev->report_enum + HID_INPUT_REPORT;
 
        list_for_each_entry(report, &report_enum->report_list, list) {
-               size_t report_size = wacom_hid_report_len(report);
+               size_t report_size = hid_report_len(report);
                if (report_size > size)
                        size = report_size;
        }
index 78ea9bf941cd3352def7eaff6f26304beb1e2f7e..2366fda010c8dccf9dd07c4f3fde9b01326e20c8 100644 (file)
@@ -1063,6 +1063,17 @@ static inline void hid_hw_wait(struct hid_device *hdev)
                hdev->ll_driver->wait(hdev);
 }
 
+/**
+ * hid_report_len - calculate the report length
+ *
+ * @report: the report we want to know the length
+ */
+static inline int hid_report_len(struct hid_report *report)
+{
+       /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
+       return ((report->size - 1) >> 3) + 1 + (report->id > 0);
+}
+
 int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
                int interrupt);