Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sfc: replace min/max nesting with clamp()

The clamp() macro explicitly expresses the intent of constraining
a value within bounds.Therefore, replacing min(max(a, b), c) with
clamp(val, lo, hi) can improve code readability.

Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
Reviewed-by: Joe Damato <joe@dama.to>
Reviewed-by: Edward Cree <ecree.xilinx@gmail.com>
Link: https://patch.msgid.link/20250812065026.620115-1-zhao.xichao@vivo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Xichao Zhao and committed by
Jakub Kicinski
6398d8a8 6a18b85c

+6 -7
+2 -2
drivers/net/ethernet/sfc/efx_channels.c
··· 216 216 217 217 if (efx_separate_tx_channels) { 218 218 efx->n_tx_channels = 219 - min(max(n_channels / 2, 1U), 220 - efx->max_tx_channels); 219 + clamp(n_channels / 2, 1U, 220 + efx->max_tx_channels); 221 221 efx->tx_channel_offset = 222 222 n_channels - efx->n_tx_channels; 223 223 efx->n_rx_channels =
+2 -3
drivers/net/ethernet/sfc/falcon/efx.c
··· 1394 1394 if (n_channels > extra_channels) 1395 1395 n_channels -= extra_channels; 1396 1396 if (ef4_separate_tx_channels) { 1397 - efx->n_tx_channels = min(max(n_channels / 2, 1398 - 1U), 1399 - efx->max_tx_channels); 1397 + efx->n_tx_channels = clamp(n_channels / 2, 1U, 1398 + efx->max_tx_channels); 1400 1399 efx->n_rx_channels = max(n_channels - 1401 1400 efx->n_tx_channels, 1402 1401 1U);
+2 -2
drivers/net/ethernet/sfc/siena/efx_channels.c
··· 217 217 218 218 if (efx_siena_separate_tx_channels) { 219 219 efx->n_tx_channels = 220 - min(max(n_channels / 2, 1U), 221 - efx->max_tx_channels); 220 + clamp(n_channels / 2, 1U, 221 + efx->max_tx_channels); 222 222 efx->tx_channel_offset = 223 223 n_channels - efx->n_tx_channels; 224 224 efx->n_rx_channels =