Thread (4 messages) 4 messages, 4 authors, 2014-12-01

Re: [PATCH] hid: export hid_report_len as an inline function in hid.h

From: Jiri Kosina <hidden>
Date: 2014-12-01 20:35:53
Also in: lkml

On Thu, 27 Nov 2014, Mathieu Magnaudet wrote:
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 <redacted>
Applied, thanks.

[ ... snip ... ]
quoted hunk ↗ jump to hunk
diff --git a/include/linux/hid.h b/include/linux/hid.h
index d585d02..06c4607 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -1087,6 +1087,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);
BTW this makes me -- being the person resposible for that ugly calculation 
-- wonder whether we shouldn't, in the name of readability, just drop the 
comment and make the code look that way instead.

-- 
Jiri Kosina
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help