@@ -2124,23 +2124,60 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21242124 struct json_object * r )
21252125{
21262126 char * eye = (char * )lane -> eye_desc ;
2127- char * printable = malloc (lane -> nrows * lane -> ncols + lane -> ncols );
2128- char * printable_start = printable ;
2129- int i , j ;
2127+ uint16_t nrows = le16_to_cpu (lane -> nrows );
2128+ uint16_t ncols = le16_to_cpu (lane -> ncols );
2129+ struct json_object * eye_array = NULL ;
2130+ char * printable_start = NULL ;
2131+ char * printable = NULL ;
2132+
2133+ if (nrows == 0 || ncols == 0 )
2134+ return NULL ;
2135+
2136+ eye_array = json_create_array ();
2137+ if (!eye_array )
2138+ return NULL ;
2139+
2140+ /*
2141+ * Allocate buffer for full printable string (with newlines)
2142+ * +1 for null terminator
2143+ */
2144+ printable = malloc (nrows * ncols + nrows + 1 );
2145+ printable_start = printable ;
21302146
21312147 if (!printable )
2132- goto exit ;
2148+ goto fail_free_eye_array ;
21332149
2134- for (i = 0 ; i < lane -> nrows ; i ++ ) {
2135- for (j = 0 ; j < lane -> ncols ; j ++ , printable ++ )
2136- sprintf (printable , "%c" , eye [i * lane -> ncols + j ]);
2137- sprintf (printable ++ , "\n" );
2150+ for (int i = 0 ; i < nrows ; i ++ ) {
2151+ char * row = malloc (ncols + 1 );
2152+
2153+ if (!row )
2154+ goto fail_free_eye_printable ;
2155+
2156+ for (int j = 0 ; j < ncols ; j ++ ) {
2157+ char ch = eye [i * ncols + j ];
2158+ * printable ++ = ch ;
2159+ row [j ] = ch ;
2160+ }
2161+
2162+ * printable ++ = '\n' ;
2163+ row [ncols ] = '\0' ;
2164+
2165+ array_add_str (eye_array , row );
2166+ free (row );
21382167 }
21392168
2140- obj_add_str (r , "printable_eye" , printable_start );
2169+ * printable = '\0' ;
2170+
2171+ obj_add_array (r , "printable_eye" , eye_array );
21412172
2142- exit :
21432173 return printable_start ;
2174+
2175+ fail_free_eye_printable :
2176+ free (printable );
2177+ fail_free_eye_array :
2178+ json_free_object (eye_array );
2179+
2180+ return NULL ;
21442181}
21452182
21462183static void json_phy_rx_eom_descs (struct nvme_phy_rx_eom_log * log ,
@@ -2155,7 +2192,20 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21552192
21562193 for (i = 0 ; i < num_descs ; i ++ ) {
21572194 struct nvme_eom_lane_desc * desc = p ;
2158- struct json_object * jdesc = json_create_object ();
2195+ _cleanup_free_ char * hexstr = NULL ;
2196+ unsigned char * vsdata = NULL ;
2197+ unsigned int vsdataoffset = 0 ;
2198+ uint16_t nrows , ncols , edlen ;
2199+ struct json_object * jdesc ;
2200+ char * hexdata ;
2201+
2202+ jdesc = json_create_object ();
2203+ if (!desc )
2204+ return ;
2205+
2206+ nrows = le16_to_cpu (desc -> nrows );
2207+ ncols = le16_to_cpu (desc -> ncols );
2208+ edlen = le16_to_cpu (desc -> edlen );
21592209
21602210 obj_add_uint (jdesc , "lid" , desc -> mstatus );
21612211 obj_add_uint (jdesc , "lane" , desc -> lane );
@@ -2164,14 +2214,36 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21642214 obj_add_uint (jdesc , "bottom" , le16_to_cpu (desc -> bottom ));
21652215 obj_add_uint (jdesc , "left" , le16_to_cpu (desc -> left ));
21662216 obj_add_uint (jdesc , "right" , le16_to_cpu (desc -> right ));
2167- obj_add_uint (jdesc , "nrows" , le16_to_cpu ( desc -> nrows ) );
2168- obj_add_uint (jdesc , "ncols" , le16_to_cpu ( desc -> ncols ) );
2169- obj_add_uint (jdesc , "edlen" , le16_to_cpu ( desc -> edlen ) );
2217+ obj_add_uint (jdesc , "nrows" , nrows );
2218+ obj_add_uint (jdesc , "ncols" , ncols );
2219+ obj_add_uint (jdesc , "edlen" , edlen );
21702220
21712221 if (NVME_EOM_ODP_PEFP (log -> odp ))
2172- allocated_eyes [i ] = json_eom_printable_eye (desc , r );
2222+ allocated_eyes [i ] = json_eom_printable_eye (desc , jdesc );
2223+
2224+ if (edlen == 0 )
2225+ continue ;
2226+
2227+ /* 2 hex chars + space per byte */
2228+ hexstr = malloc (edlen * 3 + 1 );
2229+
2230+ if (!hexstr ) {
2231+ json_free_object (jdesc );
2232+ return ;
2233+ }
2234+
2235+ /* Hex dump Vendor Specific Eye Data */
2236+ vsdataoffset = (nrows * ncols ) + sizeof (struct nvme_eom_lane_desc );
2237+ vsdata = (unsigned char * )((unsigned char * )desc + vsdataoffset );
2238+
2239+ hexdata = hexstr ;
2240+
2241+ for (int offset = 0 ; offset < edlen ; offset ++ )
2242+ hexdata += sprintf (hexdata , "%02X " , vsdata [offset ]);
2243+ /* remove trailing space */
2244+ * (hexdata - 1 ) = '\0' ;
21732245
2174- /* Eye Data field is vendor specific, doesn't map to JSON */
2246+ obj_add_str ( jdesc , "vsdata_hex" , hexstr );
21752247
21762248 array_add_obj (descs , jdesc );
21772249
0 commit comments