tracing: Cleanup event_enable_trigger_parse() by using __free()
Subsystems (2)
Steven Rostedt
maintainerPATCH 1/1 tracing: Cleanup event_enable_trigger_parse() by using __free()
From: Steven Rostedt <[email protected]>
The enable_data variable gets freed on most error paths in event_enable_trigger_parse(). Use free() to free it and just before returning normally, call no_free_ptr(enable_data) to keep it from being freed.
--- kernel/trace/trace_events_trigger.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/trace/trace_events_trigger.c +4 -8
@@ -1739,7 +1739,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, char *glob, char *cmd, char *param_and_filter) { struct trace_event_file *event_enable_file; -struct enable_trigger_data *enable_data; + struct enable_trigger_data *enable_data __free(kfree) = NULL;struct event_trigger_data *trigger_data;struct trace_array *tr = file->tr;char *param, *filter;
@@ -1789,17 +1789,13 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, enable_data->file = event_enable_file; trigger_data =trigger_data_alloc (cmd_ops, cmd, param, enable_data); -if (!trigger_data) { -kfree (enable_data); +if (!trigger_data)return ret; - }if (remove) {event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data);kfree (trigger_data); -kfree (enable_data); - ret =0 ; -return ret; +return 0 ; }/* Up the trigger_data count to make sure nothing frees it on failure */
@@ -1829,6 +1825,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, goto out_disable;event_trigger_free (trigger_data); +no_free_ptr (enable_data);return ret; out_disable:trace_event_enable_disable (event_enable_file,0 ,1 );
@@ -1837,7 +1834,6 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, out_free:event_trigger_reset_filter (cmd_ops, trigger_data);event_trigger_free (trigger_data); -kfree (enable_data);return ret; }
Signature · 1 line
2.53.0
Quoted 7 lines · On Wed, 1 Jul 2026 17:48:29 -0400 Steven Rostedt <[email protected]> wrote:
From: Steven Rostedt <[email protected]>
The
enable_datavariable gets freed on most error paths inevent_enable_trigger_parse(). Usefree()to free it and just before returning normally, callno_free_ptr(enable_data)to keep it from being freed.
This looks good to me.
Thank you,
Quoted 57 lines
Signed-off-by Steven Rostedt <[email protected]>--- kernel/trace/trace_events_trigger.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)kernel/trace/trace_events_trigger.c +4
-8@@ -1739,7 +1739,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, char *glob, char *cmd, char *param_and_filter) { struct trace_event_file *event_enable_file; -struct enable_trigger_data *enable_data; + struct enable_trigger_data *enable_data __free(kfree) = NULL;struct event_trigger_data *trigger_data;struct trace_array *tr = file->tr;char *param, *filter;@@ -1789,17 +1789,13 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, enable_data->file = event_enable_file; trigger_data =trigger_data_alloc (cmd_ops, cmd, param, enable_data); -if (!trigger_data) { -kfree (enable_data); +if (!trigger_data)return ret; - }if (remove) {event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data);kfree (trigger_data); -kfree (enable_data); - ret =0 ; -return ret; +return 0 ; }/* Up the trigger_data count to make sure nothing frees it on failure */ @@ -1829,6 +1825,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, goto out_disable;event_trigger_free (trigger_data); +no_free_ptr (enable_data);return ret; out_disable:trace_event_enable_disable (event_enable_file,0 ,1 );@@ -1837,7 +1834,6 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, out_free:event_trigger_reset_filter (cmd_ops, trigger_data);event_trigger_free (trigger_data); -kfree (enable_data);return ret; }Signature · 1 line
2.53.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
…
kernel/trace/trace_events_trigger.c int event_enable_trigger_parse(struct event_command *cmd_ops, · line 1742
Quoted 7 lines
+++
b/kernel/trace/trace_events_trigger.ckernel/trace/trace_events_trigger.c +1
-1@@ -1739,7 +1739,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, char *glob, char *cmd, char *param_and_filter) { struct trace_event_file *event_enable_file; -struct enable_trigger_data *enable_data; + struct enable_trigger_data *enable_data __free(kfree) = NULL;
…
How do you think about to reduce the scope for this local variable?
Regards,
Markus
Steven Rostedt
maintainerQuoted 10 lines · On Thu, 2 Jul 2026 11:58:02 +0200 Markus Elfring <[email protected]> wrote:
…
Quoted 7 lines
+++
b/kernel/trace/trace_events_trigger.ckernel/trace/trace_events_trigger.c +1
-1@@ -1739,7 +1739,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, char *glob, char *cmd, char *param_and_filter) { struct trace_event_file *event_enable_file; -struct enable_trigger_data *enable_data; + struct enable_trigger_data *enable_data __free(kfree) = NULL;…
Quoted 2 lines
How do you think about to reduce the scope for this local variable?
No, it's fine as is.
-- Steve
Quoted 10 lines
Quoted 10 lines
…
Quoted 7 lines
+++
b/kernel/trace/trace_events_trigger.ckernel/trace/trace_events_trigger.c +1
-1@@ -1739,7 +1739,7 @@ int event_enable_trigger_parse(struct event_command *cmd_ops, char *glob, char *cmd, char *param_and_filter) { struct trace_event_file *event_enable_file; -struct enable_trigger_data *enable_data; + struct enable_trigger_data *enable_data __free(kfree) = NULL;…
Quoted 4 lines
Quoted 2 lines
How do you think about to reduce the scope for this local variable?
No, it's fine as is.
Does this feedback mean that you disagree to an essential development requirement according to such a programming interface?
https://elixir.bootlin.com/linux/v7.1.2/source/include/linux/cleanup.h#L142-L153
Regards,
Markus
Steven Rostedt
maintainerQuoted 10 lines · On Fri, 3 Jul 2026 07:00:10 +0200 Markus Elfring <[email protected]> wrote:
Quoted 1 line
No, it's fine as is.
Does this feedback mean that you disagree to an essential development requirement according to such a programming interface?
https://elixir.bootlin.com/linux/v7.1.2/source/include/linux/cleanup.h#L142-L153* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.
This is really just a guideline.
Quoted 7 lines
*
* Lastly, given that the benefit of cleanup helpers is removal of
* "goto", and that the "goto" statement can jump between scopes, the
* expectation is that usage of "goto" and cleanup helpers is never
* mixed in the same function. I.e. for a given routine, convert all
* resources that need a "goto" cleanup to scope-based cleanup, or
* convert none of them.
The above has more to do with guard()s and not so much with a __free() at the top of the function. The reason is because things get broken if a goto jumps over a guard().
In other words, if you don't know what you are doing, don't mix them.
-- Steve
Quoted 7 lines
Quoted 5 lines
* Given that the "
__free(...)= NULL" pattern for variables defined at
* the top of the function poses this potential interdependency problem
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when__free()is used.This is really just a guideline.
Do any contributors care a bit more for involved technical details?
https://lore.kernel.org/arm-scmi/[email protected]/
Regards,
Markus
Steven Rostedt
maintainerQuoted 2 lines · On Fri, 3 Jul 2026 20:37:09 +0200 Markus Elfring <[email protected]> wrote:
Do any contributors care a bit more for involved technical details?
https://lore.kernel.org/arm-scmi/[email protected]/
That example uses the variable in a specific block whereas this variable is used in most of the function, which makes it appropriate where it lies.
-- Steve
Quoted 2 lines
That example uses the variable in a specific block whereas this variable is used in most of the function, which makes it appropriate where it lies.
What does hinder you to apply scope reductions for selected local variables more often?
Regards,
Markus
Steven Rostedt
maintainerQuoted 6 lines · On Fri, 3 Jul 2026 21:20:46 +0200 Markus Elfring <[email protected]> wrote:
Quoted 2 lines
That example uses the variable in a specific block whereas this variable is used in most of the function, which makes it appropriate where it lies.
What does hinder you to apply scope reductions for selected local variables more often?
OK, now you are just talking like Eliza.
-- Steve
Quoted 4 lines
The
enable_datavariable gets freed on most error paths inevent_enable_trigger_parse(). Usefree()to free it and just before returning normally, callno_free_ptr(enable_data)to keep it from being freed.
The conversion is incomplete for the application of scope-based resource management so far.
Regards,
Markus
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Steven,
kernel test robot noticed the following build warnings:
[auto build test WARNING on trace/for-next]
[also build test WARNING on linus/master v7.2-rc6 next-20260804] [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/Steven-Rostedt/tracing-Cleanup-event_enable_trigger_parse-by-using-__free/20260805-073956 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260701174829.67ab8a33%40gandalf.local.home patch subject: [PATCH] tracing: Cleanup event_enable_trigger_parse() by using __free() config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20260805/[email protected]/config) compiler: powerpc64-linux-gcc (GCC) 16.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from include/linux/file.h:13,
from include/linux/kernel_read_file.h:5,
from include/linux/security.h:26,
from kernel/trace/trace_events_trigger.c:8:
kernel/trace/trace_events_trigger.c: In function 'event_enable_trigger_parse':
>> include/linux/cleanup.h:228:22: warning: ignoring return value of '__must_check_fn' declared with attribute 'warn_unused_result' [-Wunused-result]
228 | ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace_events_trigger.c:1842:9: note: in expansion of macro 'no_free_ptr'
1842 | no_free_ptr(enable_data);
| ^~~~~~~~~~~vim +228 include/linux/cleanup.h
85be6d84244706 Peter Zijlstra 2023-08-15 22654da6a0924311c Peter Zijlstra 2023-05-26 227 #define no_free_ptr(p) \366fef794bd2b7 Ilpo Järvinen 2025-03-10 @228 ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))54da6a0924311c Peter Zijlstra 2023-05-26 229
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Steven,
kernel test robot noticed the following build warnings:
[auto build test WARNING on trace/for-next]
[also build test WARNING on linus/master v7.2-rc6 next-20260804] [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/Steven-Rostedt/tracing-Cleanup-event_enable_trigger_parse-by-using-__free/20260805-073956 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260701174829.67ab8a33%40gandalf.local.home patch subject: [PATCH] tracing: Cleanup event_enable_trigger_parse() by using __free() config: s390-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260805/[email protected]/config) compiler: s390x-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from ./include/linux/file.h:13,
from ./include/linux/kernel_read_file.h:5,
from ./include/linux/security.h:26,
from kernel/trace/trace_events_trigger.c:8:
kernel/trace/trace_events_trigger.c: In function 'event_enable_trigger_parse':
>> ./include/linux/cleanup.h:228:22: warning: ignoring return value of '__must_check_fn' declared with attribute 'warn_unused_result' [-Wunused-result]
228 | ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace_events_trigger.c:1842:9: note: in expansion of macro 'no_free_ptr'
1842 | no_free_ptr(enable_data);
| ^~~~~~~~~~~vim +228 ./include/linux/cleanup.h
85be6d84244706 Peter Zijlstra 2023-08-15 22654da6a0924311c Peter Zijlstra 2023-05-26 227 #define no_free_ptr(p) \366fef794bd2b7 Ilpo Järvinen 2025-03-10 @228 ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))54da6a0924311c Peter Zijlstra 2023-05-26 229
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Steven Rostedt
maintainerDoes the kernel test robot just keep on testing old versions of a patch? Sashiko discovered this issue and I made a v2 with a fix a week ago:
https://lore.kernel.org/all/[email protected]/
-- Steve
Quoted 48 lines · On Wed, 5 Aug 2026 08:21:33 +0200 kernel test robot <[email protected]> wrote:
Hi Steven,
kernel test robot noticed the following build warnings:
[auto build test WARNING on trace/for-next]
[also build test WARNING on linus/master v7.2-rc6 next-20260804] [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/Steven-Rostedt/tracing-Cleanup-event_enable_trigger_parse-by-using-__free/20260805-073956 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260701174829.67ab8a33%40gandalf.local.home patch subject: [PATCH] tracing: Cleanup event_enable_trigger_parse() by using __free() config: s390-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260805/[email protected]/config) compiler: s390x-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
In file included from
./include/linux/file.h:13,from ./include/linux/kernel_read_file.h:5, from ./include/linux/security.h:26, from kernel/trace/trace_events_trigger.c:8:
kernel/trace/trace_events_trigger.c: In function 'event_enable_trigger_parse':Quoted 1 line
Quoted 1 line
./include/linux/cleanup.h:228:22: warning: ignoring return value of '__must_check_fn' declared with attribute 'warn_unused_result' [-Wunused-result]228 | ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/trace/trace_events_trigger.c:1842:9: note: in expansion of macro 'no_free_ptr' 1842 | no_free_ptr(enable_data); | ^~~~~~~~~~~vim +228
./include/linux/cleanup.h
85be6d84244706Peter Zijlstra 2023-08-15 22654da6a0924311cPeter Zijlstra 2023-05-26 227 #defineno_free_ptr(p)\366fef794bd2b7Ilpo Järvinen 2025-03-10 @228 ((typeof(p))__must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))54da6a0924311cPeter Zijlstra 2023-05-26 229--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Quoted 2 lines · Steven Rostedt
Does the kernel test robot just keep on testing old versions of a patch?
Hi Steve, sorry about this meaningless report, we will improve the bot to check new patches to avoid sending such report.
Quoted 60 lines
Sashiko discovered this issue and I made a v2 with a fix a week ago:
https://lore.kernel.org/all/[email protected]/
-- Steve
Quoted 48 lines · On Wed, 5 Aug 2026 08:21:33 +0200 kernel test robot <[email protected]> wrote:
Hi Steven,
kernel test robot noticed the following build warnings:
[auto build test WARNING on trace/for-next]
[also build test WARNING on linus/master v7.2-rc6 next-20260804] [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/Steven-Rostedt/tracing-Cleanup-event_enable_trigger_parse-by-using-__free/20260805-073956 base: https://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace for-next patch link: https://lore.kernel.org/r/20260701174829.67ab8a33%40gandalf.local.home patch subject: [PATCH] tracing: Cleanup event_enable_trigger_parse() by using __free() config: s390-allnoconfig-bpf (https://download.01.org/0day-ci/archive/20260805/[email protected]/config) compiler: s390x-linux-gnu-gcc (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260805/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All warnings (new ones prefixed by >>):
In file included from
./include/linux/file.h:13,from ./include/linux/kernel_read_file.h:5, from ./include/linux/security.h:26, from kernel/trace/trace_events_trigger.c:8:
kernel/trace/trace_events_trigger.c: In function 'event_enable_trigger_parse':Quoted 1 line
Quoted 1 line
./include/linux/cleanup.h:228:22: warning: ignoring return value of '__must_check_fn' declared with attribute 'warn_unused_result' [-Wunused-result]228 | ((typeof(p)) __must_check_fn((__force const volatile void *)__get_and_null(p, NULL))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kernel/trace/trace_events_trigger.c:1842:9: note: in expansion of macro 'no_free_ptr' 1842 | no_free_ptr(enable_data); | ^~~~~~~~~~~vim +228
./include/linux/cleanup.h
85be6d84244706Peter Zijlstra 2023-08-15 22654da6a0924311cPeter Zijlstra 2023-05-26 227 #defineno_free_ptr(p)\366fef794bd2b7Ilpo Järvinen 2025-03-10 @228 ((typeof(p))__must_check_fn((__force const volatile void *)__get_and_null(p, NULL)))54da6a0924311cPeter Zijlstra 2023-05-26 229--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki