Message ID | alpine.DEB.2.22.394.2104062246500.19097@hadrien (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | inotify: fix minmax.cocci warnings | expand |
On Tue 06-04-21 22:49:26, Julia Lawall wrote: > From: kernel test robot <lkp@intel.com> > > Opportunity for min(). > > Generated by: scripts/coccinelle/misc/minmax.cocci > > Fixes: 8636e3295ce3 ("coccinelle: misc: add minmax script") > CC: Denis Efremov <efremov@linux.com> > Reported-by: kernel test robot <lkp@intel.com> > Signed-off-by: kernel test robot <lkp@intel.com> > Signed-off-by: Julia Lawall <julia.lawall@inria.fr> ... > --- a/fs/notify/inotify/inotify_user.c > +++ b/fs/notify/inotify/inotify_user.c > @@ -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
On Wed, 7 Apr 2021, Jan Kara wrote: > On Tue 06-04-21 22:49:26, Julia Lawall wrote: > > From: kernel test robot <lkp@intel.com> > > > > Opportunity for min(). > > > > Generated by: scripts/coccinelle/misc/minmax.cocci > > > > Fixes: 8636e3295ce3 ("coccinelle: misc: add minmax script") > > CC: Denis Efremov <efremov@linux.com> > > Reported-by: kernel test robot <lkp@intel.com> > > Signed-off-by: kernel test robot <lkp@intel.com> > > Signed-off-by: Julia Lawall <julia.lawall@inria.fr> > ... > > --- a/fs/notify/inotify/inotify_user.c > > +++ b/fs/notify/inotify/inotify_user.c > > @@ -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... 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
On 4/7/21 8:02 PM, Julia Lawall wrote: > > > On Wed, 7 Apr 2021, Jan Kara wrote: > >> On Tue 06-04-21 22:49:26, Julia Lawall wrote: >>> From: kernel test robot <lkp@intel.com> >>> >>> Opportunity for min(). >>> >>> Generated by: scripts/coccinelle/misc/minmax.cocci >>> >>> Fixes: 8636e3295ce3 ("coccinelle: misc: add minmax script") >>> CC: Denis Efremov <efremov@linux.com> >>> Reported-by: kernel test robot <lkp@intel.com> >>> Signed-off-by: kernel test robot <lkp@intel.com> >>> Signed-off-by: Julia Lawall <julia.lawall@inria.fr> >> ... >>> --- a/fs/notify/inotify/inotify_user.c >>> +++ b/fs/notify/inotify/inotify_user.c >>> @@ -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... > > 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
--- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -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,