Messages in this thread | | | Date | Mon, 1 Dec 2014 21:36:05 +0100 (CET) | From | Jiri Kosina <> | Subject | Re: [PATCH] hid: export hid_report_len as an inline function in hid.h |
| |
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 <mathieu.magnaudet@enac.fr>
Applied, thanks.
[ ... snip ... ] > 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
| |