diff mbox series

[2/6] Provide __free(argv) for argv_split() users

Message ID 173594530753.1055889.17844868397124331132.stgit@devnote2 (mailing list archive)
State Superseded
Headers show
Series kprobes: jump label: Cleanup with guard and __free | expand

Commit Message

Masami Hiramatsu (Google) Jan. 3, 2025, 11:01 p.m. UTC
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Provide __free(argv) macro for argv_split() users so that they can
avoid gotos.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 include/linux/string.h |    2 ++
 1 file changed, 2 insertions(+)

Comments

kernel test robot Jan. 4, 2025, 6:39 a.m. UTC | #1
Hi Masami,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20241220]
[also build test ERROR on v6.13-rc5]
[cannot apply to kees/for-next/hardening linus/master rostedt-trace/for-next rostedt-trace/for-next-urgent v6.13-rc5 v6.13-rc4 v6.13-rc3]
[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/Masami-Hiramatsu-Google/tracing-kprobes-Fix-to-free-objects-when-failed-to-copy-a-symbol/20250104-070535
base:   next-20241220
patch link:    https://lore.kernel.org/r/173594530753.1055889.17844868397124331132.stgit%40devnote2
patch subject: [PATCH 2/6] Provide __free(argv) for argv_split() users
config: i386-buildonly-randconfig-002-20250104 (https://download.01.org/0day-ci/archive/20250104/202501041433.GkehPwga-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250104/202501041433.GkehPwga-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/202501041433.GkehPwga-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/uuid.h:11,
                    from include/linux/mod_devicetable.h:14,
                    from scripts/mod/devicetable-offsets.c:3:
>> include/linux/string.h:315:18: error: expected ')' before 'char'
     315 | DEFINE_FREE(argv, char **, argv_free(_T))
         |                  ^~~~~
         |                  )
   make[3]: *** [scripts/Makefile.build:102: scripts/mod/devicetable-offsets.s] Error 1 shuffle=943069964
   make[3]: Target 'scripts/mod/' not remade because of errors.
   make[2]: *** [Makefile:1262: prepare0] Error 2 shuffle=943069964
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:251: __sub-make] Error 2 shuffle=943069964
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:251: __sub-make] Error 2 shuffle=943069964
   make: Target 'prepare' not remade because of errors.


vim +315 include/linux/string.h

   314	
 > 315	DEFINE_FREE(argv, char **, argv_free(_T))
   316
kernel test robot Jan. 4, 2025, 6:51 a.m. UTC | #2
Hi Masami,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20241220]
[also build test ERROR on v6.13-rc5]
[cannot apply to kees/for-next/hardening linus/master rostedt-trace/for-next rostedt-trace/for-next-urgent v6.13-rc5 v6.13-rc4 v6.13-rc3]
[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/Masami-Hiramatsu-Google/tracing-kprobes-Fix-to-free-objects-when-failed-to-copy-a-symbol/20250104-070535
base:   next-20241220
patch link:    https://lore.kernel.org/r/173594530753.1055889.17844868397124331132.stgit%40devnote2
patch subject: [PATCH 2/6] Provide __free(argv) for argv_split() users
config: i386-buildonly-randconfig-001-20250104 (https://download.01.org/0day-ci/archive/20250104/202501041451.yG7LhbEv-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250104/202501041451.yG7LhbEv-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/202501041451.yG7LhbEv-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from scripts/mod/devicetable-offsets.c:3:
   In file included from include/linux/mod_devicetable.h:14:
   In file included from include/linux/uuid.h:11:
>> include/linux/string.h:315:19: error: expected identifier
     315 | DEFINE_FREE(argv, char **, argv_free(_T))
         |                   ^
>> include/linux/string.h:315:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
     315 | DEFINE_FREE(argv, char **, argv_free(_T))
         | ^
         | int
>> include/linux/string.h:315:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
     315 | DEFINE_FREE(argv, char **, argv_free(_T))
         |            ^                            
         |                                         void
>> include/linux/string.h:315:42: error: expected ';' after top level declarator
     315 | DEFINE_FREE(argv, char **, argv_free(_T))
         |                                          ^
         |                                          ;
   4 errors generated.
   make[3]: *** [scripts/Makefile.build:102: scripts/mod/devicetable-offsets.s] Error 1 shuffle=808271366
   make[3]: Target 'scripts/mod/' not remade because of errors.
   make[2]: *** [Makefile:1262: prepare0] Error 2 shuffle=808271366
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:251: __sub-make] Error 2 shuffle=808271366
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:251: __sub-make] Error 2 shuffle=808271366
   make: Target 'prepare' not remade because of errors.


vim +315 include/linux/string.h

   314	
 > 315	DEFINE_FREE(argv, char **, argv_free(_T))
   316
Oleg Nesterov Jan. 4, 2025, 11:09 a.m. UTC | #3
On 01/04, Masami Hiramatsu (Google) wrote:
>
> +DEFINE_FREE(argv, char **, argv_free(_T))

This doesn't look right, I think we need

	DEFINE_FREE(argv, char **, if (_T) argv_free(_T))

?

From the next patch

	@@ -73,24 +73,20 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type
		struct dyn_event *pos, *n;
		char *system = NULL, *event, *p;
		int argc, ret = -ENOENT;
	-	char **argv;
	+	char **argv __free(argv) = NULL;
	 
		argv = argv_split(GFP_KERNEL, raw_command, &argc);
		if (!argv)
			return -ENOMEM;

if argv_split() returns NULL, then __free_argv() will call argv_free(NULL) ?

Oleg.
Masami Hiramatsu (Google) Jan. 5, 2025, 9 a.m. UTC | #4
On Sat, 4 Jan 2025 12:09:56 +0100
Oleg Nesterov <oleg@redhat.com> wrote:

> On 01/04, Masami Hiramatsu (Google) wrote:
> >
> > +DEFINE_FREE(argv, char **, argv_free(_T))
> 
> This doesn't look right, I think we need
> 
> 	DEFINE_FREE(argv, char **, if (_T) argv_free(_T))

Ah, yes. I misunderstood argv_free() can get NULL.

Thanks!

> 
> ?
> 
> From the next patch
> 
> 	@@ -73,24 +73,20 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type
> 		struct dyn_event *pos, *n;
> 		char *system = NULL, *event, *p;
> 		int argc, ret = -ENOENT;
> 	-	char **argv;
> 	+	char **argv __free(argv) = NULL;
> 	 
> 		argv = argv_split(GFP_KERNEL, raw_command, &argc);
> 		if (!argv)
> 			return -ENOMEM;
> 
> if argv_split() returns NULL, then __free_argv() will call argv_free(NULL) ?
> 
> Oleg.
> 
>
Masami Hiramatsu (Google) Jan. 5, 2025, 9:12 a.m. UTC | #5
On Sat, 4 Jan 2025 14:51:12 +0800
kernel test robot <lkp@intel.com> wrote:

> Hi Masami,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on next-20241220]
> [also build test ERROR on v6.13-rc5]
> [cannot apply to kees/for-next/hardening linus/master rostedt-trace/for-next rostedt-trace/for-next-urgent v6.13-rc5 v6.13-rc4 v6.13-rc3]
> [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/Masami-Hiramatsu-Google/tracing-kprobes-Fix-to-free-objects-when-failed-to-copy-a-symbol/20250104-070535
> base:   next-20241220
> patch link:    https://lore.kernel.org/r/173594530753.1055889.17844868397124331132.stgit%40devnote2
> patch subject: [PATCH 2/6] Provide __free(argv) for argv_split() users
> config: i386-buildonly-randconfig-001-20250104 (https://download.01.org/0day-ci/archive/20250104/202501041451.yG7LhbEv-lkp@intel.com/config)
> compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250104/202501041451.yG7LhbEv-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/202501041451.yG7LhbEv-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>    In file included from scripts/mod/devicetable-offsets.c:3:
>    In file included from include/linux/mod_devicetable.h:14:
>    In file included from include/linux/uuid.h:11:
> >> include/linux/string.h:315:19: error: expected identifier
>      315 | DEFINE_FREE(argv, char **, argv_free(_T))
>          |                   ^
> >> include/linux/string.h:315:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
>      315 | DEFINE_FREE(argv, char **, argv_free(_T))
>          | ^
>          | int
> >> include/linux/string.h:315:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
>      315 | DEFINE_FREE(argv, char **, argv_free(_T))
>          |            ^                            
>          |                                         void
> >> include/linux/string.h:315:42: error: expected ';' after top level declarator
>      315 | DEFINE_FREE(argv, char **, argv_free(_T))
>          |                                          ^
>          |                                          ;
>    4 errors generated.
>    make[3]: *** [scripts/Makefile.build:102: scripts/mod/devicetable-offsets.s] Error 1 shuffle=808271366
>    make[3]: Target 'scripts/mod/' not remade because of errors.
>    make[2]: *** [Makefile:1262: prepare0] Error 2 shuffle=808271366
>    make[2]: Target 'prepare' not remade because of errors.
>    make[1]: *** [Makefile:251: __sub-make] Error 2 shuffle=808271366
>    make[1]: Target 'prepare' not remade because of errors.
>    make: *** [Makefile:251: __sub-make] Error 2 shuffle=808271366
>    make: Target 'prepare' not remade because of errors.

Oops, I forgot to include cleanup.h!

Thanks, let me update it.

> 
> 
> vim +315 include/linux/string.h
> 
>    314	
>  > 315	DEFINE_FREE(argv, char **, argv_free(_T))
>    316	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
Steven Rostedt Jan. 6, 2025, 7:30 p.m. UTC | #6
On Sat,  4 Jan 2025 08:01:47 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Provide __free(argv) macro for argv_split() users so that they can
> avoid gotos.
> 
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  include/linux/string.h |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 493ac4862c77..7035a70e30be 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -312,6 +312,8 @@ extern void *kmemdup_array(const void *src, size_t count, size_t element_size, g
>  extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
>  extern void argv_free(char **argv);
>  
> +DEFINE_FREE(argv, char **, argv_free(_T))
> +
>  /* lib/cmdline.c */
>  extern int get_option(char **str, int *pint);
>  extern char *get_options(const char *str, int nints, int *ints);

FYI, I already have this change in linux-next:

  https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git/commit/?h=for-next&id=9e49ca756d207f4313fb7af48648a67da8e4e250
  https://lore.kernel.org/20241220103313.4a74ec8e@gandalf.local.home

-- Steve
diff mbox series

Patch

diff --git a/include/linux/string.h b/include/linux/string.h
index 493ac4862c77..7035a70e30be 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -312,6 +312,8 @@  extern void *kmemdup_array(const void *src, size_t count, size_t element_size, g
 extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
 extern void argv_free(char **argv);
 
+DEFINE_FREE(argv, char **, argv_free(_T))
+
 /* lib/cmdline.c */
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);