]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sfc: replace min/max nesting with clamp()
authorXichao Zhao <zhao.xichao@vivo.com>
Tue, 12 Aug 2025 06:50:26 +0000 (14:50 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 15 Aug 2025 00:48:29 +0000 (17:48 -0700)
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>
drivers/net/ethernet/sfc/efx_channels.c
drivers/net/ethernet/sfc/falcon/efx.c
drivers/net/ethernet/sfc/siena/efx_channels.c

index 06b4f52713ef3f1c09e058e476597d86b67a7d6e..0f66324ed3510503142db0e5b770bd53eb2ef7f7 100644 (file)
@@ -216,8 +216,8 @@ static int efx_allocate_msix_channels(struct efx_nic *efx,
 
        if (efx_separate_tx_channels) {
                efx->n_tx_channels =
-                       min(max(n_channels / 2, 1U),
-                           efx->max_tx_channels);
+                       clamp(n_channels / 2, 1U,
+                             efx->max_tx_channels);
                efx->tx_channel_offset =
                        n_channels - efx->n_tx_channels;
                efx->n_rx_channels =
index b07f7e4e287775aebdf158574cdc19e685611d06..d19fbf8732ff832333c958c7fd291473b1ec82d2 100644 (file)
@@ -1394,9 +1394,8 @@ static int ef4_probe_interrupts(struct ef4_nic *efx)
                        if (n_channels > extra_channels)
                                n_channels -= extra_channels;
                        if (ef4_separate_tx_channels) {
-                               efx->n_tx_channels = min(max(n_channels / 2,
-                                                            1U),
-                                                        efx->max_tx_channels);
+                               efx->n_tx_channels = clamp(n_channels / 2, 1U,
+                                                          efx->max_tx_channels);
                                efx->n_rx_channels = max(n_channels -
                                                         efx->n_tx_channels,
                                                         1U);
index d120b3c83ac07d4313c387722434cd2377d8c992..703419866d18311db66b5b24fa5fab35de3e0267 100644 (file)
@@ -217,8 +217,8 @@ static int efx_allocate_msix_channels(struct efx_nic *efx,
 
        if (efx_siena_separate_tx_channels) {
                efx->n_tx_channels =
-                       min(max(n_channels / 2, 1U),
-                           efx->max_tx_channels);
+                       clamp(n_channels / 2, 1U,
+                             efx->max_tx_channels);
                efx->tx_channel_offset =
                        n_channels - efx->n_tx_channels;
                efx->n_rx_channels =