]> www.infradead.org Git - users/hch/misc.git/commitdiff
nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi)
authorLi Haoran <li.haoran7@zte.com.cn>
Thu, 20 Mar 2025 07:53:00 +0000 (15:53 +0800)
committerKeith Busch <kbusch@kernel.org>
Thu, 20 Mar 2025 23:53:56 +0000 (16:53 -0700)
This patch replaces max(a, min(b, c)) by clamp(val, lo, hi) in the nvme
driver. The clamp() macro explicitly expresses the intent of constraining
a value within bounds, improving code readability.

Signed-off-by: Li Haoran <li.haoran7@zte.com.cn>
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/target/nvmet.h

index 9f6110ac7c4abe5d5a14791cdd8210c2092e7804..33fac9151b5b14a60f877b9e15d965e77428f72b 100644 (file)
@@ -828,7 +828,7 @@ static inline u8 nvmet_cc_iocqes(u32 cc)
 /* Convert a 32-bit number to a 16-bit 0's based number */
 static inline __le16 to0based(u32 a)
 {
-       return cpu_to_le16(max(1U, min(1U << 16, a)) - 1);
+       return cpu_to_le16(clamp(a, 1U, 1U << 16) - 1);
 }
 
 static inline bool nvmet_ns_has_pi(struct nvmet_ns *ns)