mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ye Zhang <ye.zhang@rock-chips.com>
To: linus.walleij@linaro.org, brgl@bgdev.pl, heiko@sntech.de,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	tao.huang@rock-chips.com, finley.xiao@rock-chips.com,
	tim.chen@rock-chips.com, elaine.zhang@rock-chips.com,
	Ye Zhang <ye.zhang@rock-chips.com>
Subject: [PATCH v1 4/5] gpio: rockchip: avoid division by zero
Date: Thu, 15 Aug 2024 15:16:50 +0800	[thread overview]
Message-ID: <20240815071651.3645949-5-ye.zhang@rock-chips.com> (raw)
In-Reply-To: <20240815071651.3645949-1-ye.zhang@rock-chips.com>

If the clk_get_rate return '0', it will happen division by zero.

Signed-off-by: Ye Zhang <ye.zhang@rock-chips.com>
---
 drivers/gpio/gpio-rockchip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index 8949324ed816..03e949b0a344 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -212,8 +212,10 @@ static int rockchip_gpio_set_debounce(struct gpio_chip *gc,
 	if (bank->gpio_type == GPIO_TYPE_V2 && !IS_ERR(bank->db_clk)) {
 		div_debounce_support = true;
 		freq = clk_get_rate(bank->db_clk);
+		if (!freq)
+			return -EINVAL;
 		max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq;
-		if (debounce > max_debounce)
+		if ((unsigned long)debounce > max_debounce)
 			return -EINVAL;
 
 		div = debounce * freq;
-- 
2.34.1


  parent reply	other threads:[~2024-08-15  7:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-15  7:16 [PATCH v1 0/5] gpio: rockchip: Update the GPIO driver Ye Zhang
2024-08-15  7:16 ` [PATCH v1 1/5] gpio: rockchip: support acpi Ye Zhang
2024-08-16  9:48   ` Bartosz Golaszewski
2024-08-26  6:21   ` Dan Carpenter
2024-08-15  7:16 ` [PATCH v1 2/5] gpio: rockchip: support GPIO_TYPE_V2_2 Ye Zhang
2024-08-16  9:49   ` Bartosz Golaszewski
2024-08-15  7:16 ` [PATCH v1 3/5] gpio: rockchip: Set input direction in irq_request_resources Ye Zhang
2024-08-16  9:49   ` Bartosz Golaszewski
2024-08-15  7:16 ` Ye Zhang [this message]
2024-08-16  9:51   ` [PATCH v1 4/5] gpio: rockchip: avoid division by zero Bartosz Golaszewski
2024-08-15  7:16 ` [PATCH v1 5/5] rockchip: gpio: fix debounce config error Ye Zhang
2024-08-16 10:11   ` Bartosz Golaszewski
2024-08-16  9:46 ` [PATCH v1 0/5] gpio: rockchip: Update the GPIO driver Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240815071651.3645949-5-ye.zhang@rock-chips.com \
    --to=ye.zhang@rock-chips.com \
    --cc=brgl@bgdev.pl \
    --cc=elaine.zhang@rock-chips.com \
    --cc=finley.xiao@rock-chips.com \
    --cc=heiko@sntech.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=tao.huang@rock-chips.com \
    --cc=tim.chen@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®