forked from mirrors/linux
		
	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>
			
			
This commit is contained in:
		
							parent
							
								
									53aeee7a86
								
							
						
					
					
						commit
						589a9785ee
					
				
					 1 changed files with 26 additions and 18 deletions
				
			
		| 
						 | 
					@ -733,17 +733,25 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 | 
				
			||||||
 * strict type-checking.. See the
 | 
					 * strict type-checking.. See the
 | 
				
			||||||
 * "unnecessary" pointer comparison.
 | 
					 * "unnecessary" pointer comparison.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define min(x, y) ({				\
 | 
					#define __min(t1, t2, min1, min2, x, y) ({		\
 | 
				
			||||||
	typeof(x) _min1 = (x);			\
 | 
						t1 min1 = (x);					\
 | 
				
			||||||
	typeof(y) _min2 = (y);			\
 | 
						t2 min2 = (y);					\
 | 
				
			||||||
	(void) (&_min1 == &_min2);		\
 | 
						(void) (&min1 == &min2);			\
 | 
				
			||||||
	_min1 < _min2 ? _min1 : _min2; })
 | 
						min1 < min2 ? min1 : min2; })
 | 
				
			||||||
 | 
					#define min(x, y)					\
 | 
				
			||||||
 | 
						__min(typeof(x), typeof(y),			\
 | 
				
			||||||
 | 
						      __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),	\
 | 
				
			||||||
 | 
						      x, y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define max(x, y) ({				\
 | 
					#define __max(t1, t2, max1, max2, x, y) ({		\
 | 
				
			||||||
	typeof(x) _max1 = (x);			\
 | 
						t1 max1 = (x);					\
 | 
				
			||||||
	typeof(y) _max2 = (y);			\
 | 
						t2 max2 = (y);					\
 | 
				
			||||||
	(void) (&_max1 == &_max2);		\
 | 
						(void) (&max1 == &max2);			\
 | 
				
			||||||
	_max1 > _max2 ? _max1 : _max2; })
 | 
						max1 > max2 ? max1 : max2; })
 | 
				
			||||||
 | 
					#define max(x, y)					\
 | 
				
			||||||
 | 
						__max(typeof(x), typeof(y),			\
 | 
				
			||||||
 | 
						      __UNIQUE_ID(max1_), __UNIQUE_ID(max2_),	\
 | 
				
			||||||
 | 
						      x, y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define min3(x, y, z) min((typeof(x))min(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)
 | 
					#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) { }
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Or not use min/max/clamp at all, of course.
 | 
					 * Or not use min/max/clamp at all, of course.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define min_t(type, x, y) ({			\
 | 
					#define min_t(type, x, y)				\
 | 
				
			||||||
	type __min1 = (x);			\
 | 
						__min(type, type,				\
 | 
				
			||||||
	type __min2 = (y);			\
 | 
						      __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),	\
 | 
				
			||||||
	__min1 < __min2 ? __min1: __min2; })
 | 
						      x, y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define max_t(type, x, y) ({			\
 | 
					#define max_t(type, x, y)				\
 | 
				
			||||||
	type __max1 = (x);			\
 | 
						__max(type, type,				\
 | 
				
			||||||
	type __max2 = (y);			\
 | 
						      __UNIQUE_ID(min1_), __UNIQUE_ID(min2_),	\
 | 
				
			||||||
	__max1 > __max2 ? __max1: __max2; })
 | 
						      x, y)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * clamp_t - return a value clamped to a given range using a given type
 | 
					 * clamp_t - return a value clamped to a given range using a given type
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue