[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250320155300346qoM6J3iYhvw5QD7AfBiqo@zte.com.cn>
Date: Thu, 20 Mar 2025 15:53:00 +0800 (CST)
From: <shao.mingyin@....com.cn>
To: <hch@....de>
Cc: <sagi@...mberg.me>, <kch@...dia.com>, <linux-nvme@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>, <yang.tao172@....com.cn>,
<yang.yang29@....com.cn>, <xu.xin16@....com.cn>
Subject: [PATCH v2] nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi)
From: Li Haoran <li.haoran7@....com.cn>
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@....com.cn>
Signed-off-by: Shao Mingyin <shao.mingyin@....com.cn>
---
v1->v2
Swap the arguments into a sane order.
drivers/nvme/target/nvmet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index fcf4f460dc9a..7b8a1483da2d 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -819,7 +819,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)
--
2.25.1
Powered by blists - more mailing lists