@@ -441,13 +441,8 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)
441441 else
442442 ret = register_kprobe (& tk -> rp .kp );
443443
444- if (ret == 0 ) {
444+ if (ret == 0 )
445445 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- }
451446 return ret ;
452447}
453448
@@ -591,7 +586,7 @@ static int trace_kprobe_create(int argc, const char *argv[])
591586 * Type of args:
592587 * FETCHARG:TYPE : use TYPE instead of unsigned long.
593588 */
594- struct trace_kprobe * tk ;
589+ struct trace_kprobe * tk = NULL ;
595590 int i , len , ret = 0 ;
596591 bool is_return = false;
597592 char * symbol = NULL , * tmp = NULL ;
@@ -615,68 +610,74 @@ static int trace_kprobe_create(int argc, const char *argv[])
615610 if (argc < 2 )
616611 return - ECANCELED ;
617612
613+ trace_probe_log_init ("trace_kprobe" , argc , argv );
614+
618615 event = strchr (& argv [0 ][1 ], ':' );
619616 if (event )
620617 event ++ ;
621618
622619 if (isdigit (argv [0 ][1 ])) {
623620 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 ;
626623 }
627624 if (event )
628625 len = event - & argv [0 ][1 ] - 1 ;
629626 else
630627 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+ }
633632 memcpy (buf , & argv [0 ][1 ], len );
634633 buf [len ] = '\0' ;
635634 ret = kstrtouint (buf , 0 , & maxactive );
636635 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 ;
639638 }
640639 /* kretprobes instances are iterated over via a list. The
641640 * maximum should stay reasonable.
642641 */
643642 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 ;
647645 }
648646 }
649647
650648 /* try to parse an address. if that fails, try to read the
651649 * input as a symbol. */
652650 if (kstrtoul (argv [1 ], 0 , (unsigned long * )& addr )) {
651+ trace_probe_log_set_index (1 );
653652 /* 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+ }
656657 /* a symbol specified */
657658 symbol = kstrdup (argv [1 ], GFP_KERNEL );
658659 if (!symbol )
659660 return - ENOMEM ;
660661 /* TODO: support .init module functions */
661662 ret = traceprobe_split_symbol_offset (symbol , & offset );
662663 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 ;
665666 }
666667 if (kprobe_on_func_entry (NULL , symbol , offset ))
667668 flags |= TPARG_FL_FENTRY ;
668669 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 ;
672672 }
673673 }
674- argc -= 2 ; argv += 2 ;
675674
675+ trace_probe_log_set_index (0 );
676676 if (event ) {
677- ret = traceprobe_parse_event_name (& event , & group , buf );
677+ ret = traceprobe_parse_event_name (& event , & group , buf ,
678+ event - argv [0 ]);
678679 if (ret )
679- goto out ;
680+ goto parse_error ;
680681 } else {
681682 /* Make a new event name */
682683 if (symbol )
@@ -691,13 +692,14 @@ static int trace_kprobe_create(int argc, const char *argv[])
691692
692693 /* setup a probe */
693694 tk = alloc_trace_kprobe (group , event , addr , symbol , offset , maxactive ,
694- argc , is_return );
695+ argc - 2 , is_return );
695696 if (IS_ERR (tk )) {
696697 ret = PTR_ERR (tk );
697- /* This must return -ENOMEM otherwise there is a bug */
698+ /* This must return -ENOMEM, else there is a bug */
698699 WARN_ON_ONCE (ret != - ENOMEM );
699- goto out ;
700+ goto out ; /* We know tk is not allocated */
700701 }
702+ argc -= 2 ; argv += 2 ;
701703
702704 /* parse arguments */
703705 for (i = 0 ; i < argc && i < MAX_TRACE_ARGS ; i ++ ) {
@@ -707,19 +709,32 @@ static int trace_kprobe_create(int argc, const char *argv[])
707709 goto error ;
708710 }
709711
712+ trace_probe_log_set_index (i + 2 );
710713 ret = traceprobe_parse_probe_arg (& tk -> tp , i , tmp , flags );
711714 kfree (tmp );
712715 if (ret )
713- goto error ;
716+ goto error ; /* This can be -ENOMEM */
714717 }
715718
716719 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 );
718728 goto error ;
729+ }
730+
719731out :
732+ trace_probe_log_clear ();
720733 kfree (symbol );
721734 return ret ;
722735
736+ parse_error :
737+ ret = - EINVAL ;
723738error :
724739 free_trace_kprobe (tk );
725740 goto out ;
0 commit comments