@@ -540,26 +540,34 @@ static int __parse_bitfield_probe_arg(const char *bf,
540
540
}
541
541
542
542
/* String length checking wrapper */
543
- static int traceprobe_parse_probe_arg_body (char * arg , ssize_t * size ,
543
+ static int traceprobe_parse_probe_arg_body (const char * argv , ssize_t * size ,
544
544
struct probe_arg * parg , unsigned int flags , int offset )
545
545
{
546
546
struct fetch_insn * code , * scode , * tmp = NULL ;
547
547
char * t , * t2 , * t3 ;
548
+ char * arg ;
548
549
int ret , len ;
549
550
551
+ arg = kstrdup (argv , GFP_KERNEL );
552
+ if (!arg )
553
+ return - ENOMEM ;
554
+
555
+ ret = - EINVAL ;
550
556
len = strlen (arg );
551
557
if (len > MAX_ARGSTR_LEN ) {
552
558
trace_probe_log_err (offset , ARG_TOO_LONG );
553
- return - EINVAL ;
559
+ goto out ;
554
560
} else if (len == 0 ) {
555
561
trace_probe_log_err (offset , NO_ARG_BODY );
556
- return - EINVAL ;
562
+ goto out ;
557
563
}
558
564
565
+ ret = - ENOMEM ;
559
566
parg -> comm = kstrdup (arg , GFP_KERNEL );
560
567
if (!parg -> comm )
561
- return - ENOMEM ;
568
+ goto out ;
562
569
570
+ ret = - EINVAL ;
563
571
t = strchr (arg , ':' );
564
572
if (t ) {
565
573
* t = '\0' ;
@@ -571,22 +579,22 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
571
579
offset += t2 + strlen (t2 ) - arg ;
572
580
trace_probe_log_err (offset ,
573
581
ARRAY_NO_CLOSE );
574
- return - EINVAL ;
582
+ goto out ;
575
583
} else if (t3 [1 ] != '\0' ) {
576
584
trace_probe_log_err (offset + t3 + 1 - arg ,
577
585
BAD_ARRAY_SUFFIX );
578
- return - EINVAL ;
586
+ goto out ;
579
587
}
580
588
* t3 = '\0' ;
581
589
if (kstrtouint (t2 , 0 , & parg -> count ) || !parg -> count ) {
582
590
trace_probe_log_err (offset + t2 - arg ,
583
591
BAD_ARRAY_NUM );
584
- return - EINVAL ;
592
+ goto out ;
585
593
}
586
594
if (parg -> count > MAX_ARRAY_LEN ) {
587
595
trace_probe_log_err (offset + t2 - arg ,
588
596
ARRAY_TOO_BIG );
589
- return - EINVAL ;
597
+ goto out ;
590
598
}
591
599
}
592
600
}
@@ -598,36 +606,38 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
598
606
if (strcmp (arg , "$comm" ) == 0 || strncmp (arg , "\\\"" , 2 ) == 0 ) {
599
607
/* The type of $comm must be "string", and not an array. */
600
608
if (parg -> count || (t && strcmp (t , "string" )))
601
- return - EINVAL ;
609
+ goto out ;
602
610
parg -> type = find_fetch_type ("string" );
603
611
} else
604
612
parg -> type = find_fetch_type (t );
605
613
if (!parg -> type ) {
606
614
trace_probe_log_err (offset + (t ? (t - arg ) : 0 ), BAD_TYPE );
607
- return - EINVAL ;
615
+ goto out ;
608
616
}
609
617
parg -> offset = * size ;
610
618
* size += parg -> type -> size * (parg -> count ?: 1 );
611
619
620
+ ret = - ENOMEM ;
612
621
if (parg -> count ) {
613
622
len = strlen (parg -> type -> fmttype ) + 6 ;
614
623
parg -> fmt = kmalloc (len , GFP_KERNEL );
615
624
if (!parg -> fmt )
616
- return - ENOMEM ;
625
+ goto out ;
617
626
snprintf (parg -> fmt , len , "%s[%d]" , parg -> type -> fmttype ,
618
627
parg -> count );
619
628
}
620
629
621
630
code = tmp = kcalloc (FETCH_INSN_MAX , sizeof (* code ), GFP_KERNEL );
622
631
if (!code )
623
- return - ENOMEM ;
632
+ goto out ;
624
633
code [FETCH_INSN_MAX - 1 ].op = FETCH_OP_END ;
625
634
626
635
ret = parse_probe_arg (arg , parg -> type , & code , & code [FETCH_INSN_MAX - 1 ],
627
636
flags , offset );
628
637
if (ret )
629
638
goto fail ;
630
639
640
+ ret = - EINVAL ;
631
641
/* Store operation */
632
642
if (!strcmp (parg -> type -> name , "string" ) ||
633
643
!strcmp (parg -> type -> name , "ustring" )) {
@@ -636,7 +646,6 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
636
646
code -> op != FETCH_OP_DATA ) {
637
647
trace_probe_log_err (offset + (t ? (t - arg ) : 0 ),
638
648
BAD_STRING );
639
- ret = - EINVAL ;
640
649
goto fail ;
641
650
}
642
651
if ((code -> op == FETCH_OP_IMM || code -> op == FETCH_OP_COMM ||
@@ -650,7 +659,6 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
650
659
code ++ ;
651
660
if (code -> op != FETCH_OP_NOP ) {
652
661
trace_probe_log_err (offset , TOO_MANY_OPS );
653
- ret = - EINVAL ;
654
662
goto fail ;
655
663
}
656
664
}
@@ -672,7 +680,6 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
672
680
code ++ ;
673
681
if (code -> op != FETCH_OP_NOP ) {
674
682
trace_probe_log_err (offset , TOO_MANY_OPS );
675
- ret = - EINVAL ;
676
683
goto fail ;
677
684
}
678
685
code -> op = FETCH_OP_ST_RAW ;
@@ -687,20 +694,19 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
687
694
goto fail ;
688
695
}
689
696
}
697
+ ret = - EINVAL ;
690
698
/* Loop(Array) operation */
691
699
if (parg -> count ) {
692
700
if (scode -> op != FETCH_OP_ST_MEM &&
693
701
scode -> op != FETCH_OP_ST_STRING &&
694
702
scode -> op != FETCH_OP_ST_USTRING ) {
695
703
trace_probe_log_err (offset + (t ? (t - arg ) : 0 ),
696
704
BAD_STRING );
697
- ret = - EINVAL ;
698
705
goto fail ;
699
706
}
700
707
code ++ ;
701
708
if (code -> op != FETCH_OP_NOP ) {
702
709
trace_probe_log_err (offset , TOO_MANY_OPS );
703
- ret = - EINVAL ;
704
710
goto fail ;
705
711
}
706
712
code -> op = FETCH_OP_LP_ARRAY ;
@@ -709,6 +715,7 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
709
715
code ++ ;
710
716
code -> op = FETCH_OP_END ;
711
717
718
+ ret = 0 ;
712
719
/* Shrink down the code buffer */
713
720
parg -> code = kcalloc (code - tmp + 1 , sizeof (* code ), GFP_KERNEL );
714
721
if (!parg -> code )
@@ -724,6 +731,8 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size,
724
731
kfree (code -> data );
725
732
}
726
733
kfree (tmp );
734
+ out :
735
+ kfree (arg );
727
736
728
737
return ret ;
729
738
}
@@ -745,11 +754,11 @@ static int traceprobe_conflict_field_name(const char *name,
745
754
return 0 ;
746
755
}
747
756
748
- int traceprobe_parse_probe_arg (struct trace_probe * tp , int i , char * arg ,
757
+ int traceprobe_parse_probe_arg (struct trace_probe * tp , int i , const char * arg ,
749
758
unsigned int flags )
750
759
{
751
760
struct probe_arg * parg = & tp -> args [i ];
752
- char * body ;
761
+ const char * body ;
753
762
754
763
/* Increment count for freeing args in error case */
755
764
tp -> nr_args ++ ;
0 commit comments