diff --git a/arch/arm/src/lpc43xx/lpc43_tickless_rit.c b/arch/arm/src/lpc43xx/lpc43_tickless_rit.c index 44eba05bbc..daf4bc7888 100644 --- a/arch/arm/src/lpc43xx/lpc43_tickless_rit.c +++ b/arch/arm/src/lpc43xx/lpc43_tickless_rit.c @@ -35,6 +35,8 @@ #include #include +#include + #include #include #include @@ -46,14 +48,6 @@ #ifdef CONFIG_SCHED_TICKLESS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef min -# define min(a,b) (a < b ? a : b) -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -428,13 +422,13 @@ static bool lpc43_tl_set_calc_arm(uint32_t curr, uint32_t to_set, bool arm) if (curr < TO_RESET_NEXT) { - calc_time = min(TO_RESET_NEXT, to_set); + calc_time = MIN(TO_RESET_NEXT, to_set); } else { if (curr < TO_END) { - calc_time = min(curr + RESET_TICKS, to_set); + calc_time = MIN(curr + RESET_TICKS, to_set); } else { diff --git a/arch/arm/src/lpc54xx/lpc54_tickless.c b/arch/arm/src/lpc54xx/lpc54_tickless.c index bd6278b85e..6740e08a7b 100644 --- a/arch/arm/src/lpc54xx/lpc54_tickless.c +++ b/arch/arm/src/lpc54xx/lpc54_tickless.c @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -42,10 +44,6 @@ * Pre-processor Definitions ****************************************************************************/ -#ifndef min -# define min(a,b) (a < b ? a : b) -#endif - #define COUNTER_MAX 0x0000ffffffffffffllu /**************************************************************************** @@ -468,13 +466,13 @@ static bool lpc54_set_calc_arm(uint64_t curr, uint64_t to_set, bool arm) if (curr < g_to_reset_next) { - calc_time = min(g_to_reset_next, to_set); + calc_time = MIN(g_to_reset_next, to_set); } else { if (curr < g_to_end) { - calc_time = min(curr + g_reset_ticks, to_set); + calc_time = MIN(curr + g_reset_ticks, to_set); } else { diff --git a/arch/arm/src/s32k3xx/s32k3xx_emac.c b/arch/arm/src/s32k3xx/s32k3xx_emac.c index e5be2db74a..8f4d734154 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_emac.c +++ b/arch/arm/src/s32k3xx/s32k3xx_emac.c @@ -35,6 +35,8 @@ #include #include +#include + #include #include @@ -138,10 +140,6 @@ # warning "You are using an incomplete/untested configuration" #endif -#ifndef min -# define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - /* We need at least one more free buffer than transmit buffers */ #define S32K3XX_EMAC_NFREEBUFFERS (CONFIG_S32K3XX_ENET_NTXBUFFERS+1) @@ -1319,7 +1317,7 @@ static int s32k3xx_recvframe(struct s32k3xx_driver_s *priv) up_invalidate_dcache((uintptr_t)dev->d_buf, (uintptr_t)dev->d_buf + - min(dev->d_len, ALIGNED_BUFSIZE)); + MIN(dev->d_len, ALIGNED_BUFSIZE)); ninfo("rxhead: %p d_buf: %p d_len: %d\n", priv->rxhead, dev->d_buf, dev->d_len); diff --git a/arch/arm/src/s32k3xx/s32k3xx_progmem.c b/arch/arm/src/s32k3xx/s32k3xx_progmem.c index 89975829c7..38be56657d 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_progmem.c +++ b/arch/arm/src/s32k3xx/s32k3xx_progmem.c @@ -30,6 +30,8 @@ #include #include +#include + #include "hardware/s32k3xx_pflash.h" #include "hardware/s32k3xx_xrdc.h" @@ -51,11 +53,6 @@ # error Progmem must be a multiple of 8 #endif -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -392,7 +389,7 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count) execute_init_sequence(dest); - for (i = 0; i < min(32, words_to_write); i++) + for (i = 0; i < MIN(32, words_to_write); i++) { if (offset > 0) { diff --git a/arch/arm/src/s32k3xx/s32k3xx_qspi.c b/arch/arm/src/s32k3xx/s32k3xx_qspi.c index c587008f22..4fde2bdb66 100644 --- a/arch/arm/src/s32k3xx/s32k3xx_qspi.c +++ b/arch/arm/src/s32k3xx/s32k3xx_qspi.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -75,8 +76,6 @@ #define ALIGN_UP(n) (((n)+ALIGN_MASK) & ~ALIGN_MASK) #define IS_ALIGNED(n) (((uint32_t)(n) & ALIGN_MASK) == 0) -#define min(a, b) (((a) < (b)) ? (a) : (b)) - /* LUT entries used for various command sequences */ #define QSPI_LUT_READ 0U /* Quad Output read */ #define QSPI_LUT_WRITE 1U /* Quad write */ @@ -683,7 +682,7 @@ static int qspi_receive_blocking(struct s32k3xx_qspidev_s *priv, uint32_t regval; int ret = 0; - readlen = min(128, remaining); + readlen = MIN(128, remaining); /* Copy sequence in LUT registers */ @@ -703,7 +702,7 @@ static int qspi_receive_blocking(struct s32k3xx_qspidev_s *priv, regval |= QSPI_MCR_CLR_RXF; putreg32(regval, S32K3XX_QSPI_MCR); - readlen = min(128, remaining); + readlen = MIN(128, remaining); #ifdef CONFIG_S32K3XX_QSPI_INTERRUPTS /* enable end of transfer interrupt for asynchronous transfers */ @@ -886,7 +885,7 @@ static int qspi_transmit_blocking(struct s32k3xx_qspidev_s *priv, uint32_t regval; uint32_t count = UINT32_MAX; uint32_t *data = (uint32_t *)meminfo->buffer; - uint32_t write_cycle = min(32, ((uint32_t)remaining) >> 2U); + uint32_t write_cycle = MIN(32, ((uint32_t)remaining) >> 2U); uint32_t timeout = 1000; int ret = 0; diff --git a/arch/arm/src/stm32f0l0g0/stm32_pwm.h b/arch/arm/src/stm32f0l0g0/stm32_pwm.h index 2cdb8f3324..93757a06dc 100644 --- a/arch/arm/src/stm32f0l0g0/stm32_pwm.h +++ b/arch/arm/src/stm32f0l0g0/stm32_pwm.h @@ -50,6 +50,8 @@ #include #include +#include + #include "chip.h" #include "hardware/stm32_tim.h" @@ -326,15 +328,13 @@ #endif #define PWM_TIM17_NCHANNELS PWM_TIM17_CHANNEL1 -#define PWM_MAX(a, b) ((a) > (b) ? (a) : (b)) - -#define PWM_NCHANNELS PWM_MAX(PWM_TIM1_NCHANNELS, \ - PWM_MAX(PWM_TIM2_NCHANNELS, \ - PWM_MAX(PWM_TIM3_NCHANNELS, \ - PWM_MAX(PWM_TIM14_NCHANNELS, \ - PWM_MAX(PWM_TIM15_NCHANNELS, \ - PWM_MAX(PWM_TIM16_NCHANNELS, \ - PWM_TIM17_NCHANNELS)))))) +#define PWM_NCHANNELS MAX(PWM_TIM1_NCHANNELS, \ + MAX(PWM_TIM2_NCHANNELS, \ + MAX(PWM_TIM3_NCHANNELS, \ + MAX(PWM_TIM14_NCHANNELS, \ + MAX(PWM_TIM15_NCHANNELS, \ + MAX(PWM_TIM16_NCHANNELS, \ + PWM_TIM17_NCHANNELS)))))) #else /* !CONFIG_PWM_MULTICHAN */ diff --git a/arch/arm/src/stm32h7/stm32_ethernet.c b/arch/arm/src/stm32h7/stm32_ethernet.c index 14e468cfa4..567d4b0cb1 100644 --- a/arch/arm/src/stm32h7/stm32_ethernet.c +++ b/arch/arm/src/stm32h7/stm32_ethernet.c @@ -33,6 +33,8 @@ #include #include +#include + #include #include @@ -213,10 +215,6 @@ # define CONFIG_STM32H7_ETH_NTXDESC 4 #endif -#ifndef min -# define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - /* We need at least one more free buffer than transmit buffers */ #define STM32_ETH_NFREEBUFFERS (CONFIG_STM32H7_ETH_NTXDESC+1) @@ -1795,7 +1793,7 @@ static int stm32_recvframe(struct stm32_ethmac_s *priv) up_invalidate_dcache((uintptr_t)dev->d_buf, (uintptr_t)dev->d_buf + - min(dev->d_len, ALIGNED_BUFSIZE)); + MIN(dev->d_len, ALIGNED_BUFSIZE)); ninfo("rxhead: %p d_buf: %p d_len: %d\n", priv->rxhead, dev->d_buf, dev->d_len); diff --git a/arch/risc-v/src/common/riscv_pmp.c b/arch/risc-v/src/common/riscv_pmp.c index 0e32f1be53..a802074ab7 100644 --- a/arch/risc-v/src/common/riscv_pmp.c +++ b/arch/risc-v/src/common/riscv_pmp.c @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -77,14 +79,6 @@ region##_val; \ }) -#ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -680,7 +674,7 @@ int riscv_check_pmp_access(uintptr_t attr, uintptr_t base, uintptr_t size) { /* Found matching region that allows access */ - size -= min(end, entry.end) - max(base, entry.base); + size -= MIN(end, entry.end) - MAX(base, entry.base); } else { diff --git a/arch/risc-v/src/litex/litex_sdio.c b/arch/risc-v/src/litex/litex_sdio.c index 9be0b2e958..13359662a3 100644 --- a/arch/risc-v/src/litex/litex_sdio.c +++ b/arch/risc-v/src/litex/litex_sdio.c @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -88,9 +90,6 @@ # define CONFIG_LITEX_SD4BIT_FREQ 50000000 /* 25MHz SD 4-bit, normal clocking */ #endif -#define max(x, y) (((x) > (y)) ? (x) : (y)) -#define min(x, y) (((x) < (y)) ? (x) : (y)) - /**************************************************************************** * Private Types ****************************************************************************/ @@ -626,7 +625,7 @@ static void litex_clock(struct sdio_dev_s *dev, enum sdio_clock_e rate) uint32_t divider; divider = clk_freq ? litex_get_hfclk() / clk_freq : MAX_DIVIDER; divider = litex_pow2roundup(divider); - divider = min(max(divider, 2), MAX_DIVIDER); + divider = MIN(MAX(divider, 2), MAX_DIVIDER); /* this is the *effective* new clk_freq */ diff --git a/drivers/crypto/dev_urandom.c b/drivers/crypto/dev_urandom.c index 8d3affd569..b6c6efda87 100644 --- a/drivers/crypto/dev_urandom.c +++ b/drivers/crypto/dev_urandom.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -79,8 +80,6 @@ union xorshift128_state_u * Private Function Prototypes ****************************************************************************/ -#define min(a, b) (((a) < (b)) ? (a) : (b)) - static ssize_t devurand_read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t devurand_write(FAR struct file *filep, FAR const char *buffer, @@ -220,7 +219,7 @@ static ssize_t devurand_write(FAR struct file *filep, FAR const char *buffer, #ifdef CONFIG_DEV_URANDOM_CONGRUENTIAL unsigned int seed = 0; - len = min(len, sizeof(unsigned int)); + len = MIN(len, sizeof(unsigned int)); memcpy(&seed, buffer, len); srand(seed); return len; @@ -242,7 +241,7 @@ static ssize_t devurand_write(FAR struct file *filep, FAR const char *buffer, { /* Make unaligned input aligned. */ - currlen = min(sizeof(uint32_t) - ((uintptr_t)buffer & alignmask), len); + currlen = MIN(sizeof(uint32_t) - ((uintptr_t)buffer & alignmask), len); memcpy(&tmp, buffer, currlen); up_rngaddint(RND_SRC_SW, tmp); @@ -276,7 +275,7 @@ static ssize_t devurand_write(FAR struct file *filep, FAR const char *buffer, return initlen; #else - len = min(len, sizeof(g_prng.u)); + len = MIN(len, sizeof(g_prng.u)); memcpy(&g_prng.u, buffer, len); return len; #endif diff --git a/drivers/usbdev/pl2303.c b/drivers/usbdev/pl2303.c index b995babe55..9248acd76f 100644 --- a/drivers/usbdev/pl2303.c +++ b/drivers/usbdev/pl2303.c @@ -37,6 +37,8 @@ #include #include +#include + #include #include #include @@ -199,18 +201,6 @@ #define PL2303_RWREQUEST_TYPE (0x40) #define PL2303_RWREQUEST (0x01) /* IN/OUT, Recipient device */ -/* Misc Macros **************************************************************/ - -/* min/max macros */ - -#ifndef min -# define min(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifndef max -# define max(a,b) ((a)>(b)?(a):(b)) -#endif - /* Trace values *************************************************************/ #define PL2303_CLASSAPI_SETUP TRACE_EVENT(TRACE_CLASSAPI_ID, USBSER_TRACECLASSAPI_SETUP) @@ -617,7 +607,7 @@ static int usbclass_sndpacket(FAR struct pl2303_dev_s *priv) /* Get the maximum number of bytes that will fit into one bulk IN request */ - reqlen = max(CONFIG_PL2303_BULKIN_REQLEN, ep->maxpacket); + reqlen = MAX(CONFIG_PL2303_BULKIN_REQLEN, ep->maxpacket); while (!sq_empty(&priv->reqlist)) { @@ -1809,7 +1799,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, { case PL2303_SETLINEREQUEST: { - memcpy(priv->linest, ctrlreq->buf, min(len, 7)); + memcpy(priv->linest, ctrlreq->buf, MIN(len, 7)); ret = 0; } break; @@ -1897,7 +1887,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, if (ret >= 0) { - ctrlreq->len = min(len, ret); + ctrlreq->len = MIN(len, ret); ctrlreq->flags = USBDEV_REQFLAGS_NULLPKT; ret = EP_SUBMIT(dev->ep0, ctrlreq); if (ret < 0) diff --git a/drivers/usbdev/rndis.c b/drivers/usbdev/rndis.c index 3f01f6c9fe..52b5e7fa49 100644 --- a/drivers/usbdev/rndis.c +++ b/drivers/usbdev/rndis.c @@ -35,6 +35,8 @@ #include #include +#include + #include #include #include @@ -96,14 +98,6 @@ #define ETHWORK LPWORK -#ifndef min -# define min(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifndef max -# define max(a,b) ((a)>(b)?(a):(b)) -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -813,7 +807,7 @@ static uint16_t rndis_fillrequest(FAR struct rndis_dev_s *priv, req->len = 0; - datalen = min(priv->netdev.d_len, + datalen = MIN(priv->netdev.d_len, CONFIG_RNDIS_BULKIN_REQLEN - RNDIS_PACKET_HDR_SIZE); if (datalen > 0) { @@ -1135,7 +1129,7 @@ static inline int rndis_recvpacket(FAR struct rndis_dev_s *priv, { size_t index = priv->current_rx_received - priv->current_rx_datagram_offset; - size_t copysize = min(reqlen, + size_t copysize = MIN(reqlen, priv->current_rx_datagram_size - index); /* Check if the received packet exceeds request buffer */ @@ -2442,7 +2436,7 @@ static int usbclass_setup(FAR struct usbdevclass_driver_s *driver, if (ret >= 0) { - ctrlreq->len = min(len, ret); + ctrlreq->len = MIN(len, ret); ctrlreq->flags = USBDEV_REQFLAGS_NULLPKT; ret = EP_SUBMIT(dev->ep0, ctrlreq); if (ret < 0) diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c index c4f156ebcc..20f0be4474 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_driver.c @@ -997,7 +997,7 @@ static int bcmf_wl_scan_format_results(FAR struct bcmf_dev_s *priv, for (i = 0; i < priv->scan_result_entries; i++) { scan_result[i] = &priv->scan_result[i]; - len += (min(strlen((FAR const char *)scan_result[i]->SSID), + len += (MIN(strlen((FAR const char *)scan_result[i]->SSID), 32) + 3) & ~3; } @@ -1045,7 +1045,7 @@ static int bcmf_wl_scan_format_results(FAR struct bcmf_dev_s *priv, iwe = (FAR struct iw_event *)pointer; iwe->cmd = SIOCGIWESSID; iwe->u.essid.flags = 0; - iwe->u.essid.length = min(strlen((FAR const char *)info->SSID), 32); + iwe->u.essid.length = MIN(strlen((FAR const char *)info->SSID), 32); iwe->u.essid.pointer = (FAR void *)sizeof(iwe->u.essid); memcpy(&iwe->u.essid + 1, info->SSID, iwe->u.essid.length); iwe->len = IW_EV_LEN(essid) + ((iwe->u.essid.length + 3) & ~3); diff --git a/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.h b/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.h index b2c399aac1..0c58a18f61 100644 --- a/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.h +++ b/drivers/wireless/ieee80211/bcm43xxx/bcmf_utils.h @@ -26,14 +26,7 @@ ****************************************************************************/ #include - -#ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) -#endif +#include /**************************************************************************** * Public Function Prototypes diff --git a/libs/libc/misc/lib_ncompress.c b/libs/libc/misc/lib_ncompress.c index 26b4746619..a1c5fc8a4b 100644 --- a/libs/libc/misc/lib_ncompress.c +++ b/libs/libc/misc/lib_ncompress.c @@ -87,9 +87,6 @@ #define MARK(a) { asm(" .globl M.a"); asm("M.a:"); } -#undef min -#define min(a,b) ((a>b) ? b : a) - #ifndef IBUFSIZ # define IBUFSIZ BUFSIZ /* Defailt input buffer size */ #endif diff --git a/libs/libc/stdlib/lib_qsort.c b/libs/libc/stdlib/lib_qsort.c index 293b4b0e03..0801631f2c 100644 --- a/libs/libc/stdlib/lib_qsort.c +++ b/libs/libc/stdlib/lib_qsort.c @@ -47,14 +47,13 @@ #include #include +#include #include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define min(a, b) (a) < (b) ? a : b - #define swapcode(TYPE, parmi, parmj, n) \ { \ long i = (n) / sizeof (TYPE); \ @@ -275,10 +274,10 @@ loop: } pn = (FAR char *)base + nel * width; - r = min(pa - (FAR char *)base, pb - pa); + r = MIN(pa - (FAR char *)base, pb - pa); vecswap(base, pb - r, r); - r = min(pd - pc, pn - pd - width); + r = MIN(pd - pc, pn - pd - width); vecswap(pb, pn - r, r); if ((r = pb - pa) > width) diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 93985a4002..8afebf1821 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -58,6 +58,8 @@ #include #include +#include + #include #include #include @@ -120,7 +122,6 @@ /* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ #define is_digit(c) ((unsigned)(c) - '0' <= 9) -#define BIGGEST(a, b) (((a) > (b)) ? (a) : (b)) #define MY_TZNAME_MAX 255 /* Max and min values of the integer type T, of which only the bottom @@ -150,7 +151,7 @@ * for ttunspecified to work without crashing. */ -#define CHARS_EXTRA (BIGGEST(sizeof(UNSPEC), 2) - 1) +#define CHARS_EXTRA (MAX(sizeof(UNSPEC), 2) - 1) #define JULIAN_DAY 0 /* Jn = Julian day */ #define DAY_OF_YEAR 1 /* n = day of year */ @@ -268,7 +269,7 @@ struct state_s time_t ats[TZ_MAX_TIMES]; unsigned char types[TZ_MAX_TIMES]; struct ttinfo_s ttis[TZ_MAX_TYPES]; - char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + CHARS_EXTRA, sizeof("UTC")), + char chars[MAX(MAX(TZ_MAX_CHARS + CHARS_EXTRA, sizeof("UTC")), (2 * (MY_TZNAME_MAX + 1)))]; struct lsinfo_s lsis[TZ_MAX_LEAPS];