From: David Laight <David.Laight@ACULAB.COM>
To: 'Marco Elver' <elver@google.com>,
Thorsten Blum <thorsten.blum@toblux.com>
Cc: "dvyukov@google.com" <dvyukov@google.com>,
"kasan-dev@googlegroups.com" <kasan-dev@googlegroups.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] kcsan: Use min() to fix Coccinelle warning
Date: Fri, 28 Jun 2024 14:51:19 +0000 [thread overview]
Message-ID: <1bebf2e8a8a64b4aa4097fd045993106@AcuMS.aculab.com> (raw)
In-Reply-To: <CANpmjNMHPt7UvcZBDf-rbxP=Jm4+Ews+oYeT4b2D_nxWoN9a+g@mail.gmail.com>
From: Marco Elver
> Sent: 24 June 2024 08:03
> >
> > Fixes the following Coccinelle/coccicheck warning reported by
> > minmax.cocci:
> >
> > WARNING opportunity for min()
> >
> > Use size_t instead of int for the result of min().
> >
> > Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
>
> Reviewed-by: Marco Elver <elver@google.com>
>
> Thanks for polishing (but see below). Please compile-test with
> CONFIG_KCSAN=y if you haven't.
>
> > ---
> > kernel/kcsan/debugfs.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
> > index 1d1d1b0e4248..11b891fe6f7a 100644
> > --- a/kernel/kcsan/debugfs.c
> > +++ b/kernel/kcsan/debugfs.c
> > @@ -225,7 +225,7 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
> > {
> > char kbuf[KSYM_NAME_LEN];
> > char *arg;
> > - int read_len = count < (sizeof(kbuf) - 1) ? count : (sizeof(kbuf) - 1);
> > + size_t read_len = min(count, (sizeof(kbuf) - 1));
>
> While we're here polishing things this could be:
>
> const size_t read_len = min(count, sizeof(kbuf) - 1);
>
> ( +const, remove redundant () )
Pretty much no one makes variables 'const', it mostly just makes the code harder to read.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-06-28 14:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-23 22:06 Thorsten Blum
2024-06-24 7:02 ` Marco Elver
2024-06-24 8:00 ` Thorsten Blum
2024-06-24 8:44 ` Marco Elver
2024-06-28 14:51 ` David Laight [this message]
2024-06-28 15:03 ` Marco Elver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1bebf2e8a8a64b4aa4097fd045993106@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=thorsten.blum@toblux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®