88#define pr_fmt (fmt ) "trace_uprobe: " fmt
99
1010#include <linux/bpf-cgroup.h>
11+ #include <linux/cleanup.h>
1112#include <linux/ctype.h>
1213#include <linux/filter.h>
1314#include <linux/module.h>
1920#include <linux/uaccess.h>
2021#include <linux/uprobes.h>
2122
23+ #include "trace.h"
2224#include "trace_dynevent.h"
2325#include "trace_probe.h"
2426#include "trace_probe_tmpl.h"
@@ -537,15 +539,15 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
537539 */
538540static int __trace_uprobe_create (int argc , const char * * argv )
539541{
540- struct trace_uprobe * tu ;
541542 const char * event = NULL , * group = UPROBE_EVENT_SYSTEM ;
542543 char * arg , * filename , * rctr , * rctr_end , * tmp ;
543- char buf [MAX_EVENT_NAME_LEN ];
544- char gbuf [MAX_EVENT_NAME_LEN ];
545- enum probe_print_type ptype ;
546- struct path path ;
547544 unsigned long offset , ref_ctr_offset ;
545+ char * gbuf __free (kfree ) = NULL ;
546+ char * buf __free (kfree ) = NULL ;
547+ enum probe_print_type ptype ;
548+ struct trace_uprobe * tu ;
548549 bool is_return = false;
550+ struct path path ;
549551 int i , ret ;
550552
551553 ref_ctr_offset = 0 ;
@@ -653,6 +655,10 @@ static int __trace_uprobe_create(int argc, const char **argv)
653655 /* setup a probe */
654656 trace_probe_log_set_index (0 );
655657 if (event ) {
658+ gbuf = kmalloc (MAX_EVENT_NAME_LEN , GFP_KERNEL );
659+ if (!gbuf )
660+ goto fail_mem ;
661+
656662 ret = traceprobe_parse_event_name (& event , & group , gbuf ,
657663 event - argv [0 ]);
658664 if (ret )
@@ -664,15 +670,16 @@ static int __trace_uprobe_create(int argc, const char **argv)
664670 char * ptr ;
665671
666672 tail = kstrdup (kbasename (filename ), GFP_KERNEL );
667- if (!tail ) {
668- ret = - ENOMEM ;
669- goto fail_address_parse ;
670- }
673+ if (!tail )
674+ goto fail_mem ;
671675
672676 ptr = strpbrk (tail , ".-_" );
673677 if (ptr )
674678 * ptr = '\0' ;
675679
680+ buf = kmalloc (MAX_EVENT_NAME_LEN , GFP_KERNEL );
681+ if (!buf )
682+ goto fail_mem ;
676683 snprintf (buf , MAX_EVENT_NAME_LEN , "%c_%s_0x%lx" , 'p' , tail , offset );
677684 event = buf ;
678685 kfree (tail );
@@ -724,6 +731,9 @@ static int __trace_uprobe_create(int argc, const char **argv)
724731 trace_probe_log_clear ();
725732 return ret ;
726733
734+ fail_mem :
735+ ret = - ENOMEM ;
736+
727737fail_address_parse :
728738 trace_probe_log_clear ();
729739 path_put (& path );
0 commit comments