diff --git a/boards/posix/native_posix/main.c b/boards/posix/native_posix/main.c index 1bdad39e84e..956a44a328a 100644 --- a/boards/posix/native_posix/main.c +++ b/boards/posix/native_posix/main.c @@ -36,7 +36,7 @@ void posix_exit(int exit_code) { static int max_exit_code; - max_exit_code = max(exit_code, max_exit_code); + max_exit_code = MAX(exit_code, max_exit_code); /* * posix_soc_clean_up may not return if this is called from a SW thread, * but instead it would get posix_exit() recalled again diff --git a/boards/posix/native_posix/timer_model.c b/boards/posix/native_posix/timer_model.c index 26b049d6b6d..0f127e1377b 100644 --- a/boards/posix/native_posix/timer_model.c +++ b/boards/posix/native_posix/timer_model.c @@ -126,7 +126,7 @@ void hwtimer_set_real_time_mode(bool new_rt) static void hwtimer_update_timer(void) { - hw_timer_timer = min(hw_timer_tick_timer, hw_timer_awake_timer); + hw_timer_timer = MIN(hw_timer_tick_timer, hw_timer_awake_timer); } static inline void host_clock_gettime(struct timespec *tv) diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index ae68fc6cb0a..ed8598037d7 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -232,7 +232,7 @@ static size_t h4_discard(struct device *uart, size_t len) { u8_t buf[33]; - return uart_fifo_read(uart, buf, min(len, sizeof(buf))); + return uart_fifo_read(uart, buf, MIN(len, sizeof(buf))); } static inline void read_payload(void) diff --git a/drivers/entropy/entropy_sam.c b/drivers/entropy/entropy_sam.c index 2da922e6788..d4593f3a12d 100644 --- a/drivers/entropy/entropy_sam.c +++ b/drivers/entropy/entropy_sam.c @@ -58,7 +58,7 @@ static int entropy_sam_get_entropy(struct device *dev, u8_t *buffer, } value = trng->TRNG_ODATA; - to_copy = min(length, sizeof(value)); + to_copy = MIN(length, sizeof(value)); memcpy(buffer, &value, to_copy); buffer += to_copy; diff --git a/drivers/entropy/fake_entropy_native_posix.c b/drivers/entropy/fake_entropy_native_posix.c index b41a7444f80..a927005dba7 100644 --- a/drivers/entropy/fake_entropy_native_posix.c +++ b/drivers/entropy/fake_entropy_native_posix.c @@ -35,7 +35,7 @@ static int entropy_native_posix_get_entropy(struct device *dev, u8_t *buffer, */ long int value = random(); - size_t to_copy = min(length, sizeof(long int)); + size_t to_copy = MIN(length, sizeof(long int)); memcpy(buffer, &value, to_copy); buffer += to_copy; diff --git a/drivers/flash/flash_sam.c b/drivers/flash/flash_sam.c index 8f989dd6ca6..e3c3a09b077 100644 --- a/drivers/flash/flash_sam.c +++ b/drivers/flash/flash_sam.c @@ -185,7 +185,7 @@ static int flash_sam_write(struct device *dev, off_t offset, /* Maximum size without crossing a page */ eop_len = -(offset | ~(IFLASH_PAGE_SIZE - 1)); - write_len = min(len, eop_len); + write_len = MIN(len, eop_len); rc = flash_sam_write_page(dev, offset, data8, write_len); if (rc < 0) { diff --git a/drivers/flash/soc_flash_nios2_qspi.c b/drivers/flash/soc_flash_nios2_qspi.c index 0764b4169aa..512085a719b 100644 --- a/drivers/flash/soc_flash_nios2_qspi.c +++ b/drivers/flash/soc_flash_nios2_qspi.c @@ -105,7 +105,7 @@ static int flash_nios2_qspi_erase(struct device *dev, off_t offset, size_t len) } /* calculate the byte size of data to be written in a sector */ - length_to_erase = min(qspi_dev->sector_size - offset_in_block, + length_to_erase = MIN(qspi_dev->sector_size - offset_in_block, remaining_length); /* Erase sector */ @@ -297,7 +297,7 @@ static int flash_nios2_qspi_write(struct device *dev, off_t offset, } /* calculate the byte size of data to be written in a sector */ - length_to_write = min(qspi_dev->sector_size - offset_in_block, + length_to_write = MIN(qspi_dev->sector_size - offset_in_block, remaining_length); rc = flash_nios2_qspi_write_block(dev, diff --git a/drivers/i2c/i2c_dw.c b/drivers/i2c/i2c_dw.c index 135b4cc45f3..8f6a8a08605 100644 --- a/drivers/i2c/i2c_dw.c +++ b/drivers/i2c/i2c_dw.c @@ -69,8 +69,8 @@ static inline void _i2c_dw_data_ask(struct device *dev) tx_empty = I2C_DW_FIFO_DEPTH - regs->ic_txflr; /* Figure out how many bytes we can request */ - cnt = min(I2C_DW_FIFO_DEPTH, dw->request_bytes); - cnt = min(min(tx_empty, rx_empty), cnt); + cnt = MIN(I2C_DW_FIFO_DEPTH, dw->request_bytes); + cnt = MIN(MIN(tx_empty, rx_empty), cnt); while (cnt > 0) { /* Tell controller to get another byte */ diff --git a/drivers/i2c/i2c_esp32.c b/drivers/i2c/i2c_esp32.c index fff7dbe9590..fe794e7d0e3 100644 --- a/drivers/i2c/i2c_esp32.c +++ b/drivers/i2c/i2c_esp32.c @@ -388,7 +388,7 @@ static int i2c_esp32_read_msg(struct device *dev, u16_t addr, for (; msg.len; cmd = (void *)I2C_COMD0_REG(config->index)) { volatile struct i2c_esp32_cmd *wait_cmd = NULL; - u32_t to_read = min(I2C_ESP32_BUFFER_SIZE, msg.len - 1); + u32_t to_read = MIN(I2C_ESP32_BUFFER_SIZE, msg.len - 1); /* Might be the last byte, in which case, `to_read` will * be 0 here. See comment below. @@ -464,7 +464,7 @@ static int i2c_esp32_write_msg(struct device *dev, u16_t addr, cmd = i2c_esp32_write_addr(dev, cmd, &msg, addr); for (; msg.len; cmd = (void *)I2C_COMD0_REG(config->index)) { - u32_t to_send = min(I2C_ESP32_BUFFER_SIZE, msg.len); + u32_t to_send = MIN(I2C_ESP32_BUFFER_SIZE, msg.len); u32_t i; int ret; diff --git a/drivers/spi/spi_sam.c b/drivers/spi/spi_sam.c index 95bcf716247..54c5b9da8e1 100644 --- a/drivers/spi/spi_sam.c +++ b/drivers/spi/spi_sam.c @@ -92,7 +92,7 @@ static int spi_sam_configure(struct device *dev, /* Use the requested or next higest possible frequency */ div = SOC_ATMEL_SAM_MCK_FREQ_HZ / config->frequency; - div = max(1, min(UINT8_MAX, div)); + div = MAX(1, MIN(UINT8_MAX, div)); spi_csr |= SPI_CSR_SCBR(div); regs->SPI_CR = SPI_CR_SPIDIS; /* Disable SPI */ diff --git a/drivers/spi/spi_sam0.c b/drivers/spi/spi_sam0.c index 8a62187bbc2..dfc1d11fb70 100644 --- a/drivers/spi/spi_sam0.c +++ b/drivers/spi/spi_sam0.c @@ -95,7 +95,7 @@ static int spi_sam0_configure(struct device *dev, /* Use the requested or next higest possible frequency */ div = (SOC_ATMEL_SAM0_GCLK0_FREQ_HZ / config->frequency) / 2 - 1; - div = max(0, min(UINT8_MAX, div)); + div = MAX(0, MIN(UINT8_MAX, div)); /* Update the configuration only if it has changed */ if (regs->CTRLA.reg != ctrla.reg || regs->CTRLB.reg != ctrlb.reg || diff --git a/drivers/timer/arcv2_timer0.c b/drivers/timer/arcv2_timer0.c index 42cb8f6f39b..2648b8dab53 100644 --- a/drivers/timer/arcv2_timer0.c +++ b/drivers/timer/arcv2_timer0.c @@ -194,7 +194,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #if defined(CONFIG_TICKLESS_KERNEL) u32_t delay; - ticks = min(MAX_TICKS, max(ticks - 1, 0)); + ticks = MIN(MAX_TICKS, MAX(ticks - 1, 0)); /* Desired delay in the future */ delay = (ticks == 0) ? MIN_DELAY : ticks * CYC_PER_TICK; diff --git a/drivers/timer/cortex_m_systick.c b/drivers/timer/cortex_m_systick.c index 6ce3405866d..b3b183c74d7 100644 --- a/drivers/timer/cortex_m_systick.c +++ b/drivers/timer/cortex_m_systick.c @@ -93,7 +93,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #if defined(CONFIG_TICKLESS_KERNEL) && !defined(CONFIG_QEMU_TICKLESS_WORKAROUND) u32_t delay; - ticks = min(MAX_TICKS, max(ticks - 1, 0)); + ticks = MIN(MAX_TICKS, MAX(ticks - 1, 0)); /* Desired delay in the future */ delay = (ticks == 0) ? MIN_DELAY : ticks * CYC_PER_TICK; diff --git a/drivers/timer/hpet.c b/drivers/timer/hpet.c index 47cc4980ec3..f3a55885760 100644 --- a/drivers/timer/hpet.c +++ b/drivers/timer/hpet.c @@ -109,7 +109,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) } ticks = ticks == K_FOREVER ? max_ticks : ticks; - ticks = max(min(ticks - 1, (s32_t)max_ticks), 0); + ticks = MAX(MIN(ticks - 1, (s32_t)max_ticks), 0); k_spinlock_key_t key = k_spin_lock(&lock); u32_t now = MAIN_COUNTER_REG, cyc; diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index cc5e5a24742..ef202da3552 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -128,7 +128,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #ifdef CONFIG_TICKLESS_KERNEL ticks = (ticks == K_FOREVER) ? MAX_TICKS : ticks; - ticks = max(min(ticks - 1, (s32_t)MAX_TICKS), 0); + ticks = MAX(MIN(ticks - 1, (s32_t)MAX_TICKS), 0); /* * Get the requested delay in tick-aligned cycles. Increase @@ -136,7 +136,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) * cycles elapsed since the last tick. Cap at the maximum * tick-aligned delta. */ - u32_t cyc = min((1 + ticks) * CYC_PER_TICK, MAX_DELAY); + u32_t cyc = MIN((1 + ticks) * CYC_PER_TICK, MAX_DELAY); u32_t key = irq_lock(); u32_t d = counter_sub(counter(), last_count); diff --git a/drivers/timer/riscv_machine_timer.c b/drivers/timer/riscv_machine_timer.c index c6b6f6427b4..7e295263e1f 100644 --- a/drivers/timer/riscv_machine_timer.c +++ b/drivers/timer/riscv_machine_timer.c @@ -95,7 +95,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) } ticks = ticks == K_FOREVER ? MAX_TICKS : ticks; - ticks = max(min(ticks - 1, (s32_t)MAX_TICKS), 0); + ticks = MAX(MIN(ticks - 1, (s32_t)MAX_TICKS), 0); k_spinlock_key_t key = k_spin_lock(&lock); u64_t now = mtime(); diff --git a/drivers/timer/sam0_rtc_timer.c b/drivers/timer/sam0_rtc_timer.c index 61d768b0409..76f55fd44f1 100644 --- a/drivers/timer/sam0_rtc_timer.c +++ b/drivers/timer/sam0_rtc_timer.c @@ -205,7 +205,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #ifdef CONFIG_TICKLESS_KERNEL ticks = (ticks == K_FOREVER) ? MAX_TICKS : ticks; - ticks = max(min(ticks - 1, (s32_t) MAX_TICKS), 0); + ticks = MAX(MIN(ticks - 1, (s32_t) MAX_TICKS), 0); /* Compute number of RTC cycles until the next timeout. */ u32_t count = rtc_count(); diff --git a/drivers/timer/xtensa_sys_timer.c b/drivers/timer/xtensa_sys_timer.c index c03254ee457..b133c28a7c0 100644 --- a/drivers/timer/xtensa_sys_timer.c +++ b/drivers/timer/xtensa_sys_timer.c @@ -82,7 +82,7 @@ void z_clock_set_timeout(s32_t ticks, bool idle) #if defined(CONFIG_TICKLESS_KERNEL) && !defined(CONFIG_QEMU_TICKLESS_WORKAROUND) ticks = ticks == K_FOREVER ? MAX_TICKS : ticks; - ticks = max(min(ticks - 1, (s32_t)MAX_TICKS), 0); + ticks = MAX(MIN(ticks - 1, (s32_t)MAX_TICKS), 0); k_spinlock_key_t key = k_spin_lock(&lock); u32_t curr = ccount(), cyc; diff --git a/drivers/usb/device/usb_dc_nrfx.c b/drivers/usb/device/usb_dc_nrfx.c index 58204afe685..5ef7c441fe7 100644 --- a/drivers/usb/device/usb_dc_nrfx.c +++ b/drivers/usb/device/usb_dc_nrfx.c @@ -1674,7 +1674,7 @@ int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len, k_mutex_lock(&ctx->drv_lock, K_FOREVER); - bytes_to_copy = min(max_data_len, ep_ctx->buf.len); + bytes_to_copy = MIN(max_data_len, ep_ctx->buf.len); if (!data && !max_data_len) { if (read_bytes) { diff --git a/drivers/usb/device/usb_dc_sam.c b/drivers/usb/device/usb_dc_sam.c index a8b047bccc1..80f22620216 100644 --- a/drivers/usb/device/usb_dc_sam.c +++ b/drivers/usb/device/usb_dc_sam.c @@ -475,7 +475,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data *const cfg) * Map the endpoint size to the buffer size. Only power of 2 buffer * sizes between 8 and 1024 are possible, get the next power of 2. */ - log2ceil_mps = 32 - __builtin_clz((max(cfg->ep_mps, 8) << 1) - 1) - 1; + log2ceil_mps = 32 - __builtin_clz((MAX(cfg->ep_mps, 8) << 1) - 1) - 1; regval |= USBHS_DEVEPTCFG_EPSIZE(log2ceil_mps - 3); dev_data.ep_data[ep_idx].mps = cfg->ep_mps; @@ -695,7 +695,7 @@ int usb_dc_ep_write(u8_t ep, const u8_t *data, u32_t data_len, u32_t *ret_bytes) } /* Write the data to the FIFO */ - packet_len = min(data_len, dev_data.ep_data[ep_idx].mps); + packet_len = MIN(data_len, dev_data.ep_data[ep_idx].mps); for (int i = 0; i < packet_len; i++) { usb_dc_ep_fifo_put(ep_idx, data[i]); } diff --git a/drivers/usb/device/usb_dc_sam0.c b/drivers/usb/device/usb_dc_sam0.c index 813e2505ca0..672d56d9c03 100644 --- a/drivers/usb/device/usb_dc_sam0.c +++ b/drivers/usb/device/usb_dc_sam0.c @@ -490,7 +490,7 @@ int usb_dc_ep_read_ex(u8_t ep, u8_t *buf, u32_t max_data_len, } remain = bytes - data->out_at; - take = min(max_data_len, remain); + take = MIN(max_data_len, remain); memcpy(buf, (u8_t *)addr + data->out_at, take); if (read_bytes != NULL) { diff --git a/drivers/usb/device/usb_dc_stm32.c b/drivers/usb/device/usb_dc_stm32.c index 27d60eb8ad8..08e30f4abbd 100644 --- a/drivers/usb/device/usb_dc_stm32.c +++ b/drivers/usb/device/usb_dc_stm32.c @@ -797,7 +797,7 @@ int usb_dc_ep_read_wait(u8_t ep, u8_t *data, u32_t max_data_len, * previously stored in the buffer. */ if (data) { - read_count = min(read_count, max_data_len); + read_count = MIN(read_count, max_data_len); memcpy(data, usb_dc_stm32_state.ep_buf[EP_IDX(ep)] + ep_state->read_offset, read_count); ep_state->read_count -= read_count; diff --git a/drivers/wifi/eswifi/eswifi_bus_spi.c b/drivers/wifi/eswifi/eswifi_bus_spi.c index bfb29f363de..9dfae204797 100644 --- a/drivers/wifi/eswifi/eswifi_bus_spi.c +++ b/drivers/wifi/eswifi/eswifi_bus_spi.c @@ -159,7 +159,7 @@ data: } while (eswifi_spi_cmddata_ready(spi) && to_read) { - to_read = min(rlen - offset, to_read); + to_read = MIN(rlen - offset, to_read); memset(rsp + offset, 0, to_read); eswifi_spi_read(eswifi, rsp + offset, to_read); offset += to_read; diff --git a/ext/lib/mgmt/mcumgr/cmd/log_mgmt/port/zephyr/src/zephyr_log_mgmt.c b/ext/lib/mgmt/mcumgr/cmd/log_mgmt/port/zephyr/src/zephyr_log_mgmt.c index 378c3ead6a7..94e49dbaa41 100644 --- a/ext/lib/mgmt/mcumgr/cmd/log_mgmt/port/zephyr/src/zephyr_log_mgmt.c +++ b/ext/lib/mgmt/mcumgr/cmd/log_mgmt/port/zephyr/src/zephyr_log_mgmt.c @@ -121,7 +121,7 @@ zephyr_log_mgmt_walk_cb(struct mdlog *log, struct mdlog_offset *log_offset, return 0; } - read_len = min(len - sizeof ueh, LOG_MGMT_BODY_LEN - sizeof ueh); + read_len = MIN(len - sizeof ueh, LOG_MGMT_BODY_LEN - sizeof ueh); rc = mdlog_read(log, desciptor, zephyr_log_mgmt_walk_arg->body, sizeof ueh, read_len); if (rc < 0) { diff --git a/include/arch/arc/arch.h b/include/arch/arc/arch.h index 61ade13cfae..83bf65f242d 100644 --- a/include/arch/arc/arch.h +++ b/include/arch/arc/arch.h @@ -68,7 +68,7 @@ extern "C" { #define STACK_GUARD_SIZE 0 #endif /* CONFIG_MPU_STACK_GUARD */ -#define STACK_SIZE_ALIGN(x) max(STACK_ALIGN, x) +#define STACK_SIZE_ALIGN(x) MAX(STACK_ALIGN, x) /** @@ -91,7 +91,7 @@ extern "C" { #define _ARCH_THREAD_STACK_LEN(size) \ (POW2_CEIL(STACK_SIZE_ALIGN(size)) + \ - max(POW2_CEIL(STACK_SIZE_ALIGN(size)), \ + MAX(POW2_CEIL(STACK_SIZE_ALIGN(size)), \ POW2_CEIL(STACK_GUARD_SIZE + CONFIG_PRIVILEGED_STACK_SIZE))) #define _ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \ diff --git a/include/arch/arm/arch.h b/include/arch/arm/arch.h index a801926c468..8a109ff48f6 100644 --- a/include/arch/arm/arch.h +++ b/include/arch/arm/arch.h @@ -109,7 +109,7 @@ extern "C" { #if defined(CONFIG_USERSPACE) #define STACK_ALIGN CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE #else -#define STACK_ALIGN max(STACK_ALIGN_SIZE, MPU_GUARD_ALIGN_AND_SIZE) +#define STACK_ALIGN MAX(STACK_ALIGN_SIZE, MPU_GUARD_ALIGN_AND_SIZE) #endif /** diff --git a/include/arch/x86/arch.h b/include/arch/x86/arch.h index 1da31d591eb..e5c07cdc4a0 100644 --- a/include/arch/x86/arch.h +++ b/include/arch/x86/arch.h @@ -613,7 +613,7 @@ extern struct task_state_segment _main_tss; #define _ARCH_THREAD_STACK_LEN(size) \ (ROUND_UP((size), \ - max(_STACK_BASE_ALIGN, _STACK_SIZE_ALIGN)) + \ + MAX(_STACK_BASE_ALIGN, _STACK_SIZE_ALIGN)) + \ _STACK_GUARD_SIZE) #define _ARCH_THREAD_STACK_ARRAY_DEFINE(sym, nmemb, size) \ diff --git a/include/misc/util.h b/include/misc/util.h index 405e09bb76e..ae1a71ebec5 100644 --- a/include/misc/util.h +++ b/include/misc/util.h @@ -86,12 +86,12 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; } #define INLINE #endif -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif static inline int is_power_of_two(unsigned int x) diff --git a/include/net/lldp.h b/include/net/lldp.h index 95aabb8e7b6..a46b1907450 100644 --- a/include/net/lldp.h +++ b/include/net/lldp.h @@ -95,7 +95,7 @@ extern "C" { * to zero so LLDP Rx agents can invalidate the entry related to this node. */ #define NET_LLDP_TTL \ - min((CONFIG_NET_LLDP_TX_INTERVAL * CONFIG_NET_LLDP_TX_HOLD) + 1, 65535) + MIN((CONFIG_NET_LLDP_TX_INTERVAL * CONFIG_NET_LLDP_TX_HOLD) + 1, 65535) struct net_if; diff --git a/kernel/pipes.c b/kernel/pipes.c index 9f83107ea0f..a51735a0eb3 100644 --- a/kernel/pipes.c +++ b/kernel/pipes.c @@ -197,7 +197,7 @@ void k_pipe_cleanup(struct k_pipe *pipe) static size_t pipe_xfer(unsigned char *dest, size_t dest_size, const unsigned char *src, size_t src_size) { - size_t num_bytes = min(dest_size, src_size); + size_t num_bytes = MIN(dest_size, src_size); const unsigned char *end = src + num_bytes; while (src != end) { @@ -227,7 +227,7 @@ static size_t pipe_buffer_put(struct k_pipe *pipe, for (i = 0; i < 2; i++) { - run_length = min(pipe->size - pipe->bytes_used, + run_length = MIN(pipe->size - pipe->bytes_used, pipe->size - pipe->write_index); bytes_copied = pipe_xfer(pipe->buffer + pipe->write_index, @@ -263,7 +263,7 @@ static size_t pipe_buffer_get(struct k_pipe *pipe, int i; for (i = 0; i < 2; i++) { - run_length = min(pipe->bytes_used, + run_length = MIN(pipe->bytes_used, pipe->size - pipe->read_index); bytes_copied = pipe_xfer(dest + num_bytes_read, diff --git a/kernel/timeout.c b/kernel/timeout.c index 8654376ba0e..f7420319086 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -62,7 +62,7 @@ static s32_t next_timeout(void) { int maxw = can_wait_forever ? K_FOREVER : INT_MAX; struct _timeout *to = first(); - s32_t ret = to == NULL ? maxw : max(0, to->dticks - elapsed()); + s32_t ret = to == NULL ? maxw : MAX(0, to->dticks - elapsed()); #ifdef CONFIG_TIMESLICING if (_current_cpu->slice_ticks && _current_cpu->slice_ticks < ret) { @@ -76,7 +76,7 @@ void _add_timeout(struct _timeout *to, _timeout_func_t fn, s32_t ticks) { __ASSERT(!sys_dnode_is_linked(&to->node), ""); to->fn = fn; - ticks = max(1, ticks); + ticks = MAX(1, ticks); LOCKED(&timeout_lock) { struct _timeout *t; diff --git a/lib/os/ring_buffer.c b/lib/os/ring_buffer.c index 6c9b149c29b..2aaba9b2ee4 100644 --- a/lib/os/ring_buffer.c +++ b/lib/os/ring_buffer.c @@ -114,11 +114,11 @@ u32_t ring_buf_put_claim(struct ring_buf *buf, u8_t **data, u32_t size) buf->misc.byte_mode.tmp_tail); /* Limit requested size to available size. */ - size = min(size, space); + size = MIN(size, space); trail_size = buf->size - buf->misc.byte_mode.tmp_tail; /* Limit allocated size to trail size. */ - allocated = min(trail_size, size); + allocated = MIN(trail_size, size); *data = &buf->buf.buf8[buf->misc.byte_mode.tmp_tail]; buf->misc.byte_mode.tmp_tail = @@ -169,10 +169,10 @@ u32_t ring_buf_get_claim(struct ring_buf *buf, u8_t **data, u32_t size) trail_size = buf->size - buf->misc.byte_mode.tmp_head; /* Limit requested size to available size. */ - granted_size = min(size, space); + granted_size = MIN(size, space); /* Limit allocated size to trail size. */ - granted_size = min(trail_size, granted_size); + granted_size = MIN(trail_size, granted_size); *data = &buf->buf.buf8[buf->misc.byte_mode.tmp_head]; buf->misc.byte_mode.tmp_head = diff --git a/samples/bluetooth/eddystone/src/main.c b/samples/bluetooth/eddystone/src/main.c index e85811efaf9..1cc6a580a4f 100644 --- a/samples/bluetooth/eddystone/src/main.c +++ b/samples/bluetooth/eddystone/src/main.c @@ -487,7 +487,7 @@ static ssize_t write_adv_data(struct bt_conn *conn, * controlled by characteristics 4 (Radio Tx Power) and * 5 (Advertised Tx Power). */ - slot->ad[2].data_len = min(slot->ad[2].data_len, + slot->ad[2].data_len = MIN(slot->ad[2].data_len, len + EDS_URL_WRITE_OFFSET); memcpy(&slot->ad[2].data + EDS_URL_WRITE_OFFSET, buf, slot->ad[2].data_len - EDS_URL_WRITE_OFFSET); diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index 718666d82f3..a8bd1b853e8 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -103,7 +103,7 @@ static size_t h4_discard(struct device *uart, size_t len) { u8_t buf[H4_DISCARD_LEN]; - return uart_fifo_read(uart, buf, min(len, sizeof(buf))); + return uart_fifo_read(uart, buf, MIN(len, sizeof(buf))); } static struct net_buf *h4_cmd_recv(int *remaining) diff --git a/samples/bluetooth/mesh_demo/src/microbit.c b/samples/bluetooth/mesh_demo/src/microbit.c index 295f050e5d2..fe4872f428b 100644 --- a/samples/bluetooth/mesh_demo/src/microbit.c +++ b/samples/bluetooth/mesh_demo/src/microbit.c @@ -170,7 +170,7 @@ void board_heartbeat(u8_t hops, u16_t feat) printk("%u hops\n", hops); if (hops) { - hops = min(hops, ARRAY_SIZE(hops_img)); + hops = MIN(hops, ARRAY_SIZE(hops_img)); mb_display_image(disp, MB_DISPLAY_MODE_SINGLE, K_SECONDS(2), &hops_img[hops - 1], 1); } diff --git a/samples/boards/reel_board/mesh_badge/src/mesh.c b/samples/boards/reel_board/mesh_badge/src/mesh.c index f0e676854da..5dcd87acf1d 100644 --- a/samples/boards/reel_board/mesh_badge/src/mesh.c +++ b/samples/boards/reel_board/mesh_badge/src/mesh.c @@ -322,7 +322,7 @@ static void vnd_hello(struct bt_mesh_model *model, return; } - len = min(buf->len, HELLO_MAX); + len = MIN(buf->len, HELLO_MAX); memcpy(str, buf->data, len); str[len] = '\0'; @@ -417,7 +417,7 @@ static void send_hello(struct k_work *work) bt_mesh_model_msg_init(&msg, OP_VND_HELLO); net_buf_simple_add_mem(&msg, name, - min(HELLO_MAX, first_name_len(name))); + MIN(HELLO_MAX, first_name_len(name))); if (bt_mesh_model_send(&vnd_models[0], &ctx, &msg, NULL, NULL) == 0) { board_show_text("Saying \"hi!\" to everyone", false, diff --git a/samples/boards/reel_board/mesh_badge/src/reel_board.c b/samples/boards/reel_board/mesh_badge/src/reel_board.c index 7c30f43c5f6..9dee0f5acc7 100644 --- a/samples/boards/reel_board/mesh_badge/src/reel_board.c +++ b/samples/boards/reel_board/mesh_badge/src/reel_board.c @@ -85,7 +85,7 @@ static size_t print_line(enum font_size font_size, int row, const char *text, cfb_framebuffer_set_font(epd_dev, font_size); - len = min(len, fonts[font_size].columns); + len = MIN(len, fonts[font_size].columns); memcpy(line, text, len); line[len] = '\0'; diff --git a/samples/net/nats/src/nats.c b/samples/net/nats/src/nats.c index 0b321165bf0..40ad58fd476 100644 --- a/samples/net/nats/src/nats.c +++ b/samples/net/nats/src/nats.c @@ -251,7 +251,7 @@ static int copy_pkt_to_buf(struct net_buf *src, u16_t offset, } for (copied = 0U; src && n_bytes > 0; offset = 0U) { - to_copy = min(n_bytes, src->len - offset); + to_copy = MIN(n_bytes, src->len - offset); memcpy(dst + copied, (char *)src->data + offset, to_copy); copied += to_copy; diff --git a/samples/net/sockets/coap_server/src/coap-server.c b/samples/net/sockets/coap_server/src/coap-server.c index 1f6499edde7..e9741ddee15 100644 --- a/samples/net/sockets/coap_server/src/coap-server.c +++ b/samples/net/sockets/coap_server/src/coap-server.c @@ -756,10 +756,10 @@ static int large_get(struct coap_resource *resource, goto end; } - size = min(coap_block_size_to_bytes(ctx.block_size), + size = MIN(coap_block_size_to_bytes(ctx.block_size), ctx.total_size - ctx.current); - memset(payload, 'A', min(size, sizeof(payload))); + memset(payload, 'A', MIN(size, sizeof(payload))); r = coap_packet_append_payload(&response, (u8_t *)payload, size); if (r < 0) { diff --git a/subsys/bluetooth/common/log.c b/subsys/bluetooth/common/log.c index 7777bcf1fb2..92ed58f5c79 100644 --- a/subsys/bluetooth/common/log.c +++ b/subsys/bluetooth/common/log.c @@ -26,7 +26,7 @@ const char *bt_hex_real(const void *buf, size_t len) const u8_t *b = buf; int i; - len = min(len, (sizeof(str) - 1) / 2); + len = MIN(len, (sizeof(str) - 1) / 2); for (i = 0; i < len; i++) { str[i * 2] = hex[b[i] >> 4]; diff --git a/subsys/bluetooth/controller/ll_sw/ctrl.c b/subsys/bluetooth/controller/ll_sw/ctrl.c index 09627f5c4bf..a9793bbffcd 100644 --- a/subsys/bluetooth/controller/ll_sw/ctrl.c +++ b/subsys/bluetooth/controller/ll_sw/ctrl.c @@ -1168,7 +1168,7 @@ static inline u32_t isr_rx_adv(u8_t devmatch_ok, u8_t devmatch_id, HAL_TICKER_US_TO_TICKS(RADIO_TICKER_XTAL_OFFSET_US); conn->hdr.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(RADIO_TICKER_PREEMPT_PART_MIN_US); - ticks_slot_offset = max(conn->hdr.ticks_active_to_start, + ticks_slot_offset = MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); conn_interval_us -= conn->slave.window_widening_periodic_us; @@ -1662,7 +1662,7 @@ static inline u32_t isr_rx_scan(u8_t devmatch_ok, u8_t devmatch_id, conn->hdr.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS( RADIO_TICKER_PREEMPT_PART_MIN_US); conn->hdr.ticks_slot = _radio.scanner.ticks_conn_slot; - ticks_slot_offset = max(conn->hdr.ticks_active_to_start, + ticks_slot_offset = MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); /* Stop Scanner */ @@ -2296,7 +2296,7 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx, * peer max_rx_octets */ if (lr->max_rx_octets >= PDU_DC_PAYLOAD_SIZE_MIN) { - eff_tx_octets = min(lr->max_rx_octets, + eff_tx_octets = MIN(lr->max_rx_octets, _radio.conn_curr->default_tx_octets); } @@ -2304,7 +2304,7 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx, * peer max_tx_octets */ if (lr->max_tx_octets >= PDU_DC_PAYLOAD_SIZE_MIN) { - eff_rx_octets = min(lr->max_tx_octets, + eff_rx_octets = MIN(lr->max_tx_octets, LL_LENGTH_OCTETS_RX_MAX); } @@ -2315,11 +2315,11 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx, if (lr->max_rx_time >= RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) { eff_tx_time = - min(lr->max_rx_time, + MIN(lr->max_rx_time, _radio.conn_curr->default_tx_time); #if defined(CONFIG_BT_CTLR_PHY_CODED) eff_tx_time = - max(eff_tx_time, + MAX(eff_tx_time, RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, _radio.conn_curr->phy_tx)); #endif /* CONFIG_BT_CTLR_PHY_CODED */ @@ -2331,12 +2331,12 @@ static inline u8_t isr_rx_conn_pkt_ctrl_dle(struct pdu_data *pdu_data_rx, if (lr->max_tx_time >= RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, 0)) { eff_rx_time = - min(lr->max_tx_time, + MIN(lr->max_tx_time, RADIO_PKT_TIME(LL_LENGTH_OCTETS_RX_MAX, BIT(2))); #if defined(CONFIG_BT_CTLR_PHY_CODED) eff_rx_time = - max(eff_rx_time, + MAX(eff_rx_time, RADIO_PKT_TIME(PDU_DC_PAYLOAD_SIZE_MIN, _radio.conn_curr->phy_rx)); #endif /* CONFIG_BT_CTLR_PHY_CODED */ @@ -5031,7 +5031,7 @@ static void prepare_normal_set(struct shdr *hdr, u8_t ticker_user_id, if (hdr->ticks_xtal_to_start & XON_BITMASK) { u32_t ticker_status; u32_t ticks_prepare_to_start = - max(hdr->ticks_active_to_start, + MAX(hdr->ticks_active_to_start, hdr->ticks_preempt_to_start); u32_t ticks_drift_minus = (hdr->ticks_xtal_to_start & ~XON_BITMASK) - @@ -5154,10 +5154,10 @@ static void mayfly_xtal_stop_calc(void *params) /* Compensate for current ticker in reduced prepare */ if (hdr_curr->ticks_xtal_to_start & XON_BITMASK) { - ticks_slot_abs = max(hdr_curr->ticks_active_to_start, + ticks_slot_abs = MAX(hdr_curr->ticks_active_to_start, hdr_curr->ticks_preempt_to_start); } else { - ticks_slot_abs = max(hdr_curr->ticks_active_to_start, + ticks_slot_abs = MAX(hdr_curr->ticks_active_to_start, hdr_curr->ticks_xtal_to_start); } ticks_slot_abs += hdr_curr->ticks_slot; @@ -5167,7 +5167,7 @@ static void mayfly_xtal_stop_calc(void *params) LL_ASSERT(hdr_next); ticks_prepare_to_start_next = - max(hdr_next->ticks_active_to_start, + MAX(hdr_next->ticks_active_to_start, hdr_next->ticks_preempt_to_start); /* Compensate for next ticker in reduced prepare */ @@ -5322,7 +5322,7 @@ static void sched_after_mstr_free_slot_get(u8_t user_id, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_preempt_to_start); ticks_slot_abs_curr = @@ -5335,7 +5335,7 @@ static void sched_after_mstr_free_slot_get(u8_t user_id, #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); ticks_slot_abs_curr = ticks_prepare_to_start; @@ -5448,7 +5448,7 @@ static void sched_free_win_offset_calc(struct connection *conn_curr, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn_curr->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn_curr->hdr.ticks_active_to_start, + MAX(conn_curr->hdr.ticks_active_to_start, conn_curr->hdr.ticks_preempt_to_start); ticks_slot_abs = conn_curr->hdr.ticks_xtal_to_start & @@ -5458,7 +5458,7 @@ static void sched_free_win_offset_calc(struct connection *conn_curr, #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ { u32_t ticks_prepare_to_start = - max(conn_curr->hdr.ticks_active_to_start, + MAX(conn_curr->hdr.ticks_active_to_start, conn_curr->hdr.ticks_xtal_to_start); ticks_slot_abs = ticks_prepare_to_start; @@ -5537,7 +5537,7 @@ static void sched_free_win_offset_calc(struct connection *conn_curr, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_preempt_to_start); ticks_slot_abs_curr = @@ -5550,7 +5550,7 @@ static void sched_free_win_offset_calc(struct connection *conn_curr, #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); ticks_slot_abs_curr = ticks_prepare_to_start; @@ -5807,7 +5807,7 @@ static void event_common_prepare(u32_t ticks_at_expire, * active to start duration. */ if (_ticks_xtal_to_start & XON_BITMASK) { - _ticks_xtal_to_start = max(_ticks_active_to_start, + _ticks_xtal_to_start = MAX(_ticks_active_to_start, ticks_preempt_to_start); } #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ @@ -5912,7 +5912,7 @@ static void event_common_prepare(u32_t ticks_at_expire, } #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ - ticks_to_start_new = max(_radio.ticks_active_to_start, + ticks_to_start_new = MAX(_radio.ticks_active_to_start, *ticks_xtal_to_start); /* drift the primary as required due to active line change */ @@ -6754,7 +6754,7 @@ static void event_scan_prepare(u32_t ticks_at_expire, u32_t remainder, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (_radio.scanner.hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(_radio.scanner.hdr.ticks_active_to_start, + MAX(_radio.scanner.hdr.ticks_active_to_start, _radio.scanner.hdr.ticks_preempt_to_start); ticks_at_expire_normal -= @@ -6944,7 +6944,7 @@ static inline void event_conn_upd_init(struct connection *conn, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_preempt_to_start); conn->llcp.conn_upd.ticks_anchor -= @@ -7103,7 +7103,7 @@ static inline u32_t event_conn_upd_prep(struct connection *conn, /* restore to normal prepare */ if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_preempt_to_start); conn->hdr.ticks_xtal_to_start &= ~XON_BITMASK; @@ -7128,7 +7128,7 @@ static inline u32_t event_conn_upd_prep(struct connection *conn, conn->latency_prepare -= (instant_latency - latency); /* calculate the offset, window widening and interval */ - ticks_slot_offset = max(conn->hdr.ticks_active_to_start, + ticks_slot_offset = MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); conn_interval_us = conn->llcp.conn_upd.interval * 1250; periodic_us = conn_interval_us; @@ -7683,7 +7683,7 @@ static inline void event_conn_param_req(struct connection *conn, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->hdr.ticks_active_to_start, + MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_preempt_to_start); conn->llcp_conn_param.ticks_ref -= @@ -10685,7 +10685,7 @@ u32_t radio_adv_enable(u16_t interval, u8_t chan_map, u8_t filter_policy, _radio.advertiser.hdr.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); ticks_slot_offset = - max(_radio.advertiser.hdr.ticks_active_to_start, + MAX(_radio.advertiser.hdr.ticks_active_to_start, _radio.advertiser.hdr.ticks_xtal_to_start); #if !defined(CONFIG_BT_HCI_MESH_EXT) @@ -10888,7 +10888,7 @@ u32_t radio_scan_enable(u8_t type, u8_t init_addr_type, u8_t *init_addr, HAL_TICKER_US_TO_TICKS(RADIO_TICKER_XTAL_OFFSET_US)); } - ticks_slot_offset = max(_radio.scanner.hdr.ticks_active_to_start, + ticks_slot_offset = MAX(_radio.scanner.hdr.ticks_active_to_start, _radio.scanner.hdr.ticks_xtal_to_start); ticks_anchor = ticker_ticks_now_get(); diff --git a/subsys/bluetooth/controller/ll_sw/ctrl_internal.h b/subsys/bluetooth/controller/ll_sw/ctrl_internal.h index ee8762dad80..ce55cda2acf 100644 --- a/subsys/bluetooth/controller/ll_sw/ctrl_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ctrl_internal.h @@ -319,7 +319,7 @@ struct pdu_data_q_tx { #define LL_MEM_RX_POOL_SZ (MROUND(offsetof(struct radio_pdu_node_rx, \ pdu_data) + \ - max((PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA), \ + MAX((PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA), \ (offsetof(struct pdu_data, lldata) + \ LL_LENGTH_OCTETS_RX_MAX))) * \ (RADIO_PACKET_COUNT_RX_MAX + 3)) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index 2d994e0e537..4e059563856 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -326,11 +326,11 @@ u32_t lll_evt_offset_get(struct evt_hdr *evt) if (0) { #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) } else if (evt->ticks_xtal_to_start & XON_BITMASK) { - return max(evt->ticks_active_to_start, + return MAX(evt->ticks_active_to_start, evt->ticks_preempt_to_start); #endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */ } else { - return max(evt->ticks_active_to_start, + return MAX(evt->ticks_active_to_start, evt->ticks_xtal_to_start); } } @@ -391,7 +391,7 @@ static int prepare(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, /* Calc the preempt timeout */ evt = HDR_LLL2EVT(prepare_param->param); preempt_anchor = prepare_param->ticks_at_expire; - preempt_to = max(evt->ticks_active_to_start, + preempt_to = MAX(evt->ticks_active_to_start, evt->ticks_xtal_to_start) - evt->ticks_preempt_to_start; diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 9e37bce1a94..650ddafdcbd 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -149,7 +149,7 @@ static MFIFO_DEFINE(ll_pdu_rx_free, sizeof(void *), LL_PDU_RX_CNT); #define PDU_RX_POOL_SIZE (MROUND(offsetof(struct node_rx_pdu, pdu) + \ sizeof(struct node_rx_ftr) + \ - max((PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA), \ + MAX((PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA), \ (offsetof(struct pdu_data, lldata) + \ PDU_RX_OCTETS_MAX))) * RX_CNT) diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index dff4539afb3..214ed92a99b 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -715,7 +715,7 @@ u8_t ll_adv_enable(u8_t enable) HAL_TICKER_US_TO_TICKS(EVENT_OVERHEAD_PREEMPT_MIN_US); adv->evt.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us); - ticks_slot_offset = max(adv->evt.ticks_active_to_start, + ticks_slot_offset = MAX(adv->evt.ticks_active_to_start, adv->evt.ticks_xtal_to_start); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 1e168c7f03b..de34d28fa59 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1452,7 +1452,7 @@ static inline void event_conn_upd_init(struct ll_conn *conn, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->evt.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->evt.ticks_active_to_start, + MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_preempt_to_start); conn->llcp.conn_upd.ticks_anchor -= @@ -1620,7 +1620,7 @@ static inline int event_conn_upd_prep(struct ll_conn *conn, /* restore to normal prepare */ if (conn->evt.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->evt.ticks_active_to_start, + MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_preempt_to_start); conn->evt.ticks_xtal_to_start &= ~XON_BITMASK; @@ -1645,7 +1645,7 @@ static inline int event_conn_upd_prep(struct ll_conn *conn, lll->latency_prepare -= (instant_latency - latency); /* calculate the offset, window widening and interval */ - ticks_slot_offset = max(conn->evt.ticks_active_to_start, + ticks_slot_offset = MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_xtal_to_start); conn_interval_us = conn->llcp.conn_upd.interval * 1250; periodic_us = conn_interval_us; @@ -2162,7 +2162,7 @@ static inline void event_conn_param_req(struct ll_conn *conn, #if defined(CONFIG_BT_CTLR_XTAL_ADVANCED) if (conn->evt.ticks_xtal_to_start & XON_BITMASK) { u32_t ticks_prepare_to_start = - max(conn->evt.ticks_active_to_start, + MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_preempt_to_start); conn->llcp_conn_param.ticks_ref -= diff --git a/subsys/bluetooth/controller/ll_sw/ull_master.c b/subsys/bluetooth/controller/ll_sw/ull_master.c index eeade35c7ec..c802c2928de 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_master.c +++ b/subsys/bluetooth/controller/ll_sw/ull_master.c @@ -473,7 +473,7 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, ftr->us_radio_rdy + 328 + TIFS_US + 328); - ticks_slot_offset = max(conn->evt.ticks_active_to_start, + ticks_slot_offset = MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_xtal_to_start); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { @@ -630,7 +630,7 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, conn->hdr.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS( EVENT_OVERHEAD_PREEMPT_MIN_US); conn->hdr.ticks_slot = _radio.scanner.ticks_conn_slot; - ticks_slot_offset = max(conn->hdr.ticks_active_to_start, + ticks_slot_offset = MAX(conn->hdr.ticks_active_to_start, conn->hdr.ticks_xtal_to_start); /* Stop Scanner */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index 15cd528eed4..2bd494a91f5 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -191,7 +191,7 @@ u8_t ull_scan_enable(struct ll_scan_set *scan) lll->ticks_window = 0; } - ticks_slot_offset = max(scan->evt.ticks_active_to_start, + ticks_slot_offset = MAX(scan->evt.ticks_active_to_start, scan->evt.ticks_xtal_to_start); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { diff --git a/subsys/bluetooth/controller/ll_sw/ull_slave.c b/subsys/bluetooth/controller/ll_sw/ull_slave.c index 8be39e8e2fe..74eb51e5cec 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_slave.c +++ b/subsys/bluetooth/controller/ll_sw/ull_slave.c @@ -271,7 +271,7 @@ void ull_slave_setup(memq_link_t *link, struct node_rx_hdr *rx, ftr->us_radio_rdy + 328 + TIFS_US + 328); - ticks_slot_offset = max(conn->evt.ticks_active_to_start, + ticks_slot_offset = MAX(conn->evt.ticks_active_to_start, conn->evt.ticks_xtal_to_start); if (IS_ENABLED(CONFIG_BT_CTLR_LOW_LAT)) { diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index b228eb90df9..fe1adb339e0 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -1040,7 +1040,7 @@ static inline void ticker_job_compare_update(struct ticker_instance *instance, ticks_elapsed = ticker_ticks_diff_get(ctr, cc) + HAL_TICKER_CNTR_CMP_OFFSET_MIN + HAL_TICKER_CNTR_SET_LATENCY; - cc += max(ticks_elapsed, ticks_to_expire); + cc += MAX(ticks_elapsed, ticks_to_expire); cc &= HAL_TICKER_CNTR_MASK; instance->trigger_set_cb(cc); diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 2a691b79e4b..3246bce7d90 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -247,7 +247,7 @@ static u8_t att_mtu_req(struct bt_att *att, struct net_buf *buf) * A device's Exchange MTU Request shall contain the same MTU as the * device's Exchange MTU Response (i.e. the MTU shall be symmetric). */ - att->chan.rx.mtu = min(mtu_client, mtu_server); + att->chan.rx.mtu = MIN(mtu_client, mtu_server); att->chan.tx.mtu = att->chan.rx.mtu; BT_DBG("Negotiated MTU %u", att->chan.rx.mtu); @@ -363,7 +363,7 @@ static u8_t att_mtu_rsp(struct bt_att *att, struct net_buf *buf) return att_handle_rsp(att, NULL, 0, BT_ATT_ERR_INVALID_PDU); } - att->chan.rx.mtu = min(mtu, BT_ATT_MTU); + att->chan.rx.mtu = MIN(mtu, BT_ATT_MTU); /* BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part F] page 484: * diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 7c507d82432..33613ee7bf7 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1308,7 +1308,7 @@ static struct net_buf *create_frag(struct bt_conn *conn, struct net_buf *buf) /* Fragments never have a TX completion callback */ conn_tx(frag)->cb = NULL; - frag_len = min(conn_mtu(conn), net_buf_tailroom(frag)); + frag_len = MIN(conn_mtu(conn), net_buf_tailroom(frag)); net_buf_add_mem(frag, buf->data, frag_len); net_buf_pull(buf, frag_len); diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index 647627b95d2..a54b327c6cf 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -796,7 +796,7 @@ ssize_t bt_gatt_attr_read(struct bt_conn *conn, const struct bt_gatt_attr *attr, return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } - len = min(buf_len, value_len - offset); + len = MIN(buf_len, value_len - offset); BT_DBG("handle 0x%04x offset %u length %u", attr->handle, offset, len); @@ -2552,7 +2552,7 @@ static int gatt_prepare_write(struct bt_conn *conn, struct bt_att_prepare_write_req *req; u16_t len; - len = min(params->length, bt_att_get_mtu(conn) - sizeof(*req) - 1); + len = MIN(params->length, bt_att_get_mtu(conn) - sizeof(*req) - 1); buf = bt_att_create_pdu(conn, BT_ATT_OP_PREPARE_WRITE_REQ, sizeof(*req) + len); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 343741af478..0ed654df6ea 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3652,7 +3652,7 @@ static void read_buffer_size_complete(struct net_buf *buf) BT_DBG("ACL BR/EDR buffers: pkts %u mtu %u", pkts, bt_dev.le.mtu); - pkts = min(pkts, CONFIG_BT_CONN_TX_MAX); + pkts = MIN(pkts, CONFIG_BT_CONN_TX_MAX); k_sem_init(&bt_dev.le.pkts, pkts, pkts); } @@ -3673,7 +3673,7 @@ static void le_read_buffer_size_complete(struct net_buf *buf) BT_DBG("ACL LE buffers: pkts %u mtu %u", rp->le_max_num, bt_dev.le.mtu); - le_max_num = min(rp->le_max_num, CONFIG_BT_CONN_TX_MAX); + le_max_num = MIN(rp->le_max_num, CONFIG_BT_CONN_TX_MAX); k_sem_init(&bt_dev.le.pkts, le_max_num, le_max_num); } #endif @@ -4858,7 +4858,7 @@ int bt_set_id_addr(const bt_addr_le_t *addr) void bt_id_get(bt_addr_le_t *addrs, size_t *count) { - size_t to_copy = min(*count, bt_dev.id_count); + size_t to_copy = MIN(*count, bt_dev.id_count); memcpy(addrs, bt_dev.id_addr, to_copy * sizeof(bt_addr_le_t)); *count = to_copy; @@ -5053,7 +5053,7 @@ static uint8_t bt_read_static_addr(bt_addr_le_t *addr) return 0; } rp = (void *)rsp->data; - cnt = min(rp->num_addrs, CONFIG_BT_ID_MAX); + cnt = MIN(rp->num_addrs, CONFIG_BT_ID_MAX); for (i = 0; i < cnt; i++) { addr[i].type = BT_ADDR_LE_RANDOM; diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 0bb17ca7c32..936d74bed2a 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -662,7 +662,7 @@ static void l2cap_chan_rx_init(struct bt_l2cap_le_chan *chan) /* MPS shall not be bigger than MTU + 2 as the remaining bytes cannot * be used. */ - chan->rx.mps = min(chan->rx.mtu + 2, L2CAP_MAX_LE_MPS); + chan->rx.mps = MIN(chan->rx.mtu + 2, L2CAP_MAX_LE_MPS); k_sem_init(&chan->rx.credits, 0, UINT_MAX); if (BT_DBG_ENABLED && @@ -1085,9 +1085,9 @@ segment: } /* Don't send more that TX MPS including SDU length */ - len = min(net_buf_tailroom(seg), ch->tx.mps - sdu_hdr_len); + len = MIN(net_buf_tailroom(seg), ch->tx.mps - sdu_hdr_len); /* Limit if original buffer is smaller than the segment */ - len = min(buf->len, len); + len = MIN(buf->len, len); net_buf_add_mem(seg, buf->data, len); net_buf_pull(buf, len); diff --git a/subsys/bluetooth/host/l2cap_br.c b/subsys/bluetooth/host/l2cap_br.c index ac67aea023f..95e7dabf410 100644 --- a/subsys/bluetooth/host/l2cap_br.c +++ b/subsys/bluetooth/host/l2cap_br.c @@ -740,7 +740,7 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, u8_t ident, atomic_set_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_ACCEPTOR); /* Disable fragmentation of l2cap rx pdu */ - BR_CHAN(chan)->rx.mtu = min(BR_CHAN(chan)->rx.mtu, L2CAP_BR_MAX_MTU); + BR_CHAN(chan)->rx.mtu = MIN(BR_CHAN(chan)->rx.mtu, L2CAP_BR_MAX_MTU); switch (l2cap_br_conn_security(chan, psm)) { case L2CAP_CONN_SECURITY_PENDING: diff --git a/subsys/bluetooth/host/mesh/adv.c b/subsys/bluetooth/host/mesh/adv.c index 3111abe269a..b3855f0d036 100644 --- a/subsys/bluetooth/host/mesh/adv.c +++ b/subsys/bluetooth/host/mesh/adv.c @@ -103,7 +103,7 @@ static inline void adv_send(struct net_buf *buf) struct bt_data ad; int err; - adv_int = max(adv_int_min, + adv_int = MAX(adv_int_min, BT_MESH_TRANSMIT_INT(BT_MESH_ADV(buf)->xmit)); duration = (MESH_SCAN_WINDOW_MS + ((BT_MESH_TRANSMIT_COUNT(BT_MESH_ADV(buf)->xmit) + 1) * diff --git a/subsys/bluetooth/host/mesh/cfg_cli.c b/subsys/bluetooth/host/mesh/cfg_cli.c index a09d3113c3a..abdf60c11f7 100644 --- a/subsys/bluetooth/host/mesh/cfg_cli.c +++ b/subsys/bluetooth/host/mesh/cfg_cli.c @@ -55,7 +55,7 @@ static void comp_data_status(struct bt_mesh_model *model, param = cli->op_param; *(param->status) = net_buf_simple_pull_u8(buf); - to_copy = min(net_buf_simple_tailroom(param->comp), buf->len); + to_copy = MIN(net_buf_simple_tailroom(param->comp), buf->len); net_buf_simple_add_mem(param->comp, buf->data, to_copy); k_sem_give(&cli->op_sync); diff --git a/subsys/bluetooth/host/mesh/cfg_srv.c b/subsys/bluetooth/host/mesh/cfg_srv.c index 3e133306008..fef5f770652 100644 --- a/subsys/bluetooth/host/mesh/cfg_srv.c +++ b/subsys/bluetooth/host/mesh/cfg_srv.c @@ -3378,8 +3378,8 @@ void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat) return; } - cfg->hb_sub.min_hops = min(cfg->hb_sub.min_hops, hops); - cfg->hb_sub.max_hops = max(cfg->hb_sub.max_hops, hops); + cfg->hb_sub.min_hops = MIN(cfg->hb_sub.min_hops, hops); + cfg->hb_sub.max_hops = MAX(cfg->hb_sub.max_hops, hops); if (cfg->hb_sub.count < 0xffff) { cfg->hb_sub.count++; diff --git a/subsys/bluetooth/host/mesh/lpn.c b/subsys/bluetooth/host/mesh/lpn.c index 48094bd9cff..8171e1f0686 100644 --- a/subsys/bluetooth/host/mesh/lpn.c +++ b/subsys/bluetooth/host/mesh/lpn.c @@ -35,7 +35,7 @@ #endif #define LPN_RECV_DELAY CONFIG_BT_MESH_LPN_RECV_DELAY -#define SCAN_LATENCY min(CONFIG_BT_MESH_LPN_SCAN_LATENCY, \ +#define SCAN_LATENCY MIN(CONFIG_BT_MESH_LPN_SCAN_LATENCY, \ LPN_RECV_DELAY) #define FRIEND_REQ_RETRY_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_RETRY_TIMEOUT) @@ -834,12 +834,12 @@ static s32_t poll_timeout(struct bt_mesh_lpn *lpn) { /* If we're waiting for segment acks keep polling at high freq */ if (bt_mesh_tx_in_progress()) { - return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); + return MIN(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); } if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) { lpn->poll_timeout *= 2; - lpn->poll_timeout = min(lpn->poll_timeout, + lpn->poll_timeout = MIN(lpn->poll_timeout, POLL_TIMEOUT_MAX(lpn)); } @@ -962,7 +962,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, } /* Set initial poll timeout */ - lpn->poll_timeout = min(POLL_TIMEOUT_MAX(lpn), + lpn->poll_timeout = MIN(POLL_TIMEOUT_MAX(lpn), POLL_TIMEOUT_INIT); } diff --git a/subsys/bluetooth/host/mesh/prov.c b/subsys/bluetooth/host/mesh/prov.c index e0fe710d507..2efe1f41e27 100644 --- a/subsys/bluetooth/host/mesh/prov.c +++ b/subsys/bluetooth/host/mesh/prov.c @@ -408,7 +408,7 @@ static int prov_send_adv(struct net_buf_simple *msg) link.tx.buf[0] = start; - seg_len = min(msg->len, START_PAYLOAD_MAX); + seg_len = MIN(msg->len, START_PAYLOAD_MAX); BT_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len)); net_buf_add_mem(start, msg->data, seg_len); net_buf_simple_pull(msg, seg_len); @@ -429,7 +429,7 @@ static int prov_send_adv(struct net_buf_simple *msg) link.tx.buf[seg_id] = buf; - seg_len = min(msg->len, CONT_PAYLOAD_MAX); + seg_len = MIN(msg->len, CONT_PAYLOAD_MAX); BT_DBG("seg_id %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len)); diff --git a/subsys/bluetooth/host/mesh/proxy.c b/subsys/bluetooth/host/mesh/proxy.c index c4bb54201c2..6479b524bd9 100644 --- a/subsys/bluetooth/host/mesh/proxy.c +++ b/subsys/bluetooth/host/mesh/proxy.c @@ -1170,8 +1170,8 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) * 6 slices, but make sure that a slice is at least one * second long (to avoid excessive rotation). */ - max_timeout = NODE_ID_TIMEOUT / max(subnet_count, 6); - max_timeout = max(max_timeout, K_SECONDS(1)); + max_timeout = NODE_ID_TIMEOUT / MAX(subnet_count, 6); + max_timeout = MAX(max_timeout, K_SECONDS(1)); if (remaining > max_timeout || remaining < 0) { remaining = max_timeout; diff --git a/subsys/bluetooth/host/mesh/transport.c b/subsys/bluetooth/host/mesh/transport.c index 8cf0f1fd8bc..dafba9fabfe 100644 --- a/subsys/bluetooth/host/mesh/transport.c +++ b/subsys/bluetooth/host/mesh/transport.c @@ -379,7 +379,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, (seg_o >> 3))); net_buf_add_u8(seg, ((seg_o & 0x07) << 5) | tx->seg_n); - len = min(sdu->len, 12); + len = MIN(sdu->len, 12); net_buf_add_mem(seg, sdu->data, len); net_buf_simple_pull(sdu, len); @@ -921,7 +921,7 @@ static inline s32_t ack_timeout(struct seg_rx *rx) /* Make sure we don't send more frequently than the duration for * each packet (default is 300ms). */ - return max(to, K_MSEC(400)); + return MAX(to, K_MSEC(400)); } int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, diff --git a/subsys/bluetooth/host/monitor.c b/subsys/bluetooth/host/monitor.c index 17c797c49fd..963583b5200 100644 --- a/subsys/bluetooth/host/monitor.c +++ b/subsys/bluetooth/host/monitor.c @@ -86,7 +86,7 @@ static void encode_drops(struct bt_monitor_hdr *hdr, u8_t type, count = atomic_set(val, 0); if (count) { hdr->ext[hdr->hdr_len++] = type; - hdr->ext[hdr->hdr_len++] = min(count, 255); + hdr->ext[hdr->hdr_len++] = MIN(count, 255); } } diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c index 565a03d846b..b30489f4d80 100644 --- a/subsys/bluetooth/host/rfcomm.c +++ b/subsys/bluetooth/host/rfcomm.c @@ -402,7 +402,7 @@ static void rfcomm_connected(struct bt_l2cap_chan *chan) BT_DBG("Session %p", session); /* Need to include UIH header and FCS*/ - session->mtu = min(session->br_chan.rx.mtu, + session->mtu = MIN(session->br_chan.rx.mtu, session->br_chan.tx.mtu) - BT_RFCOMM_HDR_SIZE + BT_RFCOMM_FCS_SIZE; @@ -480,7 +480,7 @@ static struct bt_rfcomm_dlc *rfcomm_dlc_accept(struct bt_rfcomm_session *session } rfcomm_dlc_init(dlc, session, dlci, BT_RFCOMM_ROLE_ACCEPTOR); - dlc->mtu = min(dlc->mtu, session->mtu); + dlc->mtu = MIN(dlc->mtu, session->mtu); return dlc; } @@ -963,7 +963,7 @@ static int rfcomm_dlc_start(struct bt_rfcomm_dlc *dlc) result = rfcomm_dlc_security(dlc); switch (result) { case RFCOMM_SECURITY_PASSED: - dlc->mtu = min(dlc->mtu, dlc->session->mtu); + dlc->mtu = MIN(dlc->mtu, dlc->session->mtu); dlc->state = BT_RFCOMM_STATE_CONFIG; rfcomm_send_pn(dlc, BT_RFCOMM_MSG_CMD_CR); break; @@ -1182,7 +1182,7 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session, BT_DBG("Incoming connection accepted dlc %p", dlc); - dlc->mtu = min(dlc->mtu, sys_le16_to_cpu(pn->mtu)); + dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); if (pn->flow_ctrl == BT_RFCOMM_PN_CFC_CMD) { if (session->cfc == BT_RFCOMM_CFC_UNKNOWN) { @@ -1206,14 +1206,14 @@ static void rfcomm_handle_pn(struct bt_rfcomm_session *session, rfcomm_dlc_close(dlc); return; } - dlc->mtu = min(dlc->mtu, sys_le16_to_cpu(pn->mtu)); + dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); rfcomm_send_pn(dlc, BT_RFCOMM_MSG_RESP_CR); } else { if (dlc->state != BT_RFCOMM_STATE_CONFIG) { return; } - dlc->mtu = min(dlc->mtu, sys_le16_to_cpu(pn->mtu)); + dlc->mtu = MIN(dlc->mtu, sys_le16_to_cpu(pn->mtu)); if (pn->flow_ctrl == BT_RFCOMM_PN_CFC_RESP) { if (session->cfc == BT_RFCOMM_CFC_UNKNOWN) { session->cfc = BT_RFCOMM_CFC_SUPPORTED; @@ -1538,7 +1538,7 @@ static void rfcomm_encrypt_change(struct bt_l2cap_chan *chan, rfcomm_send_ua(session, dlc->dlci); rfcomm_dlc_connected(dlc); } else { - dlc->mtu = min(dlc->mtu, session->mtu); + dlc->mtu = MIN(dlc->mtu, session->mtu); dlc->state = BT_RFCOMM_STATE_CONFIG; rfcomm_send_pn(dlc, BT_RFCOMM_MSG_CMD_CR); } diff --git a/subsys/bluetooth/host/sdp.c b/subsys/bluetooth/host/sdp.c index 3c37eb25ff8..222d9ce2900 100644 --- a/subsys/bluetooth/host/sdp.c +++ b/subsys/bluetooth/host/sdp.c @@ -650,7 +650,7 @@ static u16_t sdp_svc_search_req(struct bt_sdp *sdp, struct net_buf *buf, /* 4 bytes per Service Record Handle */ /* 4 bytes for ContinuationState */ - if ((min(SDP_MTU, sdp->chan.tx.mtu) - resp_buf->len) < + if ((MIN(SDP_MTU, sdp->chan.tx.mtu) - resp_buf->len) < (4 + 4 + sizeof(struct bt_sdp_hdr))) { pkt_full = true; } @@ -846,7 +846,7 @@ static u8_t select_attrs(struct bt_sdp_attribute *attr, u8_t att_idx, } if (sad->rsp_buf) { - space = min(SDP_MTU, sad->sdp->chan.tx.mtu) - + space = MIN(SDP_MTU, sad->sdp->chan.tx.mtu) - sad->rsp_buf->len - sizeof(struct bt_sdp_hdr); if ((!sad->state->pkt_full) && diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 9b819ea5f9f..f6a33f7833b 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -539,7 +539,7 @@ static u8_t get_encryption_key_size(struct bt_smp *smp) * encryption key length parameters shall be used as the encryption key * size. */ - return min(req->max_key_size, rsp->max_key_size); + return MIN(req->max_key_size, rsp->max_key_size); } #if defined(CONFIG_BT_PRIVACY) || defined(CONFIG_BT_SIGNING) || \ diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 4aef2e33794..78885dd1215 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -57,7 +57,7 @@ static bool data_cb(struct bt_data *data, void *user_data) switch (data->type) { case BT_DATA_NAME_SHORTENED: case BT_DATA_NAME_COMPLETE: - memcpy(name, data->data, min(data->data_len, NAME_LEN - 1)); + memcpy(name, data->data, MIN(data->data_len, NAME_LEN - 1)); return false; default: return true; diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index 182f5a6f8a3..d111a22317d 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -318,7 +318,7 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[]) size_t len; int i; - len = min(strtoul(argv[4], NULL, 16), sizeof(gatt_write_buf)); + len = MIN(strtoul(argv[4], NULL, 16), sizeof(gatt_write_buf)); for (i = 1; i < len; i++) { gatt_write_buf[i] = gatt_write_buf[0]; @@ -371,7 +371,7 @@ static int cmd_write_without_rsp(const struct shell *shell, if (argc > 3) { int i; - len = min(strtoul(argv[3], NULL, 16), sizeof(gatt_write_buf)); + len = MIN(strtoul(argv[3], NULL, 16), sizeof(gatt_write_buf)); for (i = 1; i < len; i++) { gatt_write_buf[i] = gatt_write_buf[0]; @@ -673,7 +673,7 @@ static ssize_t read_met(struct bt_conn *conn, const struct bt_gatt_attr *attr, const char *value = attr->user_data; u16_t value_len; - value_len = min(strlen(value), CHAR_SIZE_MAX); + value_len = MIN(strlen(value), CHAR_SIZE_MAX); return bt_gatt_attr_read(conn, attr, buf, len, offset, value, value_len); diff --git a/subsys/bluetooth/shell/l2cap.c b/subsys/bluetooth/shell/l2cap.c index 4f5bdc18032..25bf8bb2255 100644 --- a/subsys/bluetooth/shell/l2cap.c +++ b/subsys/bluetooth/shell/l2cap.c @@ -307,7 +307,7 @@ static int cmd_send(const struct shell *shell, size_t argc, char *argv[]) count = strtoul(argv[1], NULL, 10); } - len = min(l2ch_chan.ch.tx.mtu, DATA_MTU - BT_L2CAP_CHAN_SEND_RESERVE); + len = MIN(l2ch_chan.ch.tx.mtu, DATA_MTU - BT_L2CAP_CHAN_SEND_RESERVE); while (count--) { buf = net_buf_alloc(&data_tx_pool, K_FOREVER); diff --git a/subsys/bluetooth/shell/rfcomm.c b/subsys/bluetooth/shell/rfcomm.c index 3f20cd8d79e..edb2f087b04 100644 --- a/subsys/bluetooth/shell/rfcomm.c +++ b/subsys/bluetooth/shell/rfcomm.c @@ -204,7 +204,7 @@ static int cmd_send(const struct shell *shell, size_t argc, char *argv[]) while (count--) { buf = bt_rfcomm_create_pdu(&pool); /* Should reserve one byte in tail for FCS */ - len = min(rfcomm_dlc.mtu, net_buf_tailroom(buf) - 1); + len = MIN(rfcomm_dlc.mtu, net_buf_tailroom(buf) - 1); net_buf_add_mem(buf, buf_data, len); ret = bt_rfcomm_dlc_send(&rfcomm_dlc, buf); diff --git a/subsys/disk/disk_access_sdhc.c b/subsys/disk/disk_access_sdhc.c index 6dc42d44d59..51595897718 100644 --- a/subsys/disk/disk_access_sdhc.c +++ b/subsys/disk/disk_access_sdhc.c @@ -567,7 +567,7 @@ static int sdhc_rx_block(struct sdhc_data *data, u8_t *buf, int len) /* Read the data in batches */ for (i = 0; i < len; i += sizeof(sdhc_ones)) { - int remain = min(sizeof(sdhc_ones), len - i); + int remain = MIN(sizeof(sdhc_ones), len - i); struct spi_buf tx_bufs[] = { { diff --git a/subsys/fs/nvs/nvs.c b/subsys/fs/nvs/nvs.c index c28a5564053..59a0b4cdf4e 100644 --- a/subsys/fs/nvs/nvs.c +++ b/subsys/fs/nvs/nvs.c @@ -145,7 +145,7 @@ static int _nvs_flash_block_cmp(struct nvs_fs *fs, u32_t addr, const void *data, block_size = NVS_BLOCK_SIZE & ~(fs->write_block_size - 1); while (len) { - bytes_to_cmp = min(block_size, len); + bytes_to_cmp = MIN(block_size, len); rc = _nvs_flash_rd(fs, addr, buf, bytes_to_cmp); if (rc) { return rc; @@ -175,7 +175,7 @@ static int _nvs_flash_cmp_const(struct nvs_fs *fs, u32_t addr, u8_t value, block_size = NVS_BLOCK_SIZE & ~(fs->write_block_size - 1); (void)memset(cmp, value, block_size); while (len) { - bytes_to_cmp = min(block_size, len); + bytes_to_cmp = MIN(block_size, len); rc = _nvs_flash_block_cmp(fs, addr, cmp, bytes_to_cmp); if (rc) { return rc; @@ -198,7 +198,7 @@ static int _nvs_flash_block_move(struct nvs_fs *fs, u32_t addr, size_t len) block_size = NVS_BLOCK_SIZE & ~(fs->write_block_size - 1); while (len) { - bytes_to_copy = min(block_size, len); + bytes_to_copy = MIN(block_size, len); rc = _nvs_flash_rd(fs, addr, buf, bytes_to_copy); if (rc) { return rc; @@ -910,7 +910,7 @@ ssize_t nvs_read_hist(struct nvs_fs *fs, u16_t id, void *data, size_t len, rd_addr &= ADDR_SECT_MASK; rd_addr += wlk_ate.offset; - rc = _nvs_flash_rd(fs, rd_addr, data, min(len, wlk_ate.len)); + rc = _nvs_flash_rd(fs, rd_addr, data, MIN(len, wlk_ate.len)); if (rc) { goto err; } diff --git a/subsys/fs/shell.c b/subsys/fs/shell.c index a8e8f7de708..ccc71c88c58 100644 --- a/subsys/fs/shell.c +++ b/subsys/fs/shell.c @@ -281,7 +281,7 @@ static int cmd_read(const struct shell *shell, size_t argc, char **argv) u8_t buf[16]; int i; - read = fs_read(&file, buf, min(count, sizeof(buf))); + read = fs_read(&file, buf, MIN(count, sizeof(buf))); if (read <= 0) { break; } diff --git a/subsys/logging/log_backend_rtt.c b/subsys/logging/log_backend_rtt.c index 08c296dee80..6b08c746f03 100644 --- a/subsys/logging/log_backend_rtt.c +++ b/subsys/logging/log_backend_rtt.c @@ -110,7 +110,7 @@ static int line_out_drop_mode(void) } if (drop_warn) { - int cnt = min(drop_cnt, DROP_MAX); + int cnt = MIN(drop_cnt, DROP_MAX); if (cnt < 10) { line_buf[DROP_MSG_LEN - 2] = ' '; diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index e61d2ba5195..35a52630a75 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -189,7 +189,7 @@ int log_printk(const char *fmt, va_list ap) length = vsnprintk(formatted_str, sizeof(formatted_str), fmt, ap); - length = min(length, sizeof(formatted_str)); + length = MIN(length, sizeof(formatted_str)); msg = log_msg_hexdump_create(NULL, formatted_str, length); @@ -536,7 +536,7 @@ u32_t log_filter_set(struct log_backend const *const backend, backend = log_backend_get(i); current = log_filter_set(backend, domain_id, src_id, level); - max = max(current, max); + max = MAX(current, max); } level = max; @@ -544,7 +544,7 @@ u32_t log_filter_set(struct log_backend const *const backend, u32_t max = log_filter_get(backend, domain_id, src_id, false); - level = min(level, max); + level = MIN(level, max); LOG_FILTER_SLOT_SET(filters, log_backend_id_get(backend), diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 86223018d6b..92e4a7225d3 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -199,7 +199,7 @@ static void copy_args_to_msg(struct log_msg *msg, u32_t *args, u32_t nargs) } while (nargs != 0) { - u32_t cpy_args = min(nargs, ARGS_CONT_MSG); + u32_t cpy_args = MIN(nargs, ARGS_CONT_MSG); (void)memcpy(cont->payload.args, args, cpy_args * sizeof(u32_t)); diff --git a/subsys/logging/log_output.c b/subsys/logging/log_output.c index 5407c70bb49..52a7f6ca2a8 100644 --- a/subsys/logging/log_output.c +++ b/subsys/logging/log_output.c @@ -614,7 +614,7 @@ void log_output_dropped_process(const struct log_output *log_output, u32_t cnt) log_output_func_t outf = log_output->func; struct device *dev = (struct device *)log_output->control_block->ctx; - cnt = min(cnt, 9999); + cnt = MIN(cnt, 9999); len = snprintf(buf, sizeof(buf), "%d", cnt); buffer_write(outf, (u8_t *)prefix, sizeof(prefix) - 1, dev); diff --git a/subsys/net/buf.c b/subsys/net/buf.c index 03a8e3e200b..4b38a3c9898 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -145,7 +145,7 @@ static u8_t *fixed_data_alloc(struct net_buf *buf, size_t *size, s32_t timeout) struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); const struct net_buf_pool_fixed *fixed = pool->alloc->alloc_data; - *size = min(fixed->data_size, *size); + *size = MIN(fixed->data_size, *size); return fixed->data_pool + fixed->data_size * net_buf_id(buf); } @@ -316,7 +316,7 @@ success: if (timeout != K_NO_WAIT && timeout != K_FOREVER) { u32_t diff = k_uptime_get_32() - alloc_start; - timeout -= min(timeout, diff); + timeout -= MIN(timeout, diff); } buf->__buf = data_alloc(buf, &size, timeout); @@ -590,7 +590,7 @@ struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout) if (timeout != K_NO_WAIT && timeout != K_FOREVER) { u32_t diff = k_uptime_get_32() - alloc_start; - timeout -= min(timeout, diff); + timeout -= MIN(timeout, diff); } clone->__buf = data_alloc(clone, &size, timeout); @@ -681,7 +681,7 @@ size_t net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src, size_t to_copy; size_t copied; - len = min(len, dst_len); + len = MIN(len, dst_len); frag = src; @@ -694,7 +694,7 @@ size_t net_buf_linearize(void *dst, size_t dst_len, struct net_buf *src, /* traverse the fragment chain until len bytes are copied */ copied = 0; while (frag && len > 0) { - to_copy = min(len, frag->len - offset); + to_copy = MIN(len, frag->len - offset); memcpy((u8_t *)dst + copied, frag->data + offset, to_copy); copied += to_copy; @@ -723,7 +723,7 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len, const u8_t *value8 = value; do { - u16_t count = min(len, net_buf_tailroom(frag)); + u16_t count = MIN(len, net_buf_tailroom(frag)); net_buf_add_mem(frag, value8, count); len -= count; diff --git a/subsys/net/ip/dhcpv4.c b/subsys/net/ip/dhcpv4.c index 7c37b117876..b037ff05714 100644 --- a/subsys/net/ip/dhcpv4.c +++ b/subsys/net/ip/dhcpv4.c @@ -476,7 +476,7 @@ static void dhcpv4_enter_bound(struct net_if *iface) renewal_time, rebinding_time); iface->config.dhcpv4.timer_start = k_uptime_get(); - iface->config.dhcpv4.request_time = min(renewal_time, rebinding_time); + iface->config.dhcpv4.request_time = MIN(renewal_time, rebinding_time); dhcpv4_update_timeout_work(iface->config.dhcpv4.request_time); } @@ -517,7 +517,7 @@ static u32_t dhcph4_manage_timers(struct net_if *iface, s64_t timeout) return dhcpv4_send_request(iface); } - return min(iface->config.dhcpv4.renewal_time, + return MIN(iface->config.dhcpv4.renewal_time, iface->config.dhcpv4.rebinding_time); case NET_DHCPV4_RENEWING: case NET_DHCPV4_REBINDING: diff --git a/subsys/net/ip/net_pkt.c b/subsys/net/ip/net_pkt.c index 230645ad21d..5df15625424 100644 --- a/subsys/net/ip/net_pkt.c +++ b/subsys/net/ip/net_pkt.c @@ -600,12 +600,12 @@ static struct net_pkt *net_pkt_get(struct k_mem_slab *slab, iface_len = data_len = net_if_get_mtu(iface); if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6) { - data_len = max(iface_len, NET_IPV6_MTU); + data_len = MAX(iface_len, NET_IPV6_MTU); data_len -= NET_IPV6H_LEN; } if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET) { - data_len = max(iface_len, NET_IPV4_MTU); + data_len = MAX(iface_len, NET_IPV4_MTU); data_len -= NET_IPV4H_LEN; } @@ -1034,7 +1034,7 @@ int net_frag_linear_copy(struct net_buf *dst, struct net_buf *src, /* traverse the fragment chain until len bytes are copied */ copied = 0U; while (src && len > 0) { - to_copy = min(len, src->len - offset); + to_copy = MIN(len, src->len - offset); memcpy(dst->data + copied, src->data + offset, to_copy); copied += to_copy; @@ -1404,7 +1404,7 @@ struct net_buf *net_pkt_write(struct net_pkt *pkt, struct net_buf *frag, do { u16_t space = frag->size - net_buf_headroom(frag) - offset; - u16_t count = min(len, space); + u16_t count = MIN(len, space); int size_to_add; memcpy(frag->data + offset, data, count); @@ -1452,7 +1452,7 @@ static inline bool insert_data(struct net_pkt *pkt, struct net_buf *frag, struct net_buf *insert; do { - u16_t count = min(len, net_buf_tailroom(frag)); + u16_t count = MIN(len, net_buf_tailroom(frag)); if (data) { /* Copy insert data */ @@ -1660,7 +1660,7 @@ static struct net_buf *pkt_alloc_buffer(struct net_buf_pool *pool, if (timeout != K_NO_WAIT && timeout != K_FOREVER) { u32_t diff = k_uptime_get_32() - alloc_start; - timeout -= min(timeout, diff); + timeout -= MIN(timeout, diff); } #if CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG @@ -1723,9 +1723,9 @@ static size_t pkt_buffer_length(struct net_pkt *pkt, /* Family vs iface MTU */ if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6) { - max_len = max(max_len, NET_IPV6_MTU); + max_len = MAX(max_len, NET_IPV6_MTU); } else if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET) { - max_len = max(max_len, NET_IPV4_MTU); + max_len = MAX(max_len, NET_IPV4_MTU); } else { /* family == AF_UNSPEC */ #if defined (CONFIG_NET_L2_ETHERNET) if (net_if_l2(net_pkt_iface(pkt)) == @@ -1743,7 +1743,7 @@ static size_t pkt_buffer_length(struct net_pkt *pkt, max_len -= existing; - return min(size, max_len); + return MIN(size, max_len); } static size_t pkt_estimate_headers_length(struct net_pkt *pkt, @@ -1893,7 +1893,7 @@ int net_pkt_alloc_buffer(struct net_pkt *pkt, if (timeout != K_NO_WAIT && timeout != K_FOREVER) { u32_t diff = k_uptime_get_32() - alloc_start; - timeout -= min(timeout, diff); + timeout -= MIN(timeout, diff); } #if NET_LOG_LEVEL >= LOG_LEVEL_DBG @@ -2084,7 +2084,7 @@ pkt_alloc_with_buffer(struct k_mem_slab *slab, if (timeout != K_NO_WAIT && timeout != K_FOREVER) { u32_t diff = k_uptime_get_32() - alloc_start; - timeout -= min(timeout, diff); + timeout -= MIN(timeout, diff); } #if NET_LOG_LEVEL >= LOG_LEVEL_DBG diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index ff392e1e6aa..ec00cc9efab 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -282,7 +282,7 @@ struct net_tcp *net_tcp_alloc(struct net_context *context) tcp_context[i].context = context; tcp_context[i].send_seq = tcp_init_isn(); - tcp_context[i].recv_wnd = min(NET_TCP_MAX_WIN, NET_TCP_BUF_MAX_LEN); + tcp_context[i].recv_wnd = MIN(NET_TCP_MAX_WIN, NET_TCP_BUF_MAX_LEN); tcp_context[i].send_mss = NET_TCP_DEFAULT_MSS; tcp_context[i].accept_cb = NULL; diff --git a/subsys/net/ip/utils.c b/subsys/net/ip/utils.c index e1d54f0b0f5..f9bde19d474 100644 --- a/subsys/net/ip/utils.c +++ b/subsys/net/ip/utils.c @@ -555,7 +555,7 @@ static bool parse_ipv6(const char *str, size_t str_len, int end, len, ret, i; u16_t port; - len = min(INET6_ADDRSTRLEN, str_len); + len = MIN(INET6_ADDRSTRLEN, str_len); for (i = 0; i < len; i++) { if (!str[i]) { @@ -571,7 +571,7 @@ static bool parse_ipv6(const char *str, size_t str_len, return false; } - end = min(len, ptr - (str + 1)); + end = MIN(len, ptr - (str + 1)); memcpy(ipaddr, str + 1, end); } else { end = len; @@ -637,7 +637,7 @@ static bool parse_ipv4(const char *str, size_t str_len, int end, len, ret, i; u16_t port; - len = min(NET_IPV4_ADDR_LEN, str_len); + len = MIN(NET_IPV4_ADDR_LEN, str_len); for (i = 0; i < len; i++) { if (!str[i]) { @@ -653,7 +653,7 @@ static bool parse_ipv4(const char *str, size_t str_len, return false; } - end = min(len, ptr - str); + end = MIN(len, ptr - str); } else { end = len; } diff --git a/subsys/net/l2/ieee802154/ieee802154_fragment.c b/subsys/net/l2/ieee802154/ieee802154_fragment.c index 95c48998020..13f61dce7ff 100644 --- a/subsys/net/l2/ieee802154/ieee802154_fragment.c +++ b/subsys/net/l2/ieee802154/ieee802154_fragment.c @@ -128,7 +128,7 @@ static inline u8_t copy_data(struct ieee802154_fragment_ctx *ctx, { u8_t move = ctx->frag->len - (ctx->pos - ctx->frag->data); - move = min(move, max); + move = MIN(move, max); memcpy(frame_buf->data + frame_buf->len, ctx->pos, move); diff --git a/subsys/net/l2/ieee802154/ieee802154_radio_csma_ca.c b/subsys/net/l2/ieee802154/ieee802154_radio_csma_ca.c index b963937b5f1..e0d418792f0 100644 --- a/subsys/net/l2/ieee802154/ieee802154_radio_csma_ca.c +++ b/subsys/net/l2/ieee802154/ieee802154_radio_csma_ca.c @@ -49,7 +49,7 @@ loop: break; } - be = min(be + 1, max_be); + be = MIN(be + 1, max_be); nb++; if (nb > max_bo) { diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index 6ed94b07dcf..4c985509050 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -947,7 +947,7 @@ static int update_descriptive_block(struct coap_block_context *ctx, ctx->total_size = size; } ctx->current = new_current; - ctx->block_size = min(GET_BLOCK_SIZE(block), ctx->block_size); + ctx->block_size = MIN(GET_BLOCK_SIZE(block), ctx->block_size); return 0; } @@ -993,7 +993,7 @@ static int update_control_block2(struct coap_block_context *ctx, } ctx->current = new_current; - ctx->block_size = min(GET_BLOCK_SIZE(block), ctx->block_size); + ctx->block_size = MIN(GET_BLOCK_SIZE(block), ctx->block_size); return 0; } diff --git a/subsys/net/lib/dns/llmnr_responder.c b/subsys/net/lib/dns/llmnr_responder.c index 0c71af9f1ea..357f97a4116 100644 --- a/subsys/net/lib/dns/llmnr_responder.c +++ b/subsys/net/lib/dns/llmnr_responder.c @@ -473,7 +473,7 @@ static int dns_read(struct net_context *ctx, int offset; int ret; - data_len = min(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); + data_len = MIN(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); offset = net_pkt_get_len(pkt) - data_len; /* Store the DNS query name into a temporary net_buf. This means diff --git a/subsys/net/lib/dns/mdns_responder.c b/subsys/net/lib/dns/mdns_responder.c index 4c7f6404518..3acd77e6b09 100644 --- a/subsys/net/lib/dns/mdns_responder.c +++ b/subsys/net/lib/dns/mdns_responder.c @@ -296,7 +296,7 @@ static int dns_read(struct net_context *ctx, int offset; int ret; - data_len = min(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); + data_len = MIN(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); offset = net_pkt_get_len(pkt) - data_len; /* Store the DNS query name into a temporary net_buf. This means diff --git a/subsys/net/lib/dns/resolve.c b/subsys/net/lib/dns/resolve.c index 63b94a70689..4e5aab5eb4e 100644 --- a/subsys/net/lib/dns/resolve.c +++ b/subsys/net/lib/dns/resolve.c @@ -340,7 +340,7 @@ static int dns_read(struct dns_resolve_context *ctx, int ret; int server_idx, query_idx; - data_len = min(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); + data_len = MIN(net_pkt_appdatalen(pkt), DNS_RESOLVER_MAX_BUF_SIZE); offset = net_pkt_get_len(pkt) - data_len; /* TODO: Instead of this temporary copy, just use the net_pkt directly. diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index e442683dc8b..98d2b725a7b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -214,7 +214,7 @@ static char *sprint_token(const u8_t *token, u8_t tkl) if (token && tkl != LWM2M_MSG_TOKEN_LEN_SKIP) { int i; - tkl = min(tkl, sizeof(buf) / 2 - 1); + tkl = MIN(tkl, sizeof(buf) / 2 - 1); for (i = 0; i < tkl; i++) { *ptr++ = to_hex_digit(token[i] >> 4); @@ -541,7 +541,7 @@ static int engine_add_observer(struct lwm2m_message *msg, observe_node_data[i].event_timestamp = observe_node_data[i].last_timestamp; observe_node_data[i].min_period_sec = attrs.pmin; - observe_node_data[i].max_period_sec = max(attrs.pmax, attrs.pmin); + observe_node_data[i].max_period_sec = MAX(attrs.pmax, attrs.pmin); observe_node_data[i].format = format; observe_node_data[i].counter = 1U; sys_slist_append(&engine_observer_list, @@ -2337,7 +2337,7 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj, /* loop through options to parse attribute */ for (i = 0; i < nr_opt; i++) { - int limit = min(options[i].len, 5), plen = 0, vlen; + int limit = MIN(options[i].len, 5), plen = 0, vlen; float32_value_t val = { 0 }; type = 0U; @@ -2595,9 +2595,9 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj, obs->path.obj_id, obs->path.obj_inst_id, obs->path.res_id, obs->path.level, obs->min_period_sec, obs->max_period_sec, - nattrs.pmin, max(nattrs.pmin, nattrs.pmax)); + nattrs.pmin, MAX(nattrs.pmin, nattrs.pmax)); obs->min_period_sec = (u32_t)nattrs.pmin; - obs->max_period_sec = (u32_t)max(nattrs.pmin, nattrs.pmax); + obs->max_period_sec = (u32_t)MAX(nattrs.pmin, nattrs.pmax); (void)memset(&nattrs, 0, sizeof(nattrs)); } diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 444778708ea..5d212fcf76b 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -370,7 +370,7 @@ int zsock_accept_ctx(struct net_context *parent, struct sockaddr *addr, #endif if (addr != NULL && addrlen != NULL) { - int len = min(*addrlen, sizeof(ctx->remote)); + int len = MIN(*addrlen, sizeof(ctx->remote)); memcpy(addr, &ctx->remote, len); /* addrlen is a value-result argument, set to actual diff --git a/subsys/net/lib/sockets/sockets_tls.c b/subsys/net/lib/sockets/sockets_tls.c index b53cb44e5d2..397fc6288c7 100644 --- a/subsys/net/lib/sockets/sockets_tls.c +++ b/subsys/net/lib/sockets/sockets_tls.c @@ -443,7 +443,7 @@ static void dtls_peer_address_get(struct net_context *context, struct sockaddr *peer_addr, socklen_t *addrlen) { - socklen_t len = min(context->tls->dtls_peer_addrlen, *addrlen); + socklen_t len = MIN(context->tls->dtls_peer_addrlen, *addrlen); memcpy(peer_addr, &context->tls->dtls_peer_addr, len); *addrlen = len; @@ -938,7 +938,7 @@ static int tls_opt_sec_tag_list_get(struct net_context *context, return -EINVAL; } - len = min(context->tls->options.sec_tag_list.sec_tag_count * + len = MIN(context->tls->options.sec_tag_list.sec_tag_count * sizeof(sec_tag_t), *optlen); memcpy(optval, context->tls->options.sec_tag_list.sec_tags, len); @@ -1266,7 +1266,7 @@ int ztls_accept_ctx(struct net_context *parent, struct sockaddr *addr, #endif if (addr != NULL && addrlen != NULL) { - int len = min(*addrlen, sizeof(child->remote)); + int len = MIN(*addrlen, sizeof(child->remote)); memcpy(addr, &child->remote, len); /* addrlen is a value-result argument, set to actual diff --git a/subsys/settings/src/settings.c b/subsys/settings/src/settings.c index 5df29c7f6c7..8df4a8b25fb 100644 --- a/subsys/settings/src/settings.c +++ b/subsys/settings/src/settings.c @@ -140,7 +140,7 @@ int settings_val_read_cb(void *value_ctx, void *buf, size_t len) if (value_context->runtime) { rt_ctx = value_context->read_cb_ctx; - len_read = min(len, rt_ctx->size); + len_read = MIN(len, rt_ctx->size); memcpy(buf, rt_ctx->p_value, len_read); return len_read; } else { diff --git a/subsys/settings/src/settings_line.c b/subsys/settings/src/settings_line.c index 6b0dcbee194..9ad68dd9cbc 100644 --- a/subsys/settings/src/settings_line.c +++ b/subsys/settings/src/settings_line.c @@ -178,7 +178,7 @@ int settings_line_write(const char *name, const char *value, size_t val_len, while (w_size < sizeof(w_buf)) { #ifdef CONFIG_SETTINGS_USE_BASE64 if (enc_len) { - add = min(enc_len, sizeof(w_buf) - w_size); + add = MIN(enc_len, sizeof(w_buf) - w_size); memcpy(&w_buf[w_size], p_enc, add); enc_len -= add; w_size += add; @@ -187,7 +187,7 @@ int settings_line_write(const char *name, const char *value, size_t val_len, #endif if (rem) { #ifdef CONFIG_SETTINGS_USE_BASE64 - add = min(rem, MAX_ENC_BLOCK_SIZE/4*3); + add = MIN(rem, MAX_ENC_BLOCK_SIZE/4*3); rc = base64_encode(enc_buf, sizeof(enc_buf), &enc_len, value, add); if (rc) { return -EINVAL; @@ -196,7 +196,7 @@ int settings_line_write(const char *name, const char *value, size_t val_len, rem -= add; p_enc = enc_buf; #else - add = min(rem, sizeof(w_buf) - w_size); + add = MIN(rem, sizeof(w_buf) - w_size); memcpy(&w_buf[w_size], value, add); value += add; rem -= add; @@ -324,7 +324,7 @@ static int settings_line_raw_read_until(off_t seek, char *out, size_t len_req, off = seek - off; len = read_size - off; - len = min(rem_size, len); + len = MIN(rem_size, len); if (until_char != NULL) { char *pend; @@ -384,7 +384,7 @@ int settings_line_val_read(off_t val_off, off_t off, char *out, size_t len_req, read_size = rem_size / 3 * 4; read_size += (rem_size % 3 != 0 || off_begin != off) ? 4 : 0; - read_size = min(read_size, sizeof(enc_buf) - 1); + read_size = MIN(read_size, sizeof(enc_buf) - 1); exp_size = read_size; rc = settings_line_raw_read(val_off + seek_begin, enc_buf, @@ -406,7 +406,7 @@ int settings_line_val_read(off_t val_off, off_t off, char *out, size_t len_req, read_size); dec_buf[olen] = 0; - clen = min(olen + off_begin - off, rem_size); + clen = MIN(olen + off_begin - off, rem_size); memcpy(out, &dec_buf[off - off_begin], clen); rem_size -= clen; @@ -498,7 +498,7 @@ int settings_entry_copy(void *dst_ctx, off_t dst_off, void *src_ctx, size_t chunk_size; while (len) { - chunk_size = min(len, sizeof(buf)); + chunk_size = MIN(len, sizeof(buf)); rc = settings_io_cb.read_cb(src_ctx, src_off, buf, &chunk_size); if (rc) { diff --git a/subsys/settings/src/settings_store.c b/subsys/settings/src/settings_store.c index e9245822f20..48c7148abc0 100644 --- a/subsys/settings/src/settings_store.c +++ b/subsys/settings/src/settings_store.c @@ -81,7 +81,7 @@ static int settings_cmp(char const *val, size_t val_len, void *val_read_cb_ctx, off_t off = 0; for (rem = val_len; rem > 0; rem -= len_read) { - len_read = exp_len = min(sizeof(buf), rem); + len_read = exp_len = MIN(sizeof(buf), rem); rc = settings_line_val_read(val_off, off, buf, len_read, &len_read, val_read_cb_ctx); if (rc) { diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index 457922fb791..f2c8165122f 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -547,7 +547,7 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, LOG_DBG("Return HID Descriptor"); - *len = min(*len, hid_desc->if0_hid.bLength); + *len = MIN(*len, hid_desc->if0_hid.bLength); *data = (u8_t *)&hid_desc->if0_hid; break; case HID_CLASS_DESCRIPTOR_REPORT: @@ -560,7 +560,7 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, if (*len != dev_data->report_size) { LOG_WRN("len %d doesn't match " "Report Descriptor size", *len); - *len = min(*len, dev_data->report_size); + *len = MIN(*len, dev_data->report_size); } *data = (u8_t *)dev_data->report_desc; break; diff --git a/subsys/usb/class/netusb/function_rndis.c b/subsys/usb/class/netusb/function_rndis.c index 812c1a32b3a..9b7db07286f 100644 --- a/subsys/usb/class/netusb/function_rndis.c +++ b/subsys/usb/class/netusb/function_rndis.c @@ -1081,7 +1081,7 @@ static int append_bytes(u8_t *out_buf, u16_t buf_len, u8_t *data, int ret; do { - u16_t count = min(len, remaining); + u16_t count = MIN(len, remaining); #if VERBOSE_DEBUG LOG_DBG("len %u remaining %u count %u", len, remaining, count); #endif diff --git a/subsys/usb/class/usb_dfu.c b/subsys/usb/class/usb_dfu.c index 6f95bef8446..388daf15c7c 100644 --- a/subsys/usb/class/usb_dfu.c +++ b/subsys/usb/class/usb_dfu.c @@ -59,7 +59,7 @@ LOG_MODULE_REGISTER(usb_dfu); #define NUMOF_ALTERNATE_SETTINGS 2 #ifdef CONFIG_USB_COMPOSITE_DEVICE -#define USB_DFU_MAX_XFER_SIZE (min(CONFIG_USB_COMPOSITE_BUFFER_SIZE, \ +#define USB_DFU_MAX_XFER_SIZE (MIN(CONFIG_USB_COMPOSITE_BUFFER_SIZE, \ CONFIG_USB_DFU_MAX_XFER_SIZE)) #else #define USB_DFU_MAX_XFER_SIZE CONFIG_USB_DFU_MAX_XFER_SIZE diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c index 22274c7f998..33c5a4641eb 100644 --- a/subsys/usb/usb_device.c +++ b/subsys/usb/usb_device.c @@ -303,7 +303,7 @@ static void usb_handle_control_transfer(u8_t ep, } /* Send smallest of requested and offered length */ - usb_dev.data_buf_residue = min(usb_dev.data_buf_len, length); + usb_dev.data_buf_residue = MIN(usb_dev.data_buf_len, length); /* Send first part (possibly a zero-length status message) */ usb_data_to_host(); } else if (ep == USB_CONTROL_OUT_EP0) { diff --git a/tests/benchmarks/app_kernel/src/pipe_b.c b/tests/benchmarks/app_kernel/src/pipe_b.c index d094113d298..00c3b3cd19d 100644 --- a/tests/benchmarks/app_kernel/src/pipe_b.c +++ b/tests/benchmarks/app_kernel/src/pipe_b.c @@ -209,7 +209,7 @@ int pipeput(struct k_pipe *pipe, t = BENCH_START(); for (i = 0; option == _1_TO_N || (i < count); i++) { size_t sizexferd = 0; - size_t size2xfer = min(size, size2xfer_total - sizexferd_total); + size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total); int ret; size_t mim_num_of_bytes = 0; diff --git a/tests/benchmarks/app_kernel/src/pipe_r.c b/tests/benchmarks/app_kernel/src/pipe_r.c index e06aee39f84..5b47c5497c5 100644 --- a/tests/benchmarks/app_kernel/src/pipe_r.c +++ b/tests/benchmarks/app_kernel/src/pipe_r.c @@ -99,7 +99,7 @@ int pipeget(struct k_pipe *pipe, enum pipe_options option, int size, int count, t = BENCH_START(); for (i = 0; option == _1_TO_N || (i < count); i++) { size_t sizexferd = 0; - size_t size2xfer = min(size, size2xfer_total - sizexferd_total); + size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total); int ret; ret = k_pipe_get(pipe, data_recv, size2xfer, diff --git a/tests/bluetooth/tester/src/mesh.c b/tests/bluetooth/tester/src/mesh.c index c2d44774291..582eea7d71a 100644 --- a/tests/bluetooth/tester/src/mesh.c +++ b/tests/bluetooth/tester/src/mesh.c @@ -612,12 +612,12 @@ static void health_generate_faults(u8_t *data, u16_t len) rp = net_buf_simple_add(&buf, sizeof(*rp)); - cur_faults_count = min(sizeof(cur_faults), sizeof(some_faults)); + cur_faults_count = MIN(sizeof(cur_faults), sizeof(some_faults)); memcpy(cur_faults, some_faults, cur_faults_count); net_buf_simple_add_mem(&buf, cur_faults, cur_faults_count); rp->cur_faults_count = cur_faults_count; - reg_faults_count = min(sizeof(reg_faults), sizeof(some_faults)); + reg_faults_count = MIN(sizeof(reg_faults), sizeof(some_faults)); memcpy(reg_faults, some_faults, reg_faults_count); net_buf_simple_add_mem(&buf, reg_faults, reg_faults_count); rp->reg_faults_count = reg_faults_count; diff --git a/tests/net/tcp/src/main.c b/tests/net/tcp/src/main.c index b31879cd78f..b3e8b3e12f5 100644 --- a/tests/net/tcp/src/main.c +++ b/tests/net/tcp/src/main.c @@ -1530,7 +1530,7 @@ static inline u32_t get_recv_wnd(struct net_tcp *tcp) * size is always the same. There are two configurables to * check though. */ - return min(NET_TCP_MAX_WIN, NET_TCP_BUF_MAX_LEN); + return MIN(NET_TCP_MAX_WIN, NET_TCP_BUF_MAX_LEN); } static bool test_tcp_seq_validity(void) diff --git a/tests/subsys/settings/fcb/src/settings_test_fcb.c b/tests/subsys/settings/fcb/src/settings_test_fcb.c index 50134c54953..1f6e9657c03 100644 --- a/tests/subsys/settings/fcb/src/settings_test_fcb.c +++ b/tests/subsys/settings/fcb/src/settings_test_fcb.c @@ -67,14 +67,14 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max) test_get_called = 1; if (argc == 1 && !strcmp(argv[0], "mybar")) { - val_len_max = min(val_len_max, sizeof(val8)); - memcpy(val, &val8, min(val_len_max, sizeof(val8))); + val_len_max = MIN(val_len_max, sizeof(val8)); + memcpy(val, &val8, MIN(val_len_max, sizeof(val8))); return val_len_max; } if (argc == 1 && !strcmp(argv[0], "mybar64")) { - val_len_max = min(val_len_max, sizeof(val64)); - memcpy(val, &val64, min(val_len_max, sizeof(val64))); + val_len_max = MIN(val_len_max, sizeof(val64)); + memcpy(val, &val64, MIN(val_len_max, sizeof(val64))); return val_len_max; } @@ -220,7 +220,7 @@ int c2_handle_get(int argc, char **argv, char *val, int val_len_max) len = val_len_max; } - len = min(strlen(valptr), len); + len = MIN(strlen(valptr), len); memcpy(val, valptr, len); return len; } @@ -268,8 +268,8 @@ int c2_handle_export(int (*cb)(const char *name, void *value, size_t val_len)) int c3_handle_get(int argc, char **argv, char *val, int val_len_max) { if (argc == 1 && !strcmp(argv[0], "v")) { - val_len_max = min(val_len_max, sizeof(val32)); - memcpy(val, &val32, min(val_len_max, sizeof(val32))); + val_len_max = MIN(val_len_max, sizeof(val32)); + memcpy(val, &val32, MIN(val_len_max, sizeof(val32))); return val_len_max; } return -EINVAL; diff --git a/tests/subsys/settings/nffs/src/settings_test_nffs.c b/tests/subsys/settings/nffs/src/settings_test_nffs.c index 8f84841b012..f7dda2a2943 100644 --- a/tests/subsys/settings/nffs/src/settings_test_nffs.c +++ b/tests/subsys/settings/nffs/src/settings_test_nffs.c @@ -44,20 +44,20 @@ int c1_handle_get(int argc, char **argv, char *val, int val_len_max) test_get_called = 1; if (argc == 1 && !strcmp(argv[0], "mybar")) { - val_len_max = min(val_len_max, sizeof(val8)); - memcpy(val, &val8, min(val_len_max, sizeof(val8))); + val_len_max = MIN(val_len_max, sizeof(val8)); + memcpy(val, &val8, MIN(val_len_max, sizeof(val8))); return val_len_max; } if (argc == 1 && !strcmp(argv[0], "mybar16")) { - val_len_max = min(val_len_max, sizeof(val16)); - memcpy(val, &val16, min(val_len_max, sizeof(val16))); + val_len_max = MIN(val_len_max, sizeof(val16)); + memcpy(val, &val16, MIN(val_len_max, sizeof(val16))); return val_len_max; } if (argc == 1 && !strcmp(argv[0], "mybar64")) { - val_len_max = min(val_len_max, sizeof(val64)); - memcpy(val, &val64, min(val_len_max, sizeof(val64))); + val_len_max = MIN(val_len_max, sizeof(val64)); + memcpy(val, &val64, MIN(val_len_max, sizeof(val64))); return val_len_max; } diff --git a/tests/subsys/settings/src/settings_enc.c b/tests/subsys/settings/src/settings_enc.c index d75c883f658..1f007730301 100644 --- a/tests/subsys/settings/src/settings_enc.c +++ b/tests/subsys/settings/src/settings_enc.c @@ -85,7 +85,7 @@ static int read_handle(void *ctx, off_t off, char *buf, size_t *len) return -EIO; } - r_len = min(sizeof(enc_buf) - off, *len); + r_len = MIN(sizeof(enc_buf) - off, *len); if (r_len <= 0) { *len = 0; return 0; @@ -114,7 +114,7 @@ void test_raw_read_iteration(u8_t rbs, size_t off, size_t len) zassert_equal(rc, 0, "Can't read the line %d.\n", rc); - expected = min((sizeof(enc_buf) - off), len); + expected = MIN((sizeof(enc_buf) - off), len); zassert_equal(expected, len_read, "Unexpected read size\n"); zassert_true(memcmp(&enc_buf[off], &read_buf[4], len_read) == 0,