linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min'
       [not found] <53a3c359.yUYVC7fzjYpZLyLq%fengguang.wu@intel.com>
@ 2014-06-20  5:52 ` Fengguang Wu
  2014-06-20 15:19   ` Michal Nazarewicz
  0 siblings, 1 reply; 4+ messages in thread
From: Fengguang Wu @ 2014-06-20  5:52 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: kbuild-all, Johannes Weiner, Hagen Paul Pfeifer, Andrew Morton,
	Linux Memory Management List

tree:   git://git.cmpxchg.org/linux-mmotm.git master
head:   df25ba7db0775d87018e2cd92f26b9b087093840
commit: 99c369839f847d2cc4b8e759a9c57c925592efa2 [141/230] include/linux/kernel.h: rewrite min3, max3 and clamp using min and max
config: make ARCH=x86_64 allmodconfig

All warnings:

   drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1901:25: sparse: incompatible types in comparison expression (different type sizes)
   In file included from arch/x86/include/asm/percpu.h:44:0,
                    from arch/x86/include/asm/preempt.h:5,
                    from include/linux/preempt.h:18,
                    from include/linux/spinlock.h:50,
                    from include/linux/wait.h:8,
                    from include/linux/fs.h:6,
                    from drivers/net/ethernet/intel/i40e/i40e_debugfs.c:29:
   drivers/net/ethernet/intel/i40e/i40e_debugfs.c: In function 'i40e_dbg_command_write':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
>> 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);
              ^
--
   drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:269:21: sparse: incompatible types in comparison expression (different type sizes)
   In file included from include/linux/sched.h:17:0,
                    from drivers/net/wireless/rtlwifi/rtl8723ae/../wifi.h:35,
                    from drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:31:
   drivers/net/wireless/rtlwifi/rtl8723ae/dm.c: In function 'rtl92c_dm_ctrl_initgain_by_fa':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
>> include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
>> drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:269:14: note: in expansion of macro 'clamp'
     value_igi = clamp(value_igi, (u8)DM_DIG_FA_LOWER, (u8)DM_DIG_FA_UPPER);
                 ^
--
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17:    expected unsigned int [unsigned] [usertype] d32
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17:    got restricted __be32 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13:    expected unsigned short [unsigned] dat
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13:    got restricted __be16 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13:    expected unsigned short [unsigned] [addressable] dat
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13:    got restricted __be16 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:437:23: sparse: incompatible types in comparison expression (different type sizes)
   drivers/staging/iio/impedance-analyzer/ad5933.c:451:23: sparse: incompatible types in comparison expression (different type sizes)
   In file included from include/linux/interrupt.h:5:0,
                    from drivers/staging/iio/impedance-analyzer/ad5933.c:9:
   drivers/staging/iio/impedance-analyzer/ad5933.c: In function 'ad5933_store':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
>> include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
>> drivers/staging/iio/impedance-analyzer/ad5933.c:437:9: note: in expansion of macro 'clamp'
      val = clamp(val, (u16)0, (u16)0x7FF);
            ^
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
>> include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
>> drivers/staging/iio/impedance-analyzer/ad5933.c:451:9: note: in expansion of macro 'clamp'
      val = clamp(val, (u16)0, (u16)511);
            ^

sparse warnings: (new ones prefixed by >>)

>> drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1901:25: sparse: incompatible types in comparison expression (different type sizes)
   In file included from arch/x86/include/asm/percpu.h:44:0,
                    from arch/x86/include/asm/preempt.h:5,
                    from include/linux/preempt.h:18,
                    from include/linux/spinlock.h:50,
                    from include/linux/wait.h:8,
                    from include/linux/fs.h:6,
                    from drivers/net/ethernet/intel/i40e/i40e_debugfs.c:29:
   drivers/net/ethernet/intel/i40e/i40e_debugfs.c: In function 'i40e_dbg_command_write':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
   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);
              ^
--
>> drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:269:21: sparse: incompatible types in comparison expression (different type sizes)
   In file included from include/linux/sched.h:17:0,
                    from drivers/net/wireless/rtlwifi/rtl8723ae/../wifi.h:35,
                    from drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:31:
   drivers/net/wireless/rtlwifi/rtl8723ae/dm.c: In function 'rtl92c_dm_ctrl_initgain_by_fa':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
   include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
   drivers/net/wireless/rtlwifi/rtl8723ae/dm.c:269:14: note: in expansion of macro 'clamp'
     value_igi = clamp(value_igi, (u8)DM_DIG_FA_LOWER, (u8)DM_DIG_FA_UPPER);
                 ^
--
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17:    expected unsigned int [unsigned] [usertype] d32
   drivers/staging/iio/impedance-analyzer/ad5933.c:241:17:    got restricted __be32 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13:    expected unsigned short [unsigned] dat
   drivers/staging/iio/impedance-analyzer/ad5933.c:263:13:    got restricted __be16 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13: sparse: incorrect type in assignment (different base types)
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13:    expected unsigned short [unsigned] [addressable] dat
   drivers/staging/iio/impedance-analyzer/ad5933.c:271:13:    got restricted __be16 [usertype] <noident>
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
   drivers/staging/iio/impedance-analyzer/ad5933.c:310:19: sparse: cast to restricted __be32
>> drivers/staging/iio/impedance-analyzer/ad5933.c:437:23: sparse: incompatible types in comparison expression (different type sizes)
>> drivers/staging/iio/impedance-analyzer/ad5933.c:451:23: sparse: incompatible types in comparison expression (different type sizes)
   In file included from include/linux/interrupt.h:5:0,
                    from drivers/staging/iio/impedance-analyzer/ad5933.c:9:
   drivers/staging/iio/impedance-analyzer/ad5933.c: In function 'ad5933_store':
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
   include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
   drivers/staging/iio/impedance-analyzer/ad5933.c:437:9: note: in expansion of macro 'clamp'
      val = clamp(val, (u16)0, (u16)0x7FF);
            ^
   include/linux/kernel.h:713:17: warning: comparison of distinct pointer types lacks a cast [enabled by default]
     (void) (&_min1 == &_min2);  \
                    ^
   include/linux/kernel.h:744:28: note: in expansion of macro 'min'
    #define clamp(val, lo, hi) min(max(val, lo), hi)
                               ^
   drivers/staging/iio/impedance-analyzer/ad5933.c:451:9: note: in expansion of macro 'clamp'
      val = clamp(val, (u16)0, (u16)511);
            ^

vim +/min +744 include/linux/kernel.h

^1da177e Linus Torvalds     2005-04-16  707   * strict type-checking.. See the
^1da177e Linus Torvalds     2005-04-16  708   * "unnecessary" pointer comparison.
^1da177e Linus Torvalds     2005-04-16  709   */
bdf4bbaa Harvey Harrison    2008-04-30  710  #define min(x, y) ({				\
bdf4bbaa Harvey Harrison    2008-04-30  711  	typeof(x) _min1 = (x);			\
bdf4bbaa Harvey Harrison    2008-04-30  712  	typeof(y) _min2 = (y);			\
bdf4bbaa Harvey Harrison    2008-04-30 @713  	(void) (&_min1 == &_min2);		\
bdf4bbaa Harvey Harrison    2008-04-30  714  	_min1 < _min2 ? _min1 : _min2; })
bdf4bbaa Harvey Harrison    2008-04-30  715  
bdf4bbaa Harvey Harrison    2008-04-30  716  #define max(x, y) ({				\
bdf4bbaa Harvey Harrison    2008-04-30  717  	typeof(x) _max1 = (x);			\
bdf4bbaa Harvey Harrison    2008-04-30  718  	typeof(y) _max2 = (y);			\
bdf4bbaa Harvey Harrison    2008-04-30  719  	(void) (&_max1 == &_max2);		\
bdf4bbaa Harvey Harrison    2008-04-30  720  	_max1 > _max2 ? _max1 : _max2; })
bdf4bbaa Harvey Harrison    2008-04-30  721  
99c36983 Michal Nazarewicz  2014-06-20  722  #define min3(x, y, z) min(min(x, y), z)
99c36983 Michal Nazarewicz  2014-06-20  723  #define max3(x, y, z) max(max(x, y), z)
f27c85c5 Hagen Paul Pfeifer 2010-10-26  724  
bdf4bbaa Harvey Harrison    2008-04-30  725  /**
c8bf1336 Martin K. Petersen 2010-09-10  726   * min_not_zero - return the minimum that is _not_ zero, unless both are zero
c8bf1336 Martin K. Petersen 2010-09-10  727   * @x: value1
c8bf1336 Martin K. Petersen 2010-09-10  728   * @y: value2
c8bf1336 Martin K. Petersen 2010-09-10  729   */
c8bf1336 Martin K. Petersen 2010-09-10  730  #define min_not_zero(x, y) ({			\
c8bf1336 Martin K. Petersen 2010-09-10  731  	typeof(x) __x = (x);			\
c8bf1336 Martin K. Petersen 2010-09-10  732  	typeof(y) __y = (y);			\
c8bf1336 Martin K. Petersen 2010-09-10  733  	__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
c8bf1336 Martin K. Petersen 2010-09-10  734  
c8bf1336 Martin K. Petersen 2010-09-10  735  /**
bdf4bbaa Harvey Harrison    2008-04-30  736   * clamp - return a value clamped to a given range with strict typechecking
bdf4bbaa Harvey Harrison    2008-04-30  737   * @val: current value
99c36983 Michal Nazarewicz  2014-06-20  738   * @lo: lowest allowable value
99c36983 Michal Nazarewicz  2014-06-20  739   * @hi: highest allowable value
bdf4bbaa Harvey Harrison    2008-04-30  740   *
bdf4bbaa Harvey Harrison    2008-04-30  741   * This macro does strict typechecking of min/max to make sure they are of the
bdf4bbaa Harvey Harrison    2008-04-30  742   * same type as val.  See the unnecessary pointer comparisons.
bdf4bbaa Harvey Harrison    2008-04-30  743   */
99c36983 Michal Nazarewicz  2014-06-20 @744  #define clamp(val, lo, hi) min(max(val, lo), hi)
^1da177e Linus Torvalds     2005-04-16  745  
^1da177e Linus Torvalds     2005-04-16  746  /*
^1da177e Linus Torvalds     2005-04-16  747   * ..and if you can't take the strict

---
0-DAY kernel build testing backend              Open Source Technology Center
http://lists.01.org/mailman/listinfo/kbuild                 Intel Corporation

--
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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min'
  2014-06-20  5:52 ` [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min' Fengguang Wu
@ 2014-06-20 15:19   ` Michal Nazarewicz
  2014-06-20 20:39     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Nazarewicz @ 2014-06-20 15:19 UTC (permalink / raw)
  To: Fengguang Wu
  Cc: kbuild-all, Johannes Weiner, Hagen Paul Pfeifer, Andrew Morton,
	Linux Memory Management List

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)
 
 /**
  * min_not_zero - return the minimum that is _not_ zero, unless both are zero
@@ -741,7 +741,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  * This macro does strict typechecking of min/max to make sure they are of the
  * same type as val.  See the unnecessary pointer comparisons.
  */
-#define clamp(val, lo, hi) min(max(val, lo), hi)
+#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
 
 /*
  * ..and if you can't take the strict
----------- >8 --------------------------------------------------------------

increases size of the kernel:

-rwx------ 1 mpn eng 437026785 Jun 20 15:45 vmlinux.before
-rwx------ 1 mpn eng 437026881 Jun 20 15:30 vmlinux.after

even though it's still slightly smaller than w/o the patch all together:

-rwx------ 1 mpn eng 437027411 Jun 20 16:04 vmlinux.before.before

-- 
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>

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min'
  2014-06-20 15:19   ` Michal Nazarewicz
@ 2014-06-20 20:39     ` Andrew Morton
  2014-06-20 21:16       ` Michal Nazarewicz
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2014-06-20 20:39 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: Fengguang Wu, kbuild-all, Johannes Weiner, Hagen Paul Pfeifer,
	Linux Memory Management List

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;

when both _max1 and _max2 are u16?  Something other than u16 apparently
- I never knew that.

Maybe we should be fixing min() and max()?

--- 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)

--
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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min'
  2014-06-20 20:39     ` Andrew Morton
@ 2014-06-20 21:16       ` Michal Nazarewicz
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Nazarewicz @ 2014-06-20 21:16 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Fengguang Wu, kbuild-all, Johannes Weiner, Hagen Paul Pfeifer,
	Linux Memory Management List

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-20 21:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <53a3c359.yUYVC7fzjYpZLyLq%fengguang.wu@intel.com>
2014-06-20  5:52 ` [mmotm:master 141/230] include/linux/kernel.h:744:28: note: in expansion of macro 'min' Fengguang Wu
2014-06-20 15:19   ` Michal Nazarewicz
2014-06-20 20:39     ` Andrew Morton
2014-06-20 21:16       ` Michal Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).