mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi)
@ 2025-03-20  7:53 shao.mingyin
  2025-03-20 20:14 ` Keith Busch
  0 siblings, 1 reply; 2+ messages in thread
From: shao.mingyin @ 2025-03-20  7:53 UTC (permalink / raw)
  To: hch
  Cc: sagi, kch, linux-nvme, linux-kernel, yang.tao172, yang.yang29, xu.xin16

From: Li Haoran <li.haoran7@zte.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@zte.com.cn>
Signed-off-by: Shao Mingyin <shao.mingyin@zte.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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi)
  2025-03-20  7:53 [PATCH v2] nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi) shao.mingyin
@ 2025-03-20 20:14 ` Keith Busch
  0 siblings, 0 replies; 2+ messages in thread
From: Keith Busch @ 2025-03-20 20:14 UTC (permalink / raw)
  To: shao.mingyin
  Cc: hch, sagi, kch, linux-nvme, linux-kernel, yang.tao172,
	yang.yang29, xu.xin16

On Thu, Mar 20, 2025 at 03:53:00PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Li Haoran <li.haoran7@zte.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.

Thanks, applied to nvme-6.15.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-20 20:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20  7:53 [PATCH v2] nvmet: replace max(a, min(b, c)) by clamp(val, lo, hi) shao.mingyin
2025-03-20 20:14 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®