Re: [PATCH v2] gpio: rockchip: avoid division by zero

From: Andy Shevchenko
Date: Fri Aug 23 2024 - 10:46:10 EST


On Fri, Aug 23, 2024 at 11:43:04AM +0800, Ye Zhang wrote:
> If the clk_get_rate return '0', it will happen division by zero.

At the abstraction level this is good to avoid 0 division and return an error,
but...

> freq = clk_get_rate(bank->db_clk);
> + if (!freq)
> + return -EINVAL;

...do you this the absence of debounce here is a fatal error?
(Yes, I see it's a fatal when it's bigger than maximum.)

> max_debounce = (GENMASK(23, 0) + 1) * 2 * 1000000 / freq;
> if (debounce > max_debounce)
> return -EINVAL;

--
With Best Regards,
Andy Shevchenko