diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index fc2a6d751b..522829b1ac 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1337,8 +1337,9 @@ FAR struct clk_s *clk_register(FAR const char *name, return clk; } -out: clk_list_unlock(irqflags); + +out: if (clk->parents) { kmm_free(clk->parents); diff --git a/drivers/clk/clk.h b/drivers/clk/clk.h index 917e565e2c..c06095cbad 100644 --- a/drivers/clk/clk.h +++ b/drivers/clk/clk.h @@ -57,6 +57,14 @@ static inline uint32_t clk_read(uint32_t reg) return *((volatile uint32_t *)(uintptr_t)reg); } +static inline bool clk_is_best_rate_closest(uint32_t rate, uint32_t now, + uint32_t best) +{ + uint32_t rate1 = rate > now ? (rate - now) : (now - rate); + uint32_t rate2 = rate > best ? (rate - best) : (best - rate); + return rate1 < rate2; +} + static inline uint32_t gcd(uint32_t a, uint32_t b) { uint32_t r; diff --git a/drivers/clk/clk_divider.c b/drivers/clk/clk_divider.c index 7490e3dd4a..079d8f7fd3 100644 --- a/drivers/clk/clk_divider.c +++ b/drivers/clk/clk_divider.c @@ -174,7 +174,7 @@ static bool _is_best_div(uint32_t rate, uint32_t now, { if (flags & CLK_DIVIDER_ROUND_CLOSEST) { - return abs(rate - now) < abs(rate - best); + return clk_is_best_rate_closest(rate, now, best); } return now <= rate && now > best; diff --git a/drivers/clk/clk_multiplier.c b/drivers/clk/clk_multiplier.c index 0be6bbaa6e..a25c34be08 100644 --- a/drivers/clk/clk_multiplier.c +++ b/drivers/clk/clk_multiplier.c @@ -107,7 +107,7 @@ static bool __is_best_rate(uint32_t rate, uint32_t new, { if (flags & CLK_MULT_ROUND_CLOSEST) { - return abs(rate - new) < abs(rate - best); + return clk_is_best_rate_closest(rate, new, best); } return new >= rate && new < best; diff --git a/drivers/clk/clk_mux.c b/drivers/clk/clk_mux.c index fc7c4ae768..aef92cd04e 100644 --- a/drivers/clk/clk_mux.c +++ b/drivers/clk/clk_mux.c @@ -44,7 +44,7 @@ static bool mux_is_better_rate(uint32_t rate, uint32_t now, { if (flags & CLK_MUX_ROUND_CLOSEST) { - return abs(now - rate) < abs(best - rate); + return clk_is_best_rate_closest(rate, now, best); } return now <= rate && now > best; diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index 2948ace47e..0a82516649 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -165,7 +165,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) "[%s] " # endif # else - "[%5jd.%06ld] " + "[%5ju.%06ld] " # endif #endif