]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
clk: mxs: Use clamp() in clk_ref_round_rate() and clk_ref_set_rate()
authorThorsten Blum <thorsten.blum@toblux.com>
Wed, 10 Jul 2024 14:33:10 +0000 (16:33 +0200)
committerStephen Boyd <sboyd@kernel.org>
Wed, 10 Jul 2024 20:08:59 +0000 (13:08 -0700)
Use clamp() instead of duplicating its implementation.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Link: https://lore.kernel.org/r/20240710143309.706135-2-thorsten.blum@toblux.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mxs/clk-ref.c

index 3161a0b021eea2a5e28a75d7a71c32438b2a9790..2297259da89ab0bce2a00536a00e1c7aa7a9729d 100644 (file)
@@ -66,12 +66,7 @@ static long clk_ref_round_rate(struct clk_hw *hw, unsigned long rate,
 
        tmp = tmp * 18 + rate / 2;
        do_div(tmp, rate);
-       frac = tmp;
-
-       if (frac < 18)
-               frac = 18;
-       else if (frac > 35)
-               frac = 35;
+       frac = clamp(tmp, 18, 35);
 
        tmp = parent_rate;
        tmp *= 18;
@@ -91,12 +86,7 @@ static int clk_ref_set_rate(struct clk_hw *hw, unsigned long rate,
 
        tmp = tmp * 18 + rate / 2;
        do_div(tmp, rate);
-       frac = tmp;
-
-       if (frac < 18)
-               frac = 18;
-       else if (frac > 35)
-               frac = 35;
+       frac = clamp(tmp, 18, 35);
 
        spin_lock_irqsave(&mxs_lock, flags);