diff options
author | Mathieu Magnaudet <mathieu.magnaudet@gmail.com> | 2014-11-27 10:02:36 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2014-12-01 15:34:17 -0500 |
commit | dabb05c6670e6e4415d7b56cd5864a5dbd90207f (patch) | |
tree | ca80d7c8cf44f32bb0c870855ae87452c8a004c3 | |
parent | da10bc252476a8d1d1bdf7b94502ad2cbd7f30b1 (diff) |
HID: make hid_report_len as a static inline function in hid.h
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>
-rw-r--r-- | drivers/hid/hid-core.c | 6 | ||||
-rw-r--r-- | drivers/hid/hid-input.c | 2 | ||||
-rw-r--r-- | drivers/hid/hid-multitouch.c | 2 | ||||
-rw-r--r-- | drivers/hid/usbhid/hid-core.c | 3 | ||||
-rw-r--r-- | drivers/hid/wacom_sys.c | 8 | ||||
-rw-r--r-- | include/linux/hid.h | 11 |
6 files changed, 15 insertions, 17 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 3402033fa52a..ee6ba7625e77 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -1280,12 +1280,6 @@ void hid_output_report(struct hid_report *report, __u8 *data) | |||
1280 | } | 1280 | } |
1281 | EXPORT_SYMBOL_GPL(hid_output_report); | 1281 | EXPORT_SYMBOL_GPL(hid_output_report); |
1282 | 1282 | ||
1283 | static int hid_report_len(struct hid_report *report) | ||
1284 | { | ||
1285 | /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */ | ||
1286 | return ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
1287 | } | ||
1288 | |||
1289 | /* | 1283 | /* |
1290 | * Allocator for buffer that is going to be passed to hid_output_report() | 1284 | * Allocator for buffer that is going to be passed to hid_output_report() |
1291 | */ | 1285 | */ |
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 725f22ca47fc..1e95f4df4146 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -1215,7 +1215,7 @@ static void hidinput_led_worker(struct work_struct *work) | |||
1215 | return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT); | 1215 | return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT); |
1216 | 1216 | ||
1217 | /* fall back to generic raw-output-report */ | 1217 | /* fall back to generic raw-output-report */ |
1218 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | 1218 | len = hid_report_len(report); |
1219 | buf = hid_alloc_report_buf(report, GFP_KERNEL); | 1219 | buf = hid_alloc_report_buf(report, GFP_KERNEL); |
1220 | if (!buf) | 1220 | if (!buf) |
1221 | return; | 1221 | return; |
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 683cda6c60ce..f65e78b46999 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
@@ -827,7 +827,7 @@ static void mt_set_input_mode(struct hid_device *hdev) | |||
827 | r = re->report_id_hash[td->inputmode]; | 827 | r = re->report_id_hash[td->inputmode]; |
828 | if (r) { | 828 | if (r) { |
829 | if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { | 829 | if (cls->quirks & MT_QUIRK_FORCE_GET_FEATURE) { |
830 | report_len = ((r->size - 1) >> 3) + 1 + (r->id > 0); | 830 | report_len = hid_report_len(r); |
831 | buf = hid_alloc_report_buf(r, GFP_KERNEL); | 831 | buf = hid_alloc_report_buf(r, GFP_KERNEL); |
832 | if (!buf) { | 832 | if (!buf) { |
833 | hid_err(hdev, "failed to allocate buffer for report\n"); | 833 | hid_err(hdev, "failed to allocate buffer for report\n"); |
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index ca6849a0121e..b6cb7a5e4b27 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
@@ -338,8 +338,7 @@ static int hid_submit_out(struct hid_device *hid) | |||
338 | report = usbhid->out[usbhid->outtail].report; | 338 | report = usbhid->out[usbhid->outtail].report; |
339 | raw_report = usbhid->out[usbhid->outtail].raw_report; | 339 | raw_report = usbhid->out[usbhid->outtail].raw_report; |
340 | 340 | ||
341 | usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + | 341 | usbhid->urbout->transfer_buffer_length = hid_report_len(report); |
342 | 1 + (report->id > 0); | ||
343 | usbhid->urbout->dev = hid_to_usb_dev(hid); | 342 | usbhid->urbout->dev = hid_to_usb_dev(hid); |
344 | if (raw_report) { | 343 | if (raw_report) { |
345 | memcpy(usbhid->outbuf, raw_report, | 344 | memcpy(usbhid->outbuf, raw_report, |
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 8593047bb726..8e02a4a6fde0 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c | |||
@@ -1321,12 +1321,6 @@ static void wacom_calculate_res(struct wacom_features *features) | |||
1321 | features->unitExpo); | 1321 | features->unitExpo); |
1322 | } | 1322 | } |
1323 | 1323 | ||
1324 | static int wacom_hid_report_len(struct hid_report *report) | ||
1325 | { | ||
1326 | /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */ | ||
1327 | return ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
1328 | } | ||
1329 | |||
1330 | static size_t wacom_compute_pktlen(struct hid_device *hdev) | 1324 | static size_t wacom_compute_pktlen(struct hid_device *hdev) |
1331 | { | 1325 | { |
1332 | struct hid_report_enum *report_enum; | 1326 | struct hid_report_enum *report_enum; |
@@ -1336,7 +1330,7 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev) | |||
1336 | report_enum = hdev->report_enum + HID_INPUT_REPORT; | 1330 | report_enum = hdev->report_enum + HID_INPUT_REPORT; |
1337 | 1331 | ||
1338 | list_for_each_entry(report, &report_enum->report_list, list) { | 1332 | list_for_each_entry(report, &report_enum->report_list, list) { |
1339 | size_t report_size = wacom_hid_report_len(report); | 1333 | size_t report_size = hid_report_len(report); |
1340 | if (report_size > size) | 1334 | if (report_size > size) |
1341 | size = report_size; | 1335 | size = report_size; |
1342 | } | 1336 | } |
diff --git a/include/linux/hid.h b/include/linux/hid.h index 78ea9bf941cd..2366fda010c8 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
@@ -1063,6 +1063,17 @@ static inline void hid_hw_wait(struct hid_device *hdev) | |||
1063 | hdev->ll_driver->wait(hdev); | 1063 | hdev->ll_driver->wait(hdev); |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | /** | ||
1067 | * hid_report_len - calculate the report length | ||
1068 | * | ||
1069 | * @report: the report we want to know the length | ||
1070 | */ | ||
1071 | static inline int hid_report_len(struct hid_report *report) | ||
1072 | { | ||
1073 | /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */ | ||
1074 | return ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
1075 | } | ||
1076 | |||
1066 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, | 1077 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, |
1067 | int interrupt); | 1078 | int interrupt); |
1068 | 1079 | ||