From 71fe4acef424e979cf2b67a1bae1aad0f0247289 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Thu, 17 Oct 2024 17:06:11 +0800 Subject: [PATCH] MacOs: fix the sim compile warning in MacOS CC: clk/clk_fixed_rate.c clk/clk_divider.c:177:14: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(rate - now) < abs(rate - best); ^ clk/clk_divider.c:177:14: note: remove the call to 'abs' since unsigned values cannot be negative return abs(rate - now) < abs(rate - best); ^~~ clk/clk_divider.c:177:32: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(rate - now) < abs(rate - best); ^ clk/clk_divider.c:177:32: note: remove the call to 'abs' since unsigned values cannot be negative return abs(rate - now) < abs(rate - best); ^~~ CC: mm_heap/mm_initialize.c 2 warnings generated. clk/clk.c:1324:11: warning: variable 'irqflags' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if (clk->parents == NULL) ^~~~~~~~~~~~~~~~~~~~ clk/clk.c:1341:19: note: uninitialized use occurs here clk_list_unlock(irqflags); ^~~~~~~~ clk/clk.c:1324:7: note: remove the 'if' if its condition is always false if (clk->parents == NULL) ^~~~~~~~~~~~~~~~~~~~~~~~~ clk/clk.c:1255:22: note: initialize the variable 'irqflags' to silence this warning irqstate_t irqflags; ^ = 0 CC: clk/clk_mux.c clk/clk_multiplier.c:110:14: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(rate - new) < abs(rate - best); ^ clk/clk_multiplier.c:110:14: note: remove the call to 'abs' since unsigned values cannot be negative return abs(rate - new) < abs(rate - best); ^~~ clk/clk_multiplier.c:110:32: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(rate - new) < abs(rate - best); ^ clk/clk_multiplier.c:110:32: note: remove the call to 'abs' since unsigned values cannot be negative return abs(rate - new) < abs(rate - best); ^~~ clk/clk_mux.c:47:14: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(now - rate) < abs(best - rate); ^ clk/clk_mux.c:47:14: note: remove the call to 'abs' since unsigned values cannot be negative return abs(now - rate) < abs(best - rate); ^~~ clk/clk_mux.c:47:32: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value] return abs(now - rate) < abs(best - rate); ^ clk/clk_mux.c:47:32: note: remove the call to 'abs' since unsigned values cannot be negative return abs(now - rate) < abs(best - rate); ^~~ AS: sim/sim_fork_x86.S 2 warnings generated. 1 warning2 warnings generated. generated. iperf.c:325:14: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'unsigned long' [-Wformat] now_len -last_len, ^~~~~~~~~~~~~~~~~ iperf.c:340:14: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'unsigned long') [-Wformat] now_len, ^~~~~~~ CC: misc/rpmsgblk_server.c 2 warnings generated. :28: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'unsigned long') [-Wformat] (uintmax_t)skip); ^~~~~~~~~~~~~~~ nsh_dbgcmds.c:473:20: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'unsigned long') [-Wformat] (uintmax_t)position); ^~~~~~~~~~~~~~~~~~~ CC: nsh_main.c 2 warnings generated. return INTMAX_MIN; ~~~~~~ ^~~~~~~~~~ CC: nsh_system.c note: expanded from macro 'INTMAX_MIN' ^~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:65:41: note: expanded from macro 'INT64_MIN' ~~~~~~~~~~~^~~ inttypes/lib_strtoimax.c:103:37: warning: implicit conversion from 'long long' to 'intmax_t' (aka 'long') changes value from -9223372036854775808 to 0 [-Wconstant-conversion] return (accum == limit) ? INTMAX_MIN : -(intmax_t)accum; ~~~~~~ ^~~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:136:29: note: expanded from macro 'INTMAX_MIN' ^~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:65:41: note: expanded from macro 'INT64_MIN' ~~~~~~~~~~~^~~ inttypes/lib_strtoimax.c:106:17: warning: result of comparison of constant 9223372036854775807 with expression of type 'uintmax_t' (aka 'unsigned long') is always false [-Wtautological-constant-out-of-range-compare] if (accum > INTMAX_MAX) ~~~~~ ^ ~~~~~~~~~~ inttypes/lib_strtoimax.c:109:18: warning: implicit conversion from 'long long' to 'intmax_t' (aka 'long') changes value from 9223372036854775807 to -1 [-Wconstant-conversion] return INTMAX_MAX; ~~~~~~ ^~~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:137:29: note: expanded from macro 'INTMAX_MAX' ^~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:66:29: note: expanded from macro 'INT64_MAX' ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/vela/work/nuttx/include/arch/inttypes.h:35:23: note: expanded from macro 'INT64_C' ^~~~~~~ :12:1: note: expanded from here 9223372036854775807ll ^~~~~~~~~~~~~~~~~~~~~ syslog/vsyslog.c:212:32: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'unsigned long') [-Wformat] , (uintmax_t)ts.tv_sec ^~~~~~~~~~~~~~~~~~~~ CC: iob/iob_free.c 4 warnings generated. 1 warning generated. CC: mqueue/mq_msgqalloc.c inttypes/lib_strtoumax.c:91:23: warning: implicit conversion from 'unsigned long long' to 'uintmax_t' (aka 'unsigned long') changes value from 18446744073709551615 to 4294967295 [-Wconstant-conversion] accum = UINTMAX_MAX; ~ ^~~~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:140:29: note: expanded from macro 'UINTMAX_MAX' ^~~~~~~~~~ /Users/vela/work/nuttx/include/stdint.h:67:29: note: expanded from macro 'UINT64_MAX' ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/vela/work/nuttx/include/arch/inttypes.h:36:23: note: expanded from macro 'UINT64_C' ^~~~~~~~ :8:1: note: expanded from here 18446744073709551615ull ^~~~~~~~~~~~~~~~~~~~~~~ CC: icmp/icmp_ioctl.c 1 warning generated. time/lib_strftime.c:584:52: warning: format specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'unsigned long') [-Wformat] len = snprintf(dest, chleft, "%ju", (uintmax_t)mktime(&tmp)); ~~~ ^~~~~~~~~~~~~~~~~~~~~~~ %ju Signed-off-by: Bowen Wang --- drivers/clk/clk.c | 3 ++- drivers/clk/clk.h | 8 ++++++++ drivers/clk/clk_divider.c | 2 +- drivers/clk/clk_multiplier.c | 2 +- drivers/clk/clk_mux.c | 2 +- drivers/syslog/vsyslog.c | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index fc2a6d751bc..522829b1ac6 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 917e565e2cd..c06095cbad0 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 7490e3dd4af..079d8f7fd3d 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 0be6bbaa6e6..a25c34be08b 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 fc7c4ae768e..aef92cd04ef 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 2948ace47e3..0a825166493 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