2022-09-20 10:46:50

by Jianqun Xu

[permalink] [raw]
Subject: [PATCH 12/20] gpio/rockchip: add return check for clock rate set

Check if the clock rate set for the apb clock is successful or not.

Signed-off-by: Jianqun Xu <[email protected]>
---
drivers/gpio/gpio-rockchip.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
index e36cdbd4bbef..511e93a6a429 100644
--- a/drivers/gpio/gpio-rockchip.c
+++ b/drivers/gpio/gpio-rockchip.c
@@ -199,6 +199,9 @@ 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)
return -EINVAL;
--
2.25.1


2022-09-30 09:32:20

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 12/20] gpio/rockchip: add return check for clock rate set

On Tue, Sep 20, 2022 at 12:31 PM Jianqun Xu <[email protected]> wrote:
>
> Check if the clock rate set for the apb clock is successful or not.
>
> Signed-off-by: Jianqun Xu <[email protected]>
> ---
> drivers/gpio/gpio-rockchip.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
> index e36cdbd4bbef..511e93a6a429 100644
> --- a/drivers/gpio/gpio-rockchip.c
> +++ b/drivers/gpio/gpio-rockchip.c
> @@ -199,6 +199,9 @@ 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)
> return -EINVAL;
> --
> 2.25.1
>

This cannot happen, clk_get_rate() can only return 0 for clk == NULL.
We're not using an optional clock.

Bart

2022-09-30 10:01:18

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 12/20] gpio/rockchip: add return check for clock rate set

On Fri, Sep 30, 2022 at 11:17 AM Bartosz Golaszewski <[email protected]> wrote:
>
> On Tue, Sep 20, 2022 at 12:31 PM Jianqun Xu <[email protected]> wrote:
> >
> > Check if the clock rate set for the apb clock is successful or not.
> >
> > Signed-off-by: Jianqun Xu <[email protected]>
> > ---
> > drivers/gpio/gpio-rockchip.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c
> > index e36cdbd4bbef..511e93a6a429 100644
> > --- a/drivers/gpio/gpio-rockchip.c
> > +++ b/drivers/gpio/gpio-rockchip.c
> > @@ -199,6 +199,9 @@ 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)
> > return -EINVAL;
> > --
> > 2.25.1
> >
>
> This cannot happen, clk_get_rate() can only return 0 for clk == NULL.
> We're not using an optional clock.
>

Ah, sorry actually the db_clk can be NULL for certain variants. But in
that case shouldn't we just silently ignore it and return 0? Or return
-ENOTSUPP at the very least?

Bart