ata: replace macro with static inline in libata.h
PATCH 1/1 ata: replace macro with static inline in libata.h
Avoid ~70 sparse warnings like:drivers/ata/pata_ali.c:176:14: warning: symbol '__x' shadows an earlier one drivers/ata/pata_ali.c:176:14: originally declared here
Due to nesting min_t macro inside max_t macro which both use a __x identifier internally.
---
Andrew, here is a patch that drastically reduces the number of sparse warnings in libata. Alan Cox has suggested a clamp_t macro be added to kernel.h instead to avoid this issue. I don't believe Jeff Garzik has given an opinion yet (other than not applying it when originally sent this was 5/11 of the libata sparse warnings)
include/linux/libata.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
include/linux/libata.h +8 -1
@@ -764,7 +764,14 @@ struct ata_timing {unsigned short udma;/* t2CYCTYP/2 */ }; -#define FIT (v, vmin, vmax) max_t(short, min_t(short, v, vmax), vmin) +static inline short FIT (short v,short vmin,short vmax) +{ +if (v >= vmax) +return vmax; +if (v <= vmin) +return vmin; +return v; +}extern const unsigned long sata_deb_timing_normal[];extern const unsigned long sata_deb_timing_hotplug[];
Signature · 1 line
1.5.4.1.1278.gc75be
Quoted 25 lines · Harvey Harrison
Avoid ~70 sparse warnings like:
drivers/ata/pata_ali.c:176:14: warning: symbol '__x' shadows an earlier onedrivers/ata/pata_ali.c:176:14: originally declared hereDue to nesting
min_tmacro insidemax_tmacro which both use a__xidentifier internally.Signed-off-by Harvey Harrison <[email protected]>---
Andrew, here is a patch that drastically reduces the number of sparse warnings in libata. Alan Cox has suggested aclamp_tmacro be added tokernel.hinstead to avoid this issue. I don't believe Jeff Garzik has given an opinion yet (other than not applying it when originally sent this was 5/11 of the libata sparse warnings)include/linux/libata.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/linux/libata.h +0
-0@@ -764,7 +764,14 @@ struct ata_timing {unsigned short udma;/* t2CYCTYP/2 */ };
include/linux/libata.h struct ata_timing { · line 774
Quoted 10 lines
include/linux/libata.h +8
-1-#define FIT (v, vmin, vmax) max_t(short, min_t(short, v, vmax), vmin) +static inline short FIT (short v,short vmin,short vmax) +{ +if (v >= vmax) +return vmax; +if (v <= vmin) +return vmin; +return v; +}
I agree with Alan...
PATCH 1/1 ata: use clamp_t macro to avoid sparse warnings
Nesting min_t/max_t macros produces many shadowed variable warnings due to use of __x. Add a clamp_t macro to linux/kernel.h and use it in the FIT macro.
--- include/linux/kernel.h | 9 +++++++++ include/linux/libata.h | 2 +- 2 files changed, 10 insertions(+), 1 deletions(-)
include/linux/kernel.h +9 -0
@@ -362,6 +362,15 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char *#define max_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) +/* +* Clamp a value to within a given range using comparisons of a specified type. +*/ +#define clamp_t (type,val,min,max) ({ \ + type __val = (val); \ + type __min = (min); \ + type __max = (max); \ + __val = __val < __min ? __min: __val; \ + __val > __max ? __max: __val; })/** * container_of - cast a member of a structure out to the containing structure
include/linux/libata.h +1 -1
@@ -754,7 +754,7 @@ struct ata_timing {unsigned short udma;/* t2CYCTYP/2 */ }; -#define FIT (v, vmin, vmax) max_t(short, min_t(short, v, vmax), vmin) +#define FIT (v, vmin, vmax) clamp_t(short, v, vmin, vmax)extern const unsigned long sata_deb_timing_normal[];extern const unsigned long sata_deb_timing_hotplug[];
Signature · 1 line
1.5.4.2.200.g99e75