Skip to content

Commit 6b3e458

Browse files
gnoackBenjamin Tissoires
authored andcommitted
HID: Document memory allocation properties of report_fixup()
The memory pointer returned by the report_fixup() hook does not get freed by the caller. Instead, report_fixup() must return (in return value and *rsize) a memory buffer with at least the same lifetime as the input buffer (defined by rdesc and original *rsize). This is usually achieved using one of the following techniques: * Returning a pointer and size to a sub-portion of the input buffer * Returning a pointer to a static buffer * Allocating a buffer with a devm_*() function, which will automatically get freed when the device is removed. Signed-off-by: Günther Noack <gnoack@google.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
1 parent f50822f commit 6b3e458

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

include/linux/hid.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,12 @@ struct hid_usage_id {
836836
* raw_event and event should return negative on error, any other value will
837837
* pass the event on to .event() typically return 0 for success.
838838
*
839+
* report_fixup must return a report descriptor pointer whose lifetime is at
840+
* least that of the input rdesc. This is usually done by mutating the input
841+
* rdesc and returning it or a sub-portion of it. In case a new buffer is
842+
* allocated and returned, the implementation of report_fixup is responsible for
843+
* freeing it later.
844+
*
839845
* input_mapping shall return a negative value to completely ignore this usage
840846
* (e.g. doubled or invalid usage), zero to continue with parsing of this
841847
* usage by generic code (no special handling needed) or positive to skip

0 commit comments

Comments
 (0)