44 * Copyright (c) 2019 Intel Corporation.
55 */
66
7+ #include <ctype.h>
78#include <linux/isst_if.h>
89#include <sys/utsname.h>
910
@@ -2730,6 +2731,43 @@ void parse_cpu_command(char *optarg)
27302731 exit (-1 );
27312732}
27322733
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+
27332771static void parse_cmd_args (int argc , int start , char * * argv )
27342772{
27352773 int opt ;
@@ -2763,18 +2801,21 @@ static void parse_cmd_args(int argc, int start, char **argv)
27632801 auto_mode = 1 ;
27642802 break ;
27652803 case 'b' :
2804+ check_optarg ("bucket" , 0 );
27662805 fact_bucket = atoi (optarg );
27672806 break ;
27682807 case 'h' :
27692808 cmd_help = 1 ;
27702809 break ;
27712810 case 'l' :
2811+ check_optarg ("level" , 0 );
27722812 tdp_level = atoi (optarg );
27732813 break ;
27742814 case 'o' :
27752815 force_online_offline = 1 ;
27762816 break ;
27772817 case 't' :
2818+ check_optarg ("trl" , 1 );
27782819 sscanf (optarg , "0x%llx" , & fact_trl );
27792820 break ;
27802821 case 'r' :
@@ -2791,35 +2832,42 @@ static void parse_cmd_args(int argc, int start, char **argv)
27912832 break ;
27922833 /* CLOS related */
27932834 case 'c' :
2835+ check_optarg ("clos" , 0 );
27942836 current_clos = atoi (optarg );
27952837 break ;
27962838 case 'd' :
2839+ check_optarg ("desired" , 0 );
27972840 clos_desired = atoi (optarg );
27982841 clos_desired /= isst_get_disp_freq_multiplier ();
27992842 break ;
28002843 case 'e' :
2844+ check_optarg ("epp" , 0 );
28012845 clos_epp = atoi (optarg );
28022846 if (is_skx_based_platform ()) {
28032847 isst_display_error_info_message (1 , "epp can't be specified on this platform" , 0 , 0 );
28042848 exit (0 );
28052849 }
28062850 break ;
28072851 case 'n' :
2852+ check_optarg ("min" , 0 );
28082853 clos_min = atoi (optarg );
28092854 clos_min /= isst_get_disp_freq_multiplier ();
28102855 break ;
28112856 case 'm' :
2857+ check_optarg ("max" , 0 );
28122858 clos_max = atoi (optarg );
28132859 clos_max /= isst_get_disp_freq_multiplier ();
28142860 break ;
28152861 case 'p' :
2862+ check_optarg ("priority" , 0 );
28162863 clos_priority_type = atoi (optarg );
28172864 if (is_skx_based_platform () && !clos_priority_type ) {
28182865 isst_display_error_info_message (1 , "Invalid clos priority type: proportional for this platform" , 0 , 0 );
28192866 exit (0 );
28202867 }
28212868 break ;
28222869 case 'w' :
2870+ check_optarg ("weight" , 0 );
28232871 clos_prop_prio = atoi (optarg );
28242872 if (is_skx_based_platform ()) {
28252873 isst_display_error_info_message (1 , "weight can't be specified on this platform" , 0 , 0 );
0 commit comments