@@ -441,13 +441,8 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
441
441
else
442
442
ret = register_kprobe (& tk -> rp .kp );
443
443
444
- if (ret == 0 ) {
444
+ if (ret == 0 )
445
445
tk -> tp .flags |= TP_FLAG_REGISTERED ;
446
- } else if (ret == - EILSEQ ) {
447
- pr_warn ("Probing address(0x%p) is not an instruction boundary.\n" ,
448
- tk -> rp .kp .addr );
449
- ret = - EINVAL ;
450
- }
451
446
return ret ;
452
447
}
453
448
@@ -591,7 +586,7 @@ static int trace_kprobe_create(int argc, const char *argv[])
591
586
* Type of args:
592
587
* FETCHARG:TYPE : use TYPE instead of unsigned long.
593
588
*/
594
- struct trace_kprobe * tk ;
589
+ struct trace_kprobe * tk = NULL ;
595
590
int i , len , ret = 0 ;
596
591
bool is_return = false;
597
592
char * symbol = NULL , * tmp = NULL ;
@@ -615,68 +610,74 @@ static int trace_kprobe_create(int argc, const char *argv[])
615
610
if (argc < 2 )
616
611
return - ECANCELED ;
617
612
613
+ trace_probe_log_init ("trace_kprobe" , argc , argv );
614
+
618
615
event = strchr (& argv [0 ][1 ], ':' );
619
616
if (event )
620
617
event ++ ;
621
618
622
619
if (isdigit (argv [0 ][1 ])) {
623
620
if (!is_return ) {
624
- pr_info ( "Maxactive is not for kprobe" );
625
- return - EINVAL ;
621
+ trace_probe_log_err ( 1 , MAXACT_NO_KPROBE );
622
+ goto parse_error ;
626
623
}
627
624
if (event )
628
625
len = event - & argv [0 ][1 ] - 1 ;
629
626
else
630
627
len = strlen (& argv [0 ][1 ]);
631
- if (len > MAX_EVENT_NAME_LEN - 1 )
632
- return - E2BIG ;
628
+ if (len > MAX_EVENT_NAME_LEN - 1 ) {
629
+ trace_probe_log_err (1 , BAD_MAXACT );
630
+ goto parse_error ;
631
+ }
633
632
memcpy (buf , & argv [0 ][1 ], len );
634
633
buf [len ] = '\0' ;
635
634
ret = kstrtouint (buf , 0 , & maxactive );
636
635
if (ret || !maxactive ) {
637
- pr_info ( "Invalid maxactive number\n" );
638
- return ret ;
636
+ trace_probe_log_err ( 1 , BAD_MAXACT );
637
+ goto parse_error ;
639
638
}
640
639
/* kretprobes instances are iterated over via a list. The
641
640
* maximum should stay reasonable.
642
641
*/
643
642
if (maxactive > KRETPROBE_MAXACTIVE_MAX ) {
644
- pr_info ("Maxactive is too big (%d > %d).\n" ,
645
- maxactive , KRETPROBE_MAXACTIVE_MAX );
646
- return - E2BIG ;
643
+ trace_probe_log_err (1 , MAXACT_TOO_BIG );
644
+ goto parse_error ;
647
645
}
648
646
}
649
647
650
648
/* try to parse an address. if that fails, try to read the
651
649
* input as a symbol. */
652
650
if (kstrtoul (argv [1 ], 0 , (unsigned long * )& addr )) {
651
+ trace_probe_log_set_index (1 );
653
652
/* Check whether uprobe event specified */
654
- if (strchr (argv [1 ], '/' ) && strchr (argv [1 ], ':' ))
655
- return - ECANCELED ;
653
+ if (strchr (argv [1 ], '/' ) && strchr (argv [1 ], ':' )) {
654
+ ret = - ECANCELED ;
655
+ goto error ;
656
+ }
656
657
/* a symbol specified */
657
658
symbol = kstrdup (argv [1 ], GFP_KERNEL );
658
659
if (!symbol )
659
660
return - ENOMEM ;
660
661
/* TODO: support .init module functions */
661
662
ret = traceprobe_split_symbol_offset (symbol , & offset );
662
663
if (ret || offset < 0 || offset > UINT_MAX ) {
663
- pr_info ( "Failed to parse either an address or a symbol.\n" );
664
- goto out ;
664
+ trace_probe_log_err ( 0 , BAD_PROBE_ADDR );
665
+ goto parse_error ;
665
666
}
666
667
if (kprobe_on_func_entry (NULL , symbol , offset ))
667
668
flags |= TPARG_FL_FENTRY ;
668
669
if (offset && is_return && !(flags & TPARG_FL_FENTRY )) {
669
- pr_info ("Given offset is not valid for return probe.\n" );
670
- ret = - EINVAL ;
671
- goto out ;
670
+ trace_probe_log_err (0 , BAD_RETPROBE );
671
+ goto parse_error ;
672
672
}
673
673
}
674
- argc -= 2 ; argv += 2 ;
675
674
675
+ trace_probe_log_set_index (0 );
676
676
if (event ) {
677
- ret = traceprobe_parse_event_name (& event , & group , buf );
677
+ ret = traceprobe_parse_event_name (& event , & group , buf ,
678
+ event - argv [0 ]);
678
679
if (ret )
679
- goto out ;
680
+ goto parse_error ;
680
681
} else {
681
682
/* Make a new event name */
682
683
if (symbol )
@@ -691,13 +692,14 @@ static int trace_kprobe_create(int argc, const char *argv[])
691
692
692
693
/* setup a probe */
693
694
tk = alloc_trace_kprobe (group , event , addr , symbol , offset , maxactive ,
694
- argc , is_return );
695
+ argc - 2 , is_return );
695
696
if (IS_ERR (tk )) {
696
697
ret = PTR_ERR (tk );
697
- /* This must return -ENOMEM otherwise there is a bug */
698
+ /* This must return -ENOMEM, else there is a bug */
698
699
WARN_ON_ONCE (ret != - ENOMEM );
699
- goto out ;
700
+ goto out ; /* We know tk is not allocated */
700
701
}
702
+ argc -= 2 ; argv += 2 ;
701
703
702
704
/* parse arguments */
703
705
for (i = 0 ; i < argc && i < MAX_TRACE_ARGS ; i ++ ) {
@@ -707,19 +709,32 @@ static int trace_kprobe_create(int argc, const char *argv[])
707
709
goto error ;
708
710
}
709
711
712
+ trace_probe_log_set_index (i + 2 );
710
713
ret = traceprobe_parse_probe_arg (& tk -> tp , i , tmp , flags );
711
714
kfree (tmp );
712
715
if (ret )
713
- goto error ;
716
+ goto error ; /* This can be -ENOMEM */
714
717
}
715
718
716
719
ret = register_trace_kprobe (tk );
717
- if (ret )
720
+ if (ret ) {
721
+ trace_probe_log_set_index (1 );
722
+ if (ret == - EILSEQ )
723
+ trace_probe_log_err (0 , BAD_INSN_BNDRY );
724
+ else if (ret == - ENOENT )
725
+ trace_probe_log_err (0 , BAD_PROBE_ADDR );
726
+ else if (ret != - ENOMEM )
727
+ trace_probe_log_err (0 , FAIL_REG_PROBE );
718
728
goto error ;
729
+ }
730
+
719
731
out :
732
+ trace_probe_log_clear ();
720
733
kfree (symbol );
721
734
return ret ;
722
735
736
+ parse_error :
737
+ ret = - EINVAL ;
723
738
error :
724
739
free_trace_kprobe (tk );
725
740
goto out ;
0 commit comments