Skip to content

Commit dabb05c

Browse files
mmagnaudetJiri Kosina
authored andcommitted
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 <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Reviewed-by: David Herrmann <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent da10bc2 commit dabb05c

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

drivers/hid/hid-core.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,6 @@ void hid_output_report(struct hid_report *report, __u8 *data)
12801280
}
12811281
EXPORT_SYMBOL_GPL(hid_output_report);
12821282

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-
12891283
/*
12901284
* Allocator for buffer that is going to be passed to hid_output_report()
12911285
*/

drivers/hid/hid-input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ static void hidinput_led_worker(struct work_struct *work)
12151215
return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT);
12161216

12171217
/* fall back to generic raw-output-report */
1218-
len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1218+
len = hid_report_len(report);
12191219
buf = hid_alloc_report_buf(report, GFP_KERNEL);
12201220
if (!buf)
12211221
return;

drivers/hid/hid-multitouch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static void mt_set_input_mode(struct hid_device *hdev)
827827
r = re->report_id_hash[td->inputmode];
828828
if (r) {
829829
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);
831831
buf = hid_alloc_report_buf(r, GFP_KERNEL);
832832
if (!buf) {
833833
hid_err(hdev, "failed to allocate buffer for report\n");

drivers/hid/usbhid/hid-core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ static int hid_submit_out(struct hid_device *hid)
338338
report = usbhid->out[usbhid->outtail].report;
339339
raw_report = usbhid->out[usbhid->outtail].raw_report;
340340

341-
usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) +
342-
1 + (report->id > 0);
341+
usbhid->urbout->transfer_buffer_length = hid_report_len(report);
343342
usbhid->urbout->dev = hid_to_usb_dev(hid);
344343
if (raw_report) {
345344
memcpy(usbhid->outbuf, raw_report,

drivers/hid/wacom_sys.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,6 @@ static void wacom_calculate_res(struct wacom_features *features)
13211321
features->unitExpo);
13221322
}
13231323

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-
13301324
static size_t wacom_compute_pktlen(struct hid_device *hdev)
13311325
{
13321326
struct hid_report_enum *report_enum;
@@ -1336,7 +1330,7 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev)
13361330
report_enum = hdev->report_enum + HID_INPUT_REPORT;
13371331

13381332
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);
13401334
if (report_size > size)
13411335
size = report_size;
13421336
}

include/linux/hid.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,17 @@ static inline void hid_hw_wait(struct hid_device *hdev)
10631063
hdev->ll_driver->wait(hdev);
10641064
}
10651065

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+
10661077
int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
10671078
int interrupt);
10681079

0 commit comments

Comments
 (0)