From: David Laight <David.Laight@ACULAB.COM>
To: 'Andrew Morton' <akpm@linux-foundation.org>,
Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Lu Hongfei <luhongfei@vivo.com>,
Uladzislau Rezki <urezki@gmail.com>,
Christoph Hellwig <hch@infradead.org>,
"open list:VMALLOC" <linux-mm@kvack.org>,
open list <linux-kernel@vger.kernel.org>,
"opensource.kernel@vivo.com" <opensource.kernel@vivo.com>
Subject: RE: [PATCH] mm/vmalloc: Replace the ternary conditional operator with min()
Date: Sat, 10 Jun 2023 22:29:21 +0000 [thread overview]
Message-ID: <84a2c079fcd44b8490eaf039cd20d2bf@AcuMS.aculab.com> (raw)
In-Reply-To: <20230610150809.babdc5a7919258f066c8637e@linux-foundation.org>
From: Andrew Morton <akpm@linux-foundation.org>
> Sent: 10 June 2023 23:08
>
> On Sat, 10 Jun 2023 22:06:35 +0100 Lorenzo Stoakes <lstoakes@gmail.com> wrote:
>
> > > > OK, as per the pedantic test bot, you'll need to change this to:-
> > > >
> > > > num = min_t(size_t, remains, PAGE_SIZE);
>
> PAGE_SIZE is a nuisance. It _usually_ creates the need for a
> cast:
>
> hp2:/usr/src/linux-6.4-rc4> grep -r "min(.*PAGE_SIZE" . | wc -l
> 117
> hp2:/usr/src/linux-6.4-rc4> grep -r "min_t(.*PAGE_SIZE" . | wc -l
> 279
>
> Perhaps it should always have been size_t.
>
> I suppose we could do
>
> #define PAGE_SIZE_T (size_t)PAGE_SIZE
>
> And use that where needed. Mainly because I like the name ;)
Or someone take my patches to relax the checks min() does a bit.
I think I last posted them in January.
Basically:
- unsigned v unsigned is always ok.
- signed v signed is always ok.
- unsigned v signed is ok provided one value is in [0..INT_MAX].
this can be allowed for compile-time constants.
The usual 'error case' is unsigned v signed when the values
are known (by the person writing the code) to be non-negative.
Doing '(x) + 0u + 0ul + 0ull' zero extends the value without
ever masking it or 'accidentally' converting a pointer.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-06-10 22:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-09 6:13 [PATCH] mm/vmalloc: Replace the ternary conditional operator with min() Lu Hongfei
2023-06-09 7:09 ` Lorenzo Stoakes
2023-06-09 8:48 ` Lorenzo Stoakes
2023-06-10 20:09 ` David Laight
2023-06-10 21:06 ` Lorenzo Stoakes
2023-06-10 22:08 ` Andrew Morton
2023-06-10 22:23 ` Lorenzo Stoakes
2023-06-10 22:29 ` David Laight [this message]
2023-06-10 22:18 ` David Laight
2023-06-10 22:35 ` Lorenzo Stoakes
2023-06-09 8:28 ` kernel test robot
2023-06-09 9:12 ` kernel test robot
2023-06-09 9:35 ` kernel test robot
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=84a2c079fcd44b8490eaf039cd20d2bf@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lstoakes@gmail.com \
--cc=luhongfei@vivo.com \
--cc=opensource.kernel@vivo.com \
--cc=urezki@gmail.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