diff options
author | Johannes Berg <johannes.berg@intel.com> | 2016-10-07 20:02:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-10-07 21:46:30 -0400 |
commit | 589a9785ee3a7cb85f1dedc3dad1c9754c691880 (patch) | |
tree | 2a58cb3d8c4c0e1c9e025750dd4801f99352d7f1 /include/linux/kernel.h | |
parent | 53aeee7a86620b4dca81f6b807b37f36e7f99b09 (diff) |
min/max: remove sparse warnings when they're nested
Currently, when min/max are nested within themselves, sparse will warn:
warning: symbol '_min1' shadows an earlier one
originally declared here
warning: symbol '_min1' shadows an earlier one
originally declared here
warning: symbol '_min2' shadows an earlier one
originally declared here
This also immediately happens when min3() or max3() are used.
Since sparse implements __COUNTER__, we can use __UNIQUE_ID() to
generate unique variable names, avoiding this.
Link: http://lkml.kernel.org/r/1471519773-29882-1-git-send-email-johannes@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74fd6f05bc5b..bc6ed52a39b9 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -733,17 +733,25 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
733 | * strict type-checking.. See the | 733 | * strict type-checking.. See the |
734 | * "unnecessary" pointer comparison. | 734 | * "unnecessary" pointer comparison. |
735 | */ | 735 | */ |
736 | #define min(x, y) ({ \ | 736 | #define __min(t1, t2, min1, min2, x, y) ({ \ |
737 | typeof(x) _min1 = (x); \ | 737 | t1 min1 = (x); \ |
738 | typeof(y) _min2 = (y); \ | 738 | t2 min2 = (y); \ |
739 | (void) (&_min1 == &_min2); \ | 739 | (void) (&min1 == &min2); \ |
740 | _min1 < _min2 ? _min1 : _min2; }) | 740 | min1 < min2 ? min1 : min2; }) |
741 | 741 | #define min(x, y) \ | |
742 | #define max(x, y) ({ \ | 742 | __min(typeof(x), typeof(y), \ |
743 | typeof(x) _max1 = (x); \ | 743 | __UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \ |
744 | typeof(y) _max2 = (y); \ | 744 | x, y) |
745 | (void) (&_max1 == &_max2); \ | 745 | |
746 | _max1 > _max2 ? _max1 : _max2; }) | 746 | #define __max(t1, t2, max1, max2, x, y) ({ \ |
747 | t1 max1 = (x); \ | ||
748 | t2 max2 = (y); \ | ||
749 | (void) (&max1 == &max2); \ | ||
750 | max1 > max2 ? max1 : max2; }) | ||
751 | #define max(x, y) \ | ||
752 | __max(typeof(x), typeof(y), \ | ||
753 | __UNIQUE_ID(max1_), __UNIQUE_ID(max2_), \ | ||
754 | x, y) | ||
747 | 755 | ||
748 | #define min3(x, y, z) min((typeof(x))min(x, y), z) | 756 | #define min3(x, y, z) min((typeof(x))min(x, y), z) |
749 | #define max3(x, y, z) max((typeof(x))max(x, y), z) | 757 | #define max3(x, y, z) max((typeof(x))max(x, y), z) |
@@ -775,15 +783,15 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
775 | * | 783 | * |
776 | * Or not use min/max/clamp at all, of course. | 784 | * Or not use min/max/clamp at all, of course. |
777 | */ | 785 | */ |
778 | #define min_t(type, x, y) ({ \ | 786 | #define min_t(type, x, y) \ |
779 | type __min1 = (x); \ | 787 | __min(type, type, \ |
780 | type __min2 = (y); \ | 788 | __UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \ |
781 | __min1 < __min2 ? __min1: __min2; }) | 789 | x, y) |
782 | 790 | ||
783 | #define max_t(type, x, y) ({ \ | 791 | #define max_t(type, x, y) \ |
784 | type __max1 = (x); \ | 792 | __max(type, type, \ |
785 | type __max2 = (y); \ | 793 | __UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \ |
786 | __max1 > __max2 ? __max1: __max2; }) | 794 | x, y) |
787 | 795 | ||
788 | /** | 796 | /** |
789 | * clamp_t - return a value clamped to a given range using a given type | 797 | * clamp_t - return a value clamped to a given range using a given type |