[PATCH] mtip32xx: replace ternary operator with min_t()

Jiangshan Yi posted 1 patch 3 years, 9 months ago
drivers/block/mtip32xx/mtip32xx.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] mtip32xx: replace ternary operator with min_t()
Posted by Jiangshan Yi 3 years, 9 months ago
From: Jiangshan Yi <yijiangshan@kylinos.cn>

Fix the following coccicheck warning:

drivers/block/mtip32xx/mtip32xx.c:2264: WARNING opportunity for min().
drivers/block/mtip32xx/mtip32xx.c:2328: WARNING opportunity for min().
drivers/block/mtip32xx/mtip32xx.c:2357: WARNING opportunity for min().

min_t() macro is defined in include/linux/minmax.h. It avoids
multiple evaluations of the arguments when non-constant and performs
strict type-checking.

Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
 drivers/block/mtip32xx/mtip32xx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 27386a572ba4..ef6bc68f86a3 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2261,7 +2261,7 @@ static ssize_t mtip_hw_read_device_status(struct file *f, char __user *ubuf,
 
 	size += show_device_status(NULL, buf);
 
-	*offset = size <= len ? size : len;
+	*offset = min_t(size_t, size, len);
 	size = copy_to_user(ubuf, buf, *offset);
 	if (size)
 		rv = -EFAULT;
@@ -2325,7 +2325,7 @@ static ssize_t mtip_hw_read_registers(struct file *f, char __user *ubuf,
 	}
 	size += sprintf(&buf[size], "]\n");
 
-	*offset = size <= len ? size : len;
+	*offset = min_t(size_t, size, len);
 	size = copy_to_user(ubuf, buf, *offset);
 	if (size)
 		rv = -EFAULT;
@@ -2354,7 +2354,7 @@ static ssize_t mtip_hw_read_flags(struct file *f, char __user *ubuf,
 	size += sprintf(&buf[size], "Flag-dd   : [ %08lX ]\n",
 							dd->dd_flag);
 
-	*offset = size <= len ? size : len;
+	*offset = min_t(size_t, size, len);
 	size = copy_to_user(ubuf, buf, *offset);
 	if (size)
 		rv = -EFAULT;
-- 
2.25.1
Re: [PATCH] mtip32xx: replace ternary operator with min_t()
Posted by Jens Axboe 3 years, 9 months ago
On Tue, 12 Jul 2022 17:43:50 +0800, Jiangshan Yi wrote:
> From: Jiangshan Yi <yijiangshan@kylinos.cn>
> 
> Fix the following coccicheck warning:
> 
> drivers/block/mtip32xx/mtip32xx.c:2264: WARNING opportunity for min().
> drivers/block/mtip32xx/mtip32xx.c:2328: WARNING opportunity for min().
> drivers/block/mtip32xx/mtip32xx.c:2357: WARNING opportunity for min().
> 
> [...]

Applied, thanks!

[1/1] mtip32xx: replace ternary operator with min_t()
      (no commit info)

Best regards,
-- 
Jens Axboe