diff mbox series

fs/ext2: replace ternary operator with min_t()

Message ID 20220714063318.1777139-1-13667453960@163.com
State Not Applicable
Headers show
Series fs/ext2: replace ternary operator with min_t() | expand

Commit Message

Jiangshan Yi July 14, 2022, 6:33 a.m. UTC
From: Jiangshan Yi <yijiangshan@kylinos.cn>

Fix the following coccicheck warning:

fs/ext2/super.c:1494: WARNING opportunity for min().
fs/ext2/super.c:1533: 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>
---
 fs/ext2/super.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Jan Kara July 14, 2022, 10:04 a.m. UTC | #1
On Thu 14-07-22 14:33:18, Jiangshan Yi wrote:
> From: Jiangshan Yi <yijiangshan@kylinos.cn>
> 
> Fix the following coccicheck warning:
> 
> fs/ext2/super.c:1494: WARNING opportunity for min().
> fs/ext2/super.c:1533: 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>

Yeah, looks like a good cleanup. Merged to my tree. Thanks!

								Honza

> ---
>  fs/ext2/super.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext2/super.c b/fs/ext2/super.c
> index f6a19f6d9f6d..300f2f0cf566 100644
> --- a/fs/ext2/super.c
> +++ b/fs/ext2/super.c
> @@ -1490,8 +1490,7 @@ static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
>  		len = i_size-off;
>  	toread = len;
>  	while (toread > 0) {
> -		tocopy = sb->s_blocksize - offset < toread ?
> -				sb->s_blocksize - offset : toread;
> +		tocopy = min_t(size_t, sb->s_blocksize - offset, toread);
>  
>  		tmp_bh.b_state = 0;
>  		tmp_bh.b_size = sb->s_blocksize;
> @@ -1529,8 +1528,7 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
>  	struct buffer_head *bh;
>  
>  	while (towrite > 0) {
> -		tocopy = sb->s_blocksize - offset < towrite ?
> -				sb->s_blocksize - offset : towrite;
> +		tocopy = min_t(size_t, sb->s_blocksize - offset, towrite);
>  
>  		tmp_bh.b_state = 0;
>  		tmp_bh.b_size = sb->s_blocksize;
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index f6a19f6d9f6d..300f2f0cf566 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1490,8 +1490,7 @@  static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
 		len = i_size-off;
 	toread = len;
 	while (toread > 0) {
-		tocopy = sb->s_blocksize - offset < toread ?
-				sb->s_blocksize - offset : toread;
+		tocopy = min_t(size_t, sb->s_blocksize - offset, toread);
 
 		tmp_bh.b_state = 0;
 		tmp_bh.b_size = sb->s_blocksize;
@@ -1529,8 +1528,7 @@  static ssize_t ext2_quota_write(struct super_block *sb, int type,
 	struct buffer_head *bh;
 
 	while (towrite > 0) {
-		tocopy = sb->s_blocksize - offset < towrite ?
-				sb->s_blocksize - offset : towrite;
+		tocopy = min_t(size_t, sb->s_blocksize - offset, towrite);
 
 		tmp_bh.b_state = 0;
 		tmp_bh.b_size = sb->s_blocksize;