From: Michal Nazarewicz <mina86@mina86.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Fengguang Wu <fengguang.wu@intel.com>,
kbuild-all@01.org, Johannes Weiner <hannes@cmpxchg.org>,
Hagen Paul Pfeifer <hagen@jauu.net>,
Linux Memory Management List <linux-mm@kvack.org>
Subject: Re: [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min'
Date: Fri, 20 Jun 2014 23:16:49 +0200 [thread overview]
Message-ID: <xa1t7g4buvr2.fsf@mina86.com> (raw)
In-Reply-To: <20140620133954.3cc60a53f60edac2d8001b63@linux-foundation.org>
On Fri, Jun 20 2014, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Fri, 20 Jun 2014 17:19:55 +0200 Michal Nazarewicz <mina86@mina86.com> wrote:
>
>> On Fri, Jun 20 2014, Fengguang Wu <fengguang.wu@intel.com> wrote:
>> >>> include/linux/kernel.h:744:28: note: in expansion of macro 'min'
>> > #define clamp(val, lo, hi) min(max(val, lo), hi)
>> > ^
>> >>> drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1901:11: note: in expansion of macro 'clamp'
>> > bytes = clamp(bytes, (u16)1024, (u16)I40E_MAX_AQ_BUF_SIZE);
>> > ^
>>
>> The obvious fix:
>>
>> ----------- >8 --------------------------------------------------------------
>> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
>> index 44649e0..149864b 100644
>> --- a/include/linux/kernel.h
>> +++ b/include/linux/kernel.h
>> @@ -719,8 +719,8 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
>> (void) (&_max1 == &_max2); \
>> _max1 > _max2 ? _max1 : _max2; })
>>
>> -#define min3(x, y, z) min(min(x, y), z)
>> -#define max3(x, y, z) max(max(x, y), z)
>> +#define min3(x, y, z) min((typeof(x))min(x, y), z)
>> +#define max3(x, y, z) max((typeof(x))max(x, y), z)
>
> I don't get it. All the types are u16 so we should be good.
>
> What is the return type of
>
> _max1 > _max2 ? _max1 : _max2;
int… Since C promotes it. (Or unsigned, I never remember, but I think
int if the possible values fit in signed int).
> when both _max1 and _max2 are u16? Something other than u16 apparently
> - I never knew that.
>
> Maybe we should be fixing min() and max()?
This is also an option. It would make min() and max() behave more like
a function which takes arguments of type T and returns value of type T.
Currently it behaves as a C operation which undergoes all the promotion
rules other arithmetic operations undergo (i.e. all types smaller than
int get promoted to int). I don't have opinion either way.
> --- a/include/linux/kernel.h~a
> +++ a/include/linux/kernel.h
> @@ -711,13 +711,13 @@ static inline void ftrace_dump(enum ftra
> typeof(x) _min1 = (x); \
> typeof(y) _min2 = (y); \
> (void) (&_min1 == &_min2); \
> - _min1 < _min2 ? _min1 : _min2; })
> + (typeof(x))(_min1 < _min2 ? _min1 : _min2); })
>
> #define max(x, y) ({ \
> typeof(x) _max1 = (x); \
> typeof(y) _max2 = (y); \
> (void) (&_max1 == &_max2); \
> - _max1 > _max2 ? _max1 : _max2; })
> + (typeof(x))(_max1 > _max2 ? _max1 : _max2); })
>
> #define min3(x, y, z) min(min(x, y), z)
> #define max3(x, y, z) max(max(x, y), z)
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2014-06-20 21:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <53a3c359.yUYVC7fzjYpZLyLq%fengguang.wu@intel.com>
2014-06-20 5:52 ` Fengguang Wu
2014-06-20 15:19 ` Michal Nazarewicz
2014-06-20 20:39 ` Andrew Morton
2014-06-20 21:16 ` Michal Nazarewicz [this message]
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=xa1t7g4buvr2.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=akpm@linux-foundation.org \
--cc=fengguang.wu@intel.com \
--cc=hagen@jauu.net \
--cc=hannes@cmpxchg.org \
--cc=kbuild-all@01.org \
--cc=linux-mm@kvack.org \
/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