[PATCH v2] gpio: rockchip: resolve underflow issue
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Fri Aug 23 07:51:04 PDT 2024
On Fri, Aug 23, 2024 at 11:43:07AM +0800, Ye Zhang wrote:
> div_reg may be < 0 if debounce is zero, causing the unsigned int to
> overflow.
...
> - if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
> - div_debounce_support = true;
Wouldn't be cleaner (from the patch perspective) to simply move else branch here?
else
div_debounce_support = false;
> + div_debounce_support = (bank->gpio_type == GPIO_TYPE_V2) && !IS_ERR(bank->db_clk);
> + if (debounce && div_debounce_support) {
> freq = clk_get_rate(bank->db_clk);
> if (!freq)
> return -EINVAL;
> @@ -216,8 +216,6 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
>
> div = (u64)debounce * freq;
> div_reg = DIV_ROUND_CLOSEST_ULL(div, 2 * USEC_PER_SEC) - 1;
> - } else {
> - div_debounce_support = false;
> }
--
With Best Regards,
Andy Shevchenko
More information about the Linux-rockchip
mailing list