This is a note to let you know that I've just added the patch titled counter: stm32-timer-cnt: fix ceiling write max value to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: counter-stm32-timer-cnt-fix-ceiling-write-max-value.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From e4c3e133294c0a292d21073899b05ebf530169bd Mon Sep 17 00:00:00 2001 From: Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx> Date: Tue, 2 Mar 2021 15:43:55 +0100 Subject: counter: stm32-timer-cnt: fix ceiling write max value From: Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx> 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@xxxxxxxxxxx> Acked-by: William Breathitt Gray <vilhelm.gray@xxxxxxxxx> Cc: <Stable@xxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/1614696235-24088-1-git-send-email-fabrice.gasnier@xxxxxxxxxxx Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/counter/stm32-timer-cnt.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -25,6 +25,7 @@ struct stm32_timer_cnt { struct regmap *regmap; struct clk *clk; u32 ceiling; + u32 max_arr; }; /** @@ -189,6 +190,9 @@ static ssize_t stm32_count_ceiling_write if (ret) return ret; + if (ceiling > priv->max_arr) + return -ERANGE; + /* TIMx_ARR register shouldn't be buffered (ARPE=0) */ regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); regmap_write(priv->regmap, TIM_ARR, ceiling); @@ -366,6 +370,7 @@ static int stm32_timer_cnt_probe(struct priv->regmap = ddata->regmap; priv->clk = ddata->clk; priv->ceiling = ddata->max_arr; + priv->max_arr = ddata->max_arr; priv->counter.name = dev_name(dev); priv->counter.parent = dev; Patches currently in stable-queue which might be from fabrice.gasnier@xxxxxxxxxxx are queue-5.4/counter-stm32-timer-cnt-report-count-function-when-s.patch queue-5.4/counter-stm32-timer-cnt-fix-ceiling-write-max-value.patch