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

From: Jiri Kosina
Date: Mon Dec 01 2014 - 15:35:55 EST


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@xxxxxxx>

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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/