counter: stm32-timer-cnt: fix ceiling write max value
authorFabrice Gasnier <fabrice.gasnier@foss.st.com>
Tue, 2 Mar 2021 14:43:55 +0000 (15:43 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Mar 2021 08:04:16 +0000 (09:04 +0100)
commitcbc4c42dbec01922c15ac5c8071ff7d9cdc12587
tree323fb3748c2e3136958511461cba42ac23ace0cd
parentdcdde25844d4ec41b44e1538d2da39404327032d
counter: stm32-timer-cnt: fix ceiling write max value

commit e4c3e133294c0a292d21073899b05ebf530169bd upstream.

The ceiling value isn't checked before writing it into registers. The user
could write a value higher than the counter resolution (e.g. 16 or 32 bits
indicated by max_arr). This makes most significant bits to be truncated.
Fix it by checking the max_arr to report a range error [1] to the user.

[1] https://lkml.org/lkml/2021/2/12/358

Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder")
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1614696235-24088-1-git-send-email-fabrice.gasnier@foss.st.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/counter/stm32-timer-cnt.c