iavf: Use printf instead of gnu_printf for iavf_debug_d
Subsystems (3)
PATCH 1/1 iavf: Use printf instead of gnu_printf for iavf_debug_d
Clang warns:
In file included from drivers/net/ethernet/intel/iavf/iavf_main.c:4:
In file included from drivers/net/ethernet/intel/iavf/iavf.h:37:
In file included from drivers/net/ethernet/intel/iavf/iavf_type.h:8:drivers/net/ethernet/intel/iavf/iavf_osdep.h:49:18: warning: 'format' attribute argument not supported: gnu_printf [-Wignored-attributes]
__attribute__ ((format(gnu_printf, 3, 4)));
^1 warning generated.
We can convert from gnu_printf to printf without any side effects for two reasons:
1. All iavf_debug instances use standard printf formats, as pointed out by Miguel Ojeda at the below link, meaning gnu_printf is not strictly required.
2. However, GCC has aliased printf to gnu_printf on Linux since at least 2010 based on git history.
From gcc/c-family/c-format.c:
/* Attributes such as "printf" are equivalent to those such as
"gnu_printf" unless this is overridden by a target. */
static const target_ovr_attr gnu_target_overrides_format_attributes[] =
{
{ "gnu_printf", "printf" },
{ "gnu_scanf", "scanf" },
{ "gnu_strftime", "strftime" },
{ "gnu_strfmon", "strfmon" },
{ NULL, NULL }};
The mentioned override only happens on Windows (mingw32). Changing from gnu_printf to printf is a no-op for GCC and stops Clang from warning.
--- drivers/net/ethernet/intel/iavf/iavf_osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_osdep.h +1 -1
@@ -46,7 +46,7 @@ struct iavf_virt_mem {#define iavf_debug (h, m, s, ...) iavf_debug_d(h, m, s, ##__VA_ARGS__) extern void iavf_debug_d(void *hw, u32 mask, char *fmt_str, ...) - __attribute__ ((format (gnu_printf,3 ,4 ))); + __printf(3, 4);typedef enum iavf_status_code iavf_status ;#endif /* _IAVF_OSDEP_H_ */
Signature · 1 line
2.20.1
Quoted 14 lines · Nathan Chancellor
Clang warns:
In file included from
drivers/net/ethernet/intel/iavf/iavf_main.c:4:
In file included fromdrivers/net/ethernet/intel/iavf/iavf.h:37:
In file included fromdrivers/net/ethernet/intel/iavf/iavf_type.h:8:drivers/net/ethernet/intel/iavf/iavf_osdep.h:49:18: warning: 'format' attribute argument not supported:gnu_printf[-Wignored-attributes]__attribute__ ((format(gnu_printf, 3, 4))); ^1 warning generated.
We can convert from
gnu_printfto printf without any side effects for two reasons:
Quoted 6 lines
1. All
iavf_debuginstances use standard printf formats, as pointed out by Miguel Ojeda at the below link, meaninggnu_printfis not strictly required.2. However, GCC has aliased printf to
gnu_printfon Linux since at least 2010 based on git history.
Thanks for this fix!
FWIW, using godbolt to see which version something was added in is better than giving a year of the commit. I don't think it matters for this case, as the kernel already makes use of printf as you do in this change, but food for thought for next time.
Quoted 29 lines
From gcc/c-family/c-format.c: /* Attributes such as "printf" are equivalent to those such as "gnu_printf" unless this is overridden by a target. */ static const target_ovr_attr gnu_target_overrides_format_attributes[] = { { "gnu_printf", "printf" }, { "gnu_scanf", "scanf" }, { "gnu_strftime", "strftime" }, { "gnu_strfmon", "strfmon" }, { NULL, NULL } };The mentioned override only happens on Windows (mingw32). Changing from
gnu_printfto printf is a no-op for GCC and stops Clang from warning.Suggested-by Miguel Ojeda <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/intel/iavf/iavf_osdep.h +0
-0
drivers/net/ethernet/intel/iavf/iavf_osdep.h struct iavf_virt_mem { · line 49
Quoted 5 lines
drivers/net/ethernet/intel/iavf/iavf_osdep.h +1
-1@@ -46,7 +46,7 @@ struct iavf_virt_mem {#define iavf_debug (h, m, s, ...) iavf_debug_d(h, m, s, ##__VA_ARGS__) extern void iavf_debug_d(void *hw, u32 mask, char *fmt_str, ...) - __attribute__ ((format (gnu_printf,3 ,4 ))); + __printf(3, 4);
And you make use of the __attribute__ wrapper from include/linux/compiler_attributes.h, cool.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 20 lines · Nick Desaulniers
Quoted 18 lines · Nathan Chancellor
Clang warns:
In file included from
drivers/net/ethernet/intel/iavf/iavf_main.c:4:
In file included fromdrivers/net/ethernet/intel/iavf/iavf.h:37:
In file included fromdrivers/net/ethernet/intel/iavf/iavf_type.h:8:drivers/net/ethernet/intel/iavf/iavf_osdep.h:49:18: warning: 'format' attribute argument not supported:gnu_printf[-Wignored-attributes]__attribute__ ((format(gnu_printf, 3, 4))); ^1 warning generated.
We can convert from
gnu_printfto printf without any side effects for two reasons:1. All
iavf_debuginstances use standard printf formats, as pointed out by Miguel Ojeda at the below link, meaninggnu_printfis not strictly required.
Quoted 9 lines
Quoted 2 lines
2. However, GCC has aliased printf to
gnu_printfon Linux since at least 2010 based on git history.Thanks for this fix!
FWIW, using godbolt to see which version something was added in is better than giving a year of the commit. I don't think it matters for this case, as the kernel already makes use ofprintfas you do in this change, but food for thought for next time.
Yes that is a good point, I need to be taking advantage of that site more.
Thank you for the review!
Nathan
Quoted 42 lines
Quoted 29 lines
From gcc/c-family/c-format.c: /* Attributes such as "printf" are equivalent to those such as "gnu_printf" unless this is overridden by a target. */ static const target_ovr_attr gnu_target_overrides_format_attributes[] = { { "gnu_printf", "printf" }, { "gnu_scanf", "scanf" }, { "gnu_strftime", "strftime" }, { "gnu_strfmon", "strfmon" }, { NULL, NULL } };The mentioned override only happens on Windows (mingw32). Changing from
gnu_printfto printf is a no-op for GCC and stops Clang from warning.Suggested-by Miguel Ojeda <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/intel/iavf/iavf_osdep.h +0
-0drivers/net/ethernet/intel/iavf/iavf_osdep.h struct iavf_virt_mem { · line 49
Quoted 5 lines
drivers/net/ethernet/intel/iavf/iavf_osdep.h +1
-1@@ -46,7 +46,7 @@ struct iavf_virt_mem {#define iavf_debug (h, m, s, ...) iavf_debug_d(h, m, s, ##__VA_ARGS__) extern void iavf_debug_d(void *hw, u32 mask, char *fmt_str, ...) - __attribute__ ((format (gnu_printf,3 ,4 ))); + __printf(3, 4);And you make use of the
__attribute__wrapper frominclude/linux/compiler_attributes.h, cool.Reviewed-by Nick Desaulniers <[email protected]>Signature · 2 lines
Thanks, ~Nick Desaulniers
Hi Nathan,
Quoted 34 lines · Nathan Chancellor
Clang warns:
In file included from
drivers/net/ethernet/intel/iavf/iavf_main.c:4:
In file included fromdrivers/net/ethernet/intel/iavf/iavf.h:37:
In file included fromdrivers/net/ethernet/intel/iavf/iavf_type.h:8:drivers/net/ethernet/intel/iavf/iavf_osdep.h:49:18: warning: 'format' attribute argument not supported:gnu_printf[-Wignored-attributes]__attribute__ ((format(gnu_printf, 3, 4))); ^1 warning generated.
We can convert from
gnu_printfto printf without any side effects for two reasons:1. All
iavf_debuginstances use standard printf formats, as pointed out by Miguel Ojeda at the below link, meaninggnu_printfis not strictly required.2. However, GCC has aliased printf to
gnu_printfon Linux since at least 2010 based on git history.From gcc/c-family/c-format.c: /* Attributes such as "printf" are equivalent to those such as "gnu_printf" unless this is overridden by a target. */ static const target_ovr_attr gnu_target_overrides_format_attributes[] = { { "gnu_printf", "printf" }, { "gnu_scanf", "scanf" }, { "gnu_strftime", "strftime" }, { "gnu_strfmon", "strfmon" }, { NULL, NULL } };
Quoted 6 lines
The mentioned override only happens on Windows (mingw32). Changing from
gnu_printfto printf is a no-op for GCC and stops Clang from warning.Suggested-by Miguel Ojeda <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>
I forgot, in case you wanted it:
Thanks for taking care of writing the patch!
Cheers,
Miguel
Quoted 50 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at osuosl.org] On Behalf Of Nathan Chancellor
Sent: Wednesday, January 9, 2019 8:22 PM
To: Kirsher, Jeffrey T <[email protected]>
Cc: netdev at vger.kernel.org; Nick Desaulniers <[email protected]>; linux-kernel at vger.kernel.org; Miguel Ojeda <[email protected]>; intel-wired-lan at lists.osuosl.org; Nathan Chancellor <[email protected]>; David S. Miller <[email protected]>
Subject: [Intel-wired-lan] [PATCH] iavf: Use printf instead ofgnu_printfforiavf_debug_dClang warns:
In file included from
drivers/net/ethernet/intel/iavf/iavf_main.c:4:
In file included fromdrivers/net/ethernet/intel/iavf/iavf.h:37:
In file included fromdrivers/net/ethernet/intel/iavf/iavf_type.h:8:drivers/net/ethernet/intel/iavf/iavf_osdep.h:49:18: warning: 'format' attribute argument not supported:gnu_printf[-Wignored-attributes]__attribute__ ((format(gnu_printf, 3, 4))); ^1 warning generated.
We can convert from
gnu_printfto printf without any side effects for two reasons:1. All
iavf_debuginstances use standard printf formats, as pointed out by Miguel Ojeda at the below link, meaninggnu_printfis not strictly required.2. However, GCC has aliased printf to
gnu_printfon Linux since at least 2010 based on git history.From gcc/c-family/c-format.c: /* Attributes such as "printf" are equivalent to those such as "gnu_printf" unless this is overridden by a target. */ static const target_ovr_attr gnu_target_overrides_format_attributes[] = { { "gnu_printf", "printf" }, { "gnu_scanf", "scanf" }, { "gnu_strftime", "strftime" }, { "gnu_strfmon", "strfmon" }, { NULL, NULL } };The mentioned override only happens on Windows (mingw32). Changing from
gnu_printfto printf is a no-op for GCC and stops Clang from warning.
Quoted 6 lines
Suggested-by Miguel Ojeda <[email protected]>Signed-off-by Nathan Chancellor <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_osdep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)