diff mbox series

bpf: add __printf() to for printf fmt strings

Message ID 20231122133656.290475-1-ben.dooks@codethink.co.uk (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf: add __printf() to for printf fmt strings | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-11 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-10 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-3 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-16 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-llvm-16 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-16 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-llvm-16 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-16
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/codegen success Generated files up to date
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1133 this patch: 1133
netdev/cc_maintainers fail 11 maintainers not CCed: ast@kernel.org yonghong.song@linux.dev song@kernel.org haoluo@google.com martin.lau@linux.dev andrii@kernel.org jolsa@kernel.org kpsingh@kernel.org john.fastabend@gmail.com daniel@iogearbox.net sdf@google.com
netdev/build_clang success Errors and warnings before: 1155 this patch: 1155
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1160 this patch: 1160
netdev/checkpatch fail ERROR: space required after that ',' (ctx:VxV) WARNING: line length of 83 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ben Dooks Nov. 22, 2023, 1:36 p.m. UTC
The btf_seq_show() and btf_snprintf_show() take a printk format
string so add a __printf() to these two functions. This fixes the
following extended warnings:

kernel/bpf/btf.c:7094:29: error: function ‘btf_seq_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
kernel/bpf/btf.c:7131:9: error: function ‘btf_snprintf_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 kernel/bpf/btf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Daniel Borkmann Nov. 22, 2023, 3:26 p.m. UTC | #1
On 11/22/23 2:36 PM, Ben Dooks wrote:
> The btf_seq_show() and btf_snprintf_show() take a printk format
> string so add a __printf() to these two functions. This fixes the
> following extended warnings:
> 
> kernel/bpf/btf.c:7094:29: error: function ‘btf_seq_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> kernel/bpf/btf.c:7131:9: error: function ‘btf_snprintf_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> ---
>   kernel/bpf/btf.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 15d71d2986d3..46c2e87c383d 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7088,8 +7088,8 @@ static void btf_type_show(const struct btf *btf, u32 type_id, void *obj,
>   	btf_type_ops(t)->show(btf, t, type_id, obj, 0, show);
>   }
>   
> -static void btf_seq_show(struct btf_show *show, const char *fmt,
> -			 va_list args)
> +static __printf(2,0) void btf_seq_show(struct btf_show *show, const char *fmt,
> +				       va_list args)
>   {
>   	seq_vprintf((struct seq_file *)show->target, fmt, args);
>   }
> @@ -7122,7 +7122,7 @@ struct btf_show_snprintf {
>   	int len;		/* length we would have written */
>   };
>   
> -static void btf_snprintf_show(struct btf_show *show, const char *fmt,
> +static __printf(2,0) void btf_snprintf_show(struct btf_show *show, const char *fmt,
>   			      va_list args)
>   {

Looks good, only small nit is to fix up kernel-style formatting wrt spacing.

>   	struct btf_show_snprintf *ssnprintf = (struct btf_show_snprintf *)show;
>
Alan Maguire Nov. 22, 2023, 4:44 p.m. UTC | #2
On 22/11/2023 13:36, Ben Dooks wrote:
> The btf_seq_show() and btf_snprintf_show() take a printk format
> string so add a __printf() to these two functions. This fixes the
> following extended warnings:
> 
> kernel/bpf/btf.c:7094:29: error: function ‘btf_seq_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> kernel/bpf/btf.c:7131:9: error: function ‘btf_snprintf_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>

Looks good to me, thanks for fixing! Could also add a

Fixes: eb411377aed9 ("bpf: Add bpf_seq_printf_btf helper")

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

> ---
>  kernel/bpf/btf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 15d71d2986d3..46c2e87c383d 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -7088,8 +7088,8 @@ static void btf_type_show(const struct btf *btf, u32 type_id, void *obj,
>  	btf_type_ops(t)->show(btf, t, type_id, obj, 0, show);
>  }
>  
> -static void btf_seq_show(struct btf_show *show, const char *fmt,
> -			 va_list args)
> +static __printf(2,0) void btf_seq_show(struct btf_show *show, const char *fmt,
> +				       va_list args)
>  {
>  	seq_vprintf((struct seq_file *)show->target, fmt, args);
>  }
> @@ -7122,7 +7122,7 @@ struct btf_show_snprintf {
>  	int len;		/* length we would have written */
>  };
>  
> -static void btf_snprintf_show(struct btf_show *show, const char *fmt,
> +static __printf(2,0) void btf_snprintf_show(struct btf_show *show, const char *fmt,
>  			      va_list args)
>  {
>  	struct btf_show_snprintf *ssnprintf = (struct btf_show_snprintf *)show;
kernel test robot Nov. 23, 2023, 3:16 a.m. UTC | #3
Hi Ben,

kernel test robot noticed the following build warnings:

[auto build test WARNING on bpf-next/master]
[also build test WARNING on bpf/master linus/master v6.7-rc2 next-20231122]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ben-Dooks/bpf-add-__printf-to-for-printf-fmt-strings/20231122-231149
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/20231122133656.290475-1-ben.dooks%40codethink.co.uk
patch subject: [PATCH] bpf: add __printf() to for printf fmt strings
config: x86_64-randconfig-161-20231123 (https://download.01.org/0day-ci/archive/20231123/202311231030.yBuPn92M-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231123/202311231030.yBuPn92M-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311231030.yBuPn92M-lkp@intel.com/

All warnings (new ones prefixed by >>):

   kernel/bpf/btf.c: In function 'btf_type_seq_show_flags':
>> kernel/bpf/btf.c:7100:14: warning: assignment left-hand side might be a candidate for a format attribute [-Wsuggest-attribute=format]
    7100 |  sseq.showfn = btf_seq_show;
         |              ^
   kernel/bpf/btf.c: In function 'btf_type_snprintf_show':
   kernel/bpf/btf.c:7151:24: warning: assignment left-hand side might be a candidate for a format attribute [-Wsuggest-attribute=format]
    7151 |  ssnprintf.show.showfn = btf_snprintf_show;
         |                        ^


vim +7100 kernel/bpf/btf.c

31d0bc81637d8d Alan Maguire 2020-09-28  7093  
eb411377aed9e2 Alan Maguire 2020-09-28  7094  int btf_type_seq_show_flags(const struct btf *btf, u32 type_id,
31d0bc81637d8d Alan Maguire 2020-09-28  7095  			    void *obj, struct seq_file *m, u64 flags)
31d0bc81637d8d Alan Maguire 2020-09-28  7096  {
31d0bc81637d8d Alan Maguire 2020-09-28  7097  	struct btf_show sseq;
31d0bc81637d8d Alan Maguire 2020-09-28  7098  
31d0bc81637d8d Alan Maguire 2020-09-28  7099  	sseq.target = m;
31d0bc81637d8d Alan Maguire 2020-09-28 @7100  	sseq.showfn = btf_seq_show;
31d0bc81637d8d Alan Maguire 2020-09-28  7101  	sseq.flags = flags;
31d0bc81637d8d Alan Maguire 2020-09-28  7102  
31d0bc81637d8d Alan Maguire 2020-09-28  7103  	btf_type_show(btf, type_id, obj, &sseq);
31d0bc81637d8d Alan Maguire 2020-09-28  7104  
31d0bc81637d8d Alan Maguire 2020-09-28  7105  	return sseq.state.status;
31d0bc81637d8d Alan Maguire 2020-09-28  7106  }
31d0bc81637d8d Alan Maguire 2020-09-28  7107
Ben Dooks Dec. 8, 2023, 5:26 p.m. UTC | #4
On 22/11/2023 16:44, Alan Maguire wrote:
> On 22/11/2023 13:36, Ben Dooks wrote:
>> The btf_seq_show() and btf_snprintf_show() take a printk format
>> string so add a __printf() to these two functions. This fixes the
>> following extended warnings:
>>
>> kernel/bpf/btf.c:7094:29: error: function ‘btf_seq_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>> kernel/bpf/btf.c:7131:9: error: function ‘btf_snprintf_show’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
>>
>> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
> 
> Looks good to me, thanks for fixing! Could also add a
> 
> Fixes: eb411377aed9 ("bpf: Add bpf_seq_printf_btf helper")
> 
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>


Thanks, looks like the test robot found some issues so will
go back and look at those as soon as I can.

>> ---
>>   kernel/bpf/btf.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 15d71d2986d3..46c2e87c383d 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -7088,8 +7088,8 @@ static void btf_type_show(const struct btf *btf, u32 type_id, void *obj,
>>   	btf_type_ops(t)->show(btf, t, type_id, obj, 0, show);
>>   }
>>   
>> -static void btf_seq_show(struct btf_show *show, const char *fmt,
>> -			 va_list args)
>> +static __printf(2,0) void btf_seq_show(struct btf_show *show, const char *fmt,
>> +				       va_list args)
>>   {
>>   	seq_vprintf((struct seq_file *)show->target, fmt, args);
>>   }
>> @@ -7122,7 +7122,7 @@ struct btf_show_snprintf {
>>   	int len;		/* length we would have written */
>>   };
>>   
>> -static void btf_snprintf_show(struct btf_show *show, const char *fmt,
>> +static __printf(2,0) void btf_snprintf_show(struct btf_show *show, const char *fmt,
>>   			      va_list args)
>>   {
>>   	struct btf_show_snprintf *ssnprintf = (struct btf_show_snprintf *)show;
>
diff mbox series

Patch

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 15d71d2986d3..46c2e87c383d 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -7088,8 +7088,8 @@  static void btf_type_show(const struct btf *btf, u32 type_id, void *obj,
 	btf_type_ops(t)->show(btf, t, type_id, obj, 0, show);
 }
 
-static void btf_seq_show(struct btf_show *show, const char *fmt,
-			 va_list args)
+static __printf(2,0) void btf_seq_show(struct btf_show *show, const char *fmt,
+				       va_list args)
 {
 	seq_vprintf((struct seq_file *)show->target, fmt, args);
 }
@@ -7122,7 +7122,7 @@  struct btf_show_snprintf {
 	int len;		/* length we would have written */
 };
 
-static void btf_snprintf_show(struct btf_show *show, const char *fmt,
+static __printf(2,0) void btf_snprintf_show(struct btf_show *show, const char *fmt,
 			      va_list args)
 {
 	struct btf_show_snprintf *ssnprintf = (struct btf_show_snprintf *)show;