]> www.infradead.org Git - users/hch/misc.git/commitdiff
ext4: replace min/max nesting with clamp()
authorXichao Zhao <zhao.xichao@vivo.com>
Mon, 18 Aug 2025 07:28:59 +0000 (15:28 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 25 Sep 2025 18:35:21 +0000 (14:35 -0400)
The clamp() macro explicitly expresses the intent of constraining a value
within bounds.Therefore, replacing max(min(a,b),c) with clamp(val, lo, hi)
can improve code readability.

Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mmp.c

index 51661570cf3b8df7fbcae6e8d13a43acfac83d1d..ab1ff51302fbd062ba8543fcdd3809eba9b4bc3c 100644 (file)
@@ -231,9 +231,9 @@ static int kmmpd(void *data)
                 * Adjust the mmp_check_interval depending on how much time
                 * it took for the MMP block to be written.
                 */
-               mmp_check_interval = max(min(EXT4_MMP_CHECK_MULT * diff / HZ,
-                                            EXT4_MMP_MAX_CHECK_INTERVAL),
-                                        EXT4_MMP_MIN_CHECK_INTERVAL);
+               mmp_check_interval = clamp(EXT4_MMP_CHECK_MULT * diff / HZ,
+                                          EXT4_MMP_MIN_CHECK_INTERVAL,
+                                          EXT4_MMP_MAX_CHECK_INTERVAL);
                mmp->mmp_check_interval = cpu_to_le16(mmp_check_interval);
        }