diff mbox series

[v2,2/7] Provide __free(argv_free) for argv_split() users

Message ID 173617939641.1366315.14116274334551383402.stgit@devnote2 (mailing list archive)
State Superseded
Headers show
Series tracing/probes: Cleanup with guard and __free for kprobe and fprobe | expand

Commit Message

Masami Hiramatsu (Google) Jan. 6, 2025, 4:03 p.m. UTC
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 Changes in v3:
  - Rename to __free(argv_free) so that making it clear to call argv_free().
 Changes in v2:
  - Fix to call argv_free() only if the argument is !IS_ERR_OR_NULL().
  - Add including cleanup.h.
---
 include/linux/string.h |    3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/string.h b/include/linux/string.h
index 493ac4862c77..86d5d352068b 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -4,6 +4,7 @@ 
 
 #include <linux/args.h>
 #include <linux/array_size.h>
+#include <linux/cleanup.h>	/* for DEFINE_FREE() */
 #include <linux/compiler.h>	/* for inline */
 #include <linux/types.h>	/* for size_t */
 #include <linux/stddef.h>	/* for NULL */
@@ -312,6 +313,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_free, char **, if (!IS_ERR_OR_NULL(_T)) 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);