Commit 19c2aedc54b927ab10d3723038182eedf90438a4
Committed by
Greg Kroah-Hartman
1 parent
43c0364551
staging:iio: IIO_EVENT_CODE: Clamp channel numbers
Make sure we only use the allotted space for channel numbers in the event mask and do not let them override other fields. Since negative values are valid channel number, cast the channel number to signed when extracting it from an event mask. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 1 changed file with 3 additions and 2 deletions Side-by-side Diff
drivers/staging/iio/events.h
... | ... | @@ -56,7 +56,8 @@ |
56 | 56 | type, chan, chan1, chan2) \ |
57 | 57 | (((u64)type << 56) | ((u64)diff << 55) | \ |
58 | 58 | ((u64)direction << 48) | ((u64)modifier << 40) | \ |
59 | - ((u64)chan_type << 32) | (chan2 << 16) | chan1 | chan) | |
59 | + ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ | |
60 | + ((u16)chan)) | |
60 | 61 | |
61 | 62 | |
62 | 63 | #define IIO_EV_DIR_MAX 4 |
... | ... | @@ -95,7 +96,7 @@ |
95 | 96 | |
96 | 97 | /* Event code number extraction depends on which type of event we have. |
97 | 98 | * Perhaps review this function in the future*/ |
98 | -#define IIO_EVENT_CODE_EXTRACT_NUM(mask) (mask & 0xFFFF) | |
99 | +#define IIO_EVENT_CODE_EXTRACT_NUM(mask) ((__s16)(mask & 0xFFFF)) | |
99 | 100 | |
100 | 101 | #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF) |
101 | 102 |