Thread (2 messages) 2 messages, 2 authors, 2025-06-20

[PATCH v1] HID: mcp-2221: Replace manual comparison with min() macro

From: Yu Jiaoliang <hidden>
Date: 2025-06-19 02:48:08
Also in: linux-i2c, lkml
Subsystem: hid core layer, mcp2221a microchip usb-hid to i2c bridge driver, the rest · Maintainers: Jiri Kosina, Benjamin Tissoires, Rishi Gupta, Linus Torvalds

This improves code readability by using the standard
kernel macro for minimal value selection while maintaining identical
functionality.

Signed-off-by: Yu Jiaoliang <redacted>
---
 drivers/hid/hid-mcp2221.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
index 6c0ac14f11a6..dca61fb1ac08 100644
--- a/drivers/hid/hid-mcp2221.c
+++ b/drivers/hid/hid-mcp2221.c
@@ -18,6 +18,7 @@
 #include <linux/i2c.h>
 #include <linux/gpio/driver.h>
 #include <linux/iio/iio.h>
+#include <linux/minmax.h>
 #include "hid-ids.h"
 
 /* Commands codes in a raw output report */
@@ -241,10 +242,7 @@ static int mcp_i2c_write(struct mcp2221 *mcp,
 
 	idx = 0;
 	sent  = 0;
-	if (msg->len < 60)
-		len = msg->len;
-	else
-		len = 60;
+	len = min(msg->len, 60);
 
 	do {
 		mcp->txbuf[0] = type;
@@ -271,10 +269,7 @@ static int mcp_i2c_write(struct mcp2221 *mcp,
 			break;
 
 		idx = idx + len;
-		if ((msg->len - sent) < 60)
-			len = msg->len - sent;
-		else
-			len = 60;
+		len = min(msg->len - sent, 60);
 
 		/*
 		 * Testing shows delay is needed between successive writes
-- 
2.34.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help