Skip to contentSkip to conversation

inotify: fix minmax.cocci warnings

PATCH In review Julia Lawall 3 participants 4 messages Apr 6, 2021 – Apr 8, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 inotify: fix minmax.cocci warnings

From: kernel test robot <[email protected]>

Opportunity for min().

Generated by: scripts/coccinelle/misc/minmax.cocci

Fixes 8636e3295ce3 ("coccinelle: misc: add minmax script")
CC Denis Efremov <[email protected]>

---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux.git for-5.12
head:   cbc8ed0b4f7eeb782c153ec88d6d20bc0f0ca3a7
commit: 8636e3295ce33515c50ef728f0ff3800d97f9f44 [1/4] coccinelle: misc: add minmax script

:::::: branch date: 2 days ago
:::::: commit date: 2 weeks ago

 inotify_user.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/inotify/inotify_user.c +1 -1
@@ -382,7 +382,7 @@ static int inotify_add_to_idr(struct idr
 
 	spin_unlock(idr_lock);
 	idr_preload_end();
-	return ret < 0 ? ret : 0;
+	return min(ret, 0);
 }
 
 static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group,
maintainer
#1 lore raw
Quoted 11 lines · Julia Lawall

From: kernel test robot <[email protected]>

Opportunity for min().

Generated by: scripts/coccinelle/misc/minmax.cocci

Fixes 8636e3295ce3 ("coccinelle: misc: add minmax script")
CC Denis Efremov <[email protected]>

...

fs/notify/inotify/inotify_user.c static int inotify_add_to_idr(struct idr · line 386

Quoted 9 lines
fs/notify/inotify/inotify_user.c +1 -1
@@ -382,7 +382,7 @@ static int inotify_add_to_idr(struct idr
 
 	spin_unlock(idr_lock);
 	idr_preload_end();
-	return ret < 0 ? ret : 0;
+	return min(ret, 0);
 }

Honestly, while previous expression is a standard idiom for "if 'ret' holds an error, return it", the new expression is harder to understand for me. So I prefer to keep things as they are in this particular case...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 17 lines · Jan Kara
Quoted 11 lines · Julia Lawall

From: kernel test robot <[email protected]>

Opportunity for min().

Generated by: scripts/coccinelle/misc/minmax.cocci

Fixes 8636e3295ce3 ("coccinelle: misc: add minmax script")
CC Denis Efremov <[email protected]>

...

Quoted 4 lines
fs/notify/inotify/inotify_user.c +0 -0
@@ -382,7 +382,7 @@ static int inotify_add_to_idr(struct idr
 
Quoted 9 lines

fs/notify/inotify/inotify_user.c static int inotify_add_to_idr(struct idr · line 386

Quoted 5 lines
fs/notify/inotify/inotify_user.c +1 -1
 	spin_unlock(idr_lock);
 	idr_preload_end();
-	return ret < 0 ? ret : 0;
+	return min(ret, 0);
 }

Honestly, while previous expression is a standard idiom for "if 'ret' holds an error, return it", the new expression is harder to understand for me. So I prefer to keep things as they are in this particular case...

OK, I had doubts about it as well, but I forwarded it because I found them equally obscure...

Denis, maybe the semantic patch should be updated to avoid this case.

julia

#3 lore raw
Quoted 31 lines · Julia Lawall
Quoted 17 lines · Jan Kara
Quoted 11 lines · Julia Lawall

From: kernel test robot <[email protected]>

Opportunity for min().

Generated by: scripts/coccinelle/misc/minmax.cocci

Fixes 8636e3295ce3 ("coccinelle: misc: add minmax script")
CC Denis Efremov <[email protected]>

...

Quoted 4 lines
fs/notify/inotify/inotify_user.c +0 -0
@@ -382,7 +382,7 @@ static int inotify_add_to_idr(struct idr
 
Quoted 9 lines

fs/notify/inotify/inotify_user.c static int inotify_add_to_idr(struct idr · line 386

Quoted 5 lines
fs/notify/inotify/inotify_user.c +1 -1
 	spin_unlock(idr_lock);
 	idr_preload_end();
-	return ret < 0 ? ret : 0;
+	return min(ret, 0);
 }

Honestly, while previous expression is a standard idiom for "if 'ret' holds an error, return it", the new expression is harder to understand for me. So I prefer to keep things as they are in this particular case...

Quoted 4 lines

OK, I had doubts about it as well, but I forwarded it because I found them equally obscure...

Denis, maybe the semantic patch should be updated to avoid this case.

No problem, I'll send an update.

Thanks,
Denis