@@ -737,10 +737,13 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
737737 struct format cfg = {
738738 .fmt = "normal" ,
739739 };
740+ #ifdef CONFIG_JSONC
740741 bool is_json = false;
741742 struct json_object * root ;
742743 struct json_object * logPages ;
744+ #endif /* CONFIG_JSONC */
743745 struct nvme_dev * dev ;
746+ nvme_print_flags_t flags ;
744747
745748 OPT_ARGS (opts ) = {
746749 OPT_FMT ("format" , 'f' , & cfg .fmt , fmt ),
@@ -753,8 +756,16 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
753756 return -1 ;
754757 }
755758
759+ err = validate_output_format (nvme_cfg .output_format , & flags );
760+ if (err < 0 ) {
761+ nvme_show_error ("Invalid output format" );
762+ return err ;
763+ }
764+
765+ #ifdef CONFIG_JSONC
756766 if (!strcmp (cfg .fmt , "json" ))
757767 is_json = true;
768+ #endif /* CONFIG_JSONC */
758769
759770 err = nvme_get_log_smart (dev_fd (dev ), 0xffffffff , false, & smart_log );
760771 if (!err ) {
@@ -764,6 +775,7 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
764775 tempSensors [i ] = le16_to_cpu (smart_log .temp_sensor [i ]);
765776 tempSensors [i ] = tempSensors [i ] ? tempSensors [i ] - 273 : 0 ;
766777 }
778+ #ifdef CONFIG_JSONC
767779 if (is_json ) {
768780 struct json_object * stats = json_create_object ();
769781 char tempstr [64 ] = { 0 };
@@ -786,11 +798,14 @@ static int micron_temp_stats(int argc, char **argv, struct command *cmd,
786798 printf ("\n" );
787799 json_free_object (root );
788800 } else {
801+ #endif /* CONFIG_JSONC */
789802 printf ("Micron temperature information:\n" );
790803 printf ("%-10s : %u C\n" , "Current Composite Temperature" , temperature );
791804 for (i = 0 ; i < SensorCount && tempSensors [i ]; i ++ )
792805 printf ("%-10s%d : %u C\n" , "Temperature Sensor #" , i + 1 , tempSensors [i ]);
806+ #ifdef CONFIG_JSONC
793807 }
808+ #endif /* CONFIG_JSONC */
794809 }
795810 dev_close (dev );
796811 return err ;
@@ -812,7 +827,9 @@ static int micron_pcie_stats(int argc, char **argv,
812827 struct nvme_passthru_cmd admin_cmd = { 0 };
813828 enum eDriveModel eModel = UNKNOWN_MODEL ;
814829 char * res ;
830+ #ifdef CONFIG_JSONC
815831 bool is_json = true;
832+ #endif /* CONFIG_JSONC */
816833 bool counters = false;
817834 struct format {
818835 char * fmt ;
@@ -840,6 +857,7 @@ static int micron_pcie_stats(int argc, char **argv,
840857 __u16 ecrc_error ;
841858 __u16 unsupported_request_error ;
842859 } pcie_error_counters = { 0 };
860+ nvme_print_flags_t flags ;
843861
844862 struct {
845863 char * err ;
@@ -905,8 +923,16 @@ static int micron_pcie_stats(int argc, char **argv,
905923 goto out ;
906924 }
907925
926+ err = validate_output_format (cfg .fmt , & flags );
927+ if (err < 0 ) {
928+ nvme_show_error ("Invalid output format" );
929+ return err ;
930+ }
931+
932+ #ifdef CONFIG_JSONC
908933 if (!strcmp (cfg .fmt , "normal" ))
909934 is_json = false;
935+ #endif /* CONFIG_JSONC */
910936
911937 if (eModel == M5407 ) {
912938 admin_cmd .opcode = 0xD6 ;
@@ -987,6 +1013,7 @@ static int micron_pcie_stats(int argc, char **argv,
9871013 uncorrectable_errors = (__u32 )strtol (uncorrectable , NULL , 16 );
9881014
9891015print_stats :
1016+ #ifdef CONFIG_JSONC
9901017 if (is_json ) {
9911018 struct json_object * root = json_create_object ();
9921019 struct json_object * pcieErrors = json_create_array ();
@@ -1009,6 +1036,9 @@ static int micron_pcie_stats(int argc, char **argv,
10091036 printf ("\n" );
10101037 json_free_object (root );
10111038 } else if (counters == true) {
1039+ #else /* CONFIG_JSONC */
1040+ if (counters == true) {
1041+ #endif /* CONFIG_JSONC */
10121042 __u8 * pcounter = (__u8 * )& pcie_error_counters ;
10131043
10141044 for (i = 0 ; i < ARRAY_SIZE (pcie_correctable_errors ); i ++ )
@@ -1324,73 +1354,90 @@ fb_log_page[] = {
13241354
13251355static void print_smart_cloud_health_log (__u8 * buf , bool is_json )
13261356{
1357+ #ifdef CONFIG_JSONC
13271358 struct json_object * root ;
13281359 struct json_object * logPages ;
1360+ #endif /* CONFIG_JSONC */
13291361 struct json_object * stats = NULL ;
13301362 int field_count = ARRAY_SIZE (ocp_c0_log_page );
13311363
1364+ #ifdef CONFIG_JSONC
13321365 if (is_json ) {
13331366 root = json_create_object ();
13341367 stats = json_create_object ();
13351368 logPages = json_create_array ();
13361369 json_object_add_value_array (root , "OCP SMART Cloud Health Log: 0xC0" ,
13371370 logPages );
13381371 }
1372+ #endif /* CONFIG_JSONC */
13391373
13401374 generic_structure_parser (buf , ocp_c0_log_page , field_count , stats , 0 , NULL );
13411375
1376+ #ifdef CONFIG_JSONC
13421377 if (is_json ) {
13431378 json_array_add_value_object (logPages , stats );
13441379 json_print_object (root , NULL );
13451380 printf ("\n" );
13461381 json_free_object (root );
13471382 }
1383+ #endif /* CONFIG_JSONC */
13481384}
13491385
13501386static void print_nand_stats_fb (__u8 * buf , __u8 * buf2 , __u8 nsze , bool is_json , __u8 spec )
13511387{
1388+ #ifdef CONFIG_JSONC
13521389 struct json_object * root ;
13531390 struct json_object * logPages ;
1391+ #endif /* CONFIG_JSONC */
13541392 struct json_object * stats = NULL ;
13551393 int field_count = ARRAY_SIZE (fb_log_page );
13561394
1395+ #ifdef CONFIG_JSONC
13571396 if (is_json ) {
13581397 root = json_create_object ();
13591398 stats = json_create_object ();
13601399 logPages = json_create_array ();
13611400 json_object_add_value_array (root , "Extended Smart Log Page : 0xFB" ,
13621401 logPages );
13631402 }
1403+ #endif /* CONFIG_JSONC */
13641404
13651405 generic_structure_parser (buf , fb_log_page , field_count , stats , spec , NULL );
13661406
13671407 /* print last three entries from D0 log page */
13681408 if (buf2 ) {
13691409 init_d0_log_page (buf2 , nsze );
13701410
1411+ #ifdef CONFIG_JSONC
13711412 if (is_json ) {
13721413 for (int i = 0 ; i < 7 ; i ++ )
13731414 json_object_add_value_string (stats ,
13741415 d0_log_page [i ].field ,
13751416 d0_log_page [i ].datastr );
13761417 } else {
1418+ #endif /* CONFIG_JSONC */
13771419 for (int i = 0 ; i < 7 ; i ++ )
13781420 printf ("%-40s : %s\n" , d0_log_page [i ].field , d0_log_page [i ].datastr );
1421+ #ifdef CONFIG_JSONC
13791422 }
1423+ #endif /* CONFIG_JSONC */
13801424 }
13811425
1426+ #ifdef CONFIG_JSONC
13821427 if (is_json ) {
13831428 json_array_add_value_object (logPages , stats );
13841429 json_print_object (root , NULL );
13851430 printf ("\n" );
13861431 json_free_object (root );
13871432 }
1433+ #endif /* CONFIG_JSONC */
13881434}
13891435
13901436static void print_nand_stats_d0 (__u8 * buf , __u8 oacs , bool is_json )
13911437{
13921438 init_d0_log_page (buf , oacs );
13931439
1440+ #ifdef CONFIG_JSONC
13941441 if (is_json ) {
13951442 struct json_object * root = json_create_object ();
13961443 struct json_object * stats = json_create_object ();
@@ -1410,9 +1457,12 @@ static void print_nand_stats_d0(__u8 *buf, __u8 oacs, bool is_json)
14101457 printf ("\n" );
14111458 json_free_object (root );
14121459 } else {
1460+ #endif /* CONFIG_JSONC */
14131461 for (int i = 0 ; i < 7 ; i ++ )
14141462 printf ("%-40s : %s\n" , d0_log_page [i ].field , d0_log_page [i ].datastr );
1463+ #ifdef CONFIG_JSONC
14151464 }
1465+ #endif /* CONFIG_JSONC */
14161466}
14171467
14181468static bool nsze_from_oacs ; /* read nsze for now from idd[4059] */
@@ -1502,28 +1552,36 @@ static int micron_nand_stats(int argc, char **argv,
15021552
15031553static void print_ext_smart_logs_e1 (__u8 * buf , bool is_json )
15041554{
1555+ #ifdef CONFIG_JSONC
15051556 struct json_object * root ;
15061557 struct json_object * logPages ;
1558+ #endif /* CONFIG_JSONC */
15071559 struct json_object * stats = NULL ;
15081560 int field_count = ARRAY_SIZE (e1_log_page );
15091561
1562+ #ifdef CONFIG_JSONC
15101563 if (is_json ) {
15111564 root = json_create_object ();
15121565 stats = json_create_object ();
15131566 logPages = json_create_array ();
15141567 json_object_add_value_array (root , "SMART Extended Log:0xE1" , logPages );
15151568 } else {
1569+ #endif /* CONFIG_JSONC */
15161570 printf ("SMART Extended Log:0xE1\n" );
1571+ #ifdef CONFIG_JSONC
15171572 }
1573+ #endif /* CONFIG_JSONC */
15181574
15191575 generic_structure_parser (buf , e1_log_page , field_count , stats , 0 , NULL );
15201576
1577+ #ifdef CONFIG_JSONC
15211578 if (is_json ) {
15221579 json_array_add_value_object (logPages , stats );
15231580 json_print_object (root , NULL );
15241581 printf ("\n" );
15251582 json_free_object (root );
15261583 }
1584+ #endif /* CONFIG_JSONC */
15271585}
15281586
15291587static int micron_smart_ext_log (int argc , char * * argv ,
@@ -1546,12 +1604,20 @@ static int micron_smart_ext_log(int argc, char **argv,
15461604 OPT_FMT ("format" , 'f' , & cfg .fmt , fmt ),
15471605 OPT_END ()
15481606 };
1607+ nvme_print_flags_t flags ;
15491608
15501609 err = parse_and_open (& dev , argc , argv , desc , opts );
15511610 if (err ) {
15521611 printf ("\nDevice not found\n" );
15531612 return -1 ;
15541613 }
1614+
1615+ err = validate_output_format (nvme_cfg .output_format , & flags );
1616+ if (err < 0 ) {
1617+ nvme_show_error ("Invalid output format" );
1618+ return err ;
1619+ }
1620+
15551621 if (!strcmp (cfg .fmt , "normal" ))
15561622 is_json = false;
15571623
@@ -1949,13 +2015,16 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
19492015 unsigned char bs_ver_minor ;
19502016 } dinfo = { 0 };
19512017 enum eDriveModel model = UNKNOWN_MODEL ;
2018+ #ifdef CONFIG_JSONC
19522019 bool is_json = false;
19532020 struct json_object * root , * driveInfo ;
2021+ #endif /* CONFIG_JSONC */
19542022 struct nvme_dev * dev ;
19552023 struct format {
19562024 char * fmt ;
19572025 };
19582026 int err = 0 ;
2027+ nvme_print_flags_t flags ;
19592028
19602029 const char * fmt = "output format normal" ;
19612030 struct format cfg = {
@@ -1977,8 +2046,16 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
19772046 return -1 ;
19782047 }
19792048
2049+ err = validate_output_format (cfg .fmt , & flags );
2050+ if (err < 0 ) {
2051+ nvme_show_error ("Invalid output format" );
2052+ return err ;
2053+ }
2054+
2055+ #ifdef CONFIG_JSONC
19802056 if (!strcmp (cfg .fmt , "json" ))
19812057 is_json = true;
2058+ #endif /* CONFIG_JSONC */
19822059
19832060 if (model == M5407 ) {
19842061 admin_cmd .opcode = 0xD4 ,
@@ -2003,6 +2080,7 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
20032080 dinfo .ftl_unit_size = ctrl .vs [822 ];
20042081 }
20052082
2083+ #ifdef CONFIG_JSONC
20062084 if (is_json ) {
20072085 struct json_object * pinfo = json_create_object ();
20082086 char tempstr [64 ] = { 0 };
@@ -2028,6 +2106,7 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
20282106 printf ("\n" );
20292107 json_free_object (root );
20302108 } else {
2109+ #endif /* CONFIG_JSONC */
20312110 printf ("Drive Hardware Version: %u.%u\n" ,
20322111 dinfo .hw_ver_major , dinfo .hw_ver_minor );
20332112
@@ -2037,7 +2116,9 @@ static int micron_drive_info(int argc, char **argv, struct command *cmd,
20372116 if (dinfo .bs_ver_major || dinfo .bs_ver_minor )
20382117 printf ("Boot Spec.Version: %u.%u\n" ,
20392118 dinfo .bs_ver_major , dinfo .bs_ver_minor );
2119+ #ifdef CONFIG_JSONC
20402120 }
2121+ #endif /* CONFIG_JSONC */
20412122
20422123 dev_close (dev );
20432124 return 0 ;
0 commit comments