From 63cfe63d8144fbaef2c8ffead9576427e1610e77 Mon Sep 17 00:00:00 2001 From: Ye Zhang Date: Fri, 9 Aug 2024 10:05:21 +0800 Subject: [PATCH] gpio: rockchip: Prevent underflow unsigned variables. Signed-off-by: Ye Zhang Change-Id: I2910fe7c57683bbd175cbc4b28584ff84f037d07 --- drivers/gpio/gpio-rockchip.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index c726e22611fa..360c9aa9ae8c 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -209,11 +209,12 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, unsigned int cur_div_reg; u64 div; - if (bank->gpio_type >= GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) { - div_debounce_support = true; + 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; + div = (u64)(GENMASK(23, 0) + 1) * 1000000; if (bank->gpio_type == GPIO_TYPE_V2) max_debounce = DIV_ROUND_CLOSEST_ULL(div, freq); @@ -227,8 +228,6 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc, div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC) - 1; else div_reg = DIV_ROUND_CLOSEST_ULL(div, USEC_PER_SEC / 2) - 1; - } else { - div_debounce_support = false; } raw_spin_lock_irqsave(&bank->slock, flags);