4
4
* Copyright (c) 2019 Intel Corporation.
5
5
*/
6
6
7
+ #include <ctype.h>
7
8
#include <linux/isst_if.h>
8
9
#include <sys/utsname.h>
9
10
@@ -2730,6 +2731,43 @@ void parse_cpu_command(char *optarg)
2730
2731
exit (-1 );
2731
2732
}
2732
2733
2734
+ static void check_optarg (char * option , int hex )
2735
+ {
2736
+ if (optarg ) {
2737
+ char * start = optarg ;
2738
+ int i ;
2739
+
2740
+ if (hex && strlen (optarg ) < 3 ) {
2741
+ /* At least 0x plus one character must be present */
2742
+ fprintf (stderr , "malformed arguments for:%s [%s]\n" , option , optarg );
2743
+ exit (0 );
2744
+ }
2745
+
2746
+ if (hex ) {
2747
+ if (optarg [0 ] != '0' || tolower (optarg [1 ]) != 'x' ) {
2748
+ fprintf (stderr , "malformed arguments for:%s [%s]\n" ,
2749
+ option , optarg );
2750
+ exit (0 );
2751
+ }
2752
+ start = & optarg [2 ];
2753
+ }
2754
+
2755
+ for (i = 0 ; i < strlen (start ); ++ i ) {
2756
+ if (hex ) {
2757
+ if (!isxdigit (start [i ])) {
2758
+ fprintf (stderr , "malformed arguments for:%s [%s]\n" ,
2759
+ option , optarg );
2760
+ exit (0 );
2761
+ }
2762
+ } else if (!isdigit (start [i ])) {
2763
+ fprintf (stderr , "malformed arguments for:%s [%s]\n" ,
2764
+ option , optarg );
2765
+ exit (0 );
2766
+ }
2767
+ }
2768
+ }
2769
+ }
2770
+
2733
2771
static void parse_cmd_args (int argc , int start , char * * argv )
2734
2772
{
2735
2773
int opt ;
@@ -2763,18 +2801,21 @@ static void parse_cmd_args(int argc, int start, char **argv)
2763
2801
auto_mode = 1 ;
2764
2802
break ;
2765
2803
case 'b' :
2804
+ check_optarg ("bucket" , 0 );
2766
2805
fact_bucket = atoi (optarg );
2767
2806
break ;
2768
2807
case 'h' :
2769
2808
cmd_help = 1 ;
2770
2809
break ;
2771
2810
case 'l' :
2811
+ check_optarg ("level" , 0 );
2772
2812
tdp_level = atoi (optarg );
2773
2813
break ;
2774
2814
case 'o' :
2775
2815
force_online_offline = 1 ;
2776
2816
break ;
2777
2817
case 't' :
2818
+ check_optarg ("trl" , 1 );
2778
2819
sscanf (optarg , "0x%llx" , & fact_trl );
2779
2820
break ;
2780
2821
case 'r' :
@@ -2791,35 +2832,42 @@ static void parse_cmd_args(int argc, int start, char **argv)
2791
2832
break ;
2792
2833
/* CLOS related */
2793
2834
case 'c' :
2835
+ check_optarg ("clos" , 0 );
2794
2836
current_clos = atoi (optarg );
2795
2837
break ;
2796
2838
case 'd' :
2839
+ check_optarg ("desired" , 0 );
2797
2840
clos_desired = atoi (optarg );
2798
2841
clos_desired /= isst_get_disp_freq_multiplier ();
2799
2842
break ;
2800
2843
case 'e' :
2844
+ check_optarg ("epp" , 0 );
2801
2845
clos_epp = atoi (optarg );
2802
2846
if (is_skx_based_platform ()) {
2803
2847
isst_display_error_info_message (1 , "epp can't be specified on this platform" , 0 , 0 );
2804
2848
exit (0 );
2805
2849
}
2806
2850
break ;
2807
2851
case 'n' :
2852
+ check_optarg ("min" , 0 );
2808
2853
clos_min = atoi (optarg );
2809
2854
clos_min /= isst_get_disp_freq_multiplier ();
2810
2855
break ;
2811
2856
case 'm' :
2857
+ check_optarg ("max" , 0 );
2812
2858
clos_max = atoi (optarg );
2813
2859
clos_max /= isst_get_disp_freq_multiplier ();
2814
2860
break ;
2815
2861
case 'p' :
2862
+ check_optarg ("priority" , 0 );
2816
2863
clos_priority_type = atoi (optarg );
2817
2864
if (is_skx_based_platform () && !clos_priority_type ) {
2818
2865
isst_display_error_info_message (1 , "Invalid clos priority type: proportional for this platform" , 0 , 0 );
2819
2866
exit (0 );
2820
2867
}
2821
2868
break ;
2822
2869
case 'w' :
2870
+ check_optarg ("weight" , 0 );
2823
2871
clos_prop_prio = atoi (optarg );
2824
2872
if (is_skx_based_platform ()) {
2825
2873
isst_display_error_info_message (1 , "weight can't be specified on this platform" , 0 , 0 );
0 commit comments