@@ -2128,11 +2128,14 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21282128 uint16_t ncols = le16_to_cpu (lane -> ncols );
21292129 char * printable = NULL ;
21302130 char * printable_start = NULL ;
2131- struct json_object * eye_array = json_create_array () ;
2131+ struct json_object * eye_array = NULL ;
21322132
21332133 if (nrows == 0 || ncols == 0 )
21342134 return NULL ;
21352135
2136+ eye_array = json_create_array ();
2137+ if (!eye_array )
2138+ return NULL ;
21362139 /*
21372140 * Allocate buffer for full printable string (with newlines)
21382141 * +1 for null terminator
@@ -2141,21 +2144,13 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21412144 printable_start = printable ;
21422145
21432146 if (!printable )
2144- return NULL ;
2145-
2146- if (!eye_array ) {
2147- free (printable );
2148- return NULL ;
2149- }
2147+ goto fail_free_eye_array ;
21502148
21512149 for (int i = 0 ; i < nrows ; i ++ ) {
21522150 char * row = malloc (ncols + 1 );
21532151
2154- if (!row ) {
2155- /* Cleanup on failure */
2156- free (printable_start );
2157- return NULL ;
2158- }
2152+ if (!row )
2153+ goto fail_free_eye_printable ;
21592154
21602155 for (int j = 0 ; j < ncols ; j ++ ) {
21612156 char ch = eye [i * ncols + j ];
@@ -2175,6 +2170,13 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21752170 obj_add_array (r , "printable_eye" , eye_array );
21762171
21772172 return printable_start ;
2173+
2174+ fail_free_eye_printable :
2175+ free (printable );
2176+ fail_free_eye_array :
2177+ json_free_object (eye_array );
2178+
2179+ return NULL ;
21782180}
21792181
21802182static void json_phy_rx_eom_descs (struct nvme_phy_rx_eom_log * log ,
@@ -2189,12 +2191,20 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21892191
21902192 for (i = 0 ; i < num_descs ; i ++ ) {
21912193 struct nvme_eom_lane_desc * desc = p ;
2194+ _cleanup_free_ char * hexstr = NULL ;
21922195 unsigned char * vsdata = NULL ;
21932196 unsigned int vsdataoffset = 0 ;
2194- struct json_object * jdesc = json_create_object ();
2195- uint16_t nrows = le16_to_cpu (desc -> nrows );
2196- uint16_t ncols = le16_to_cpu (desc -> ncols );
2197- uint16_t edlen = le16_to_cpu (desc -> edlen );
2197+ uint16_t nrows , ncols , edlen ;
2198+ struct json_object * jdesc ;
2199+ char * hexdata ;
2200+
2201+ jdesc = json_create_object ();
2202+ if (!desc )
2203+ return ;
2204+
2205+ nrows = le16_to_cpu (desc -> nrows );
2206+ ncols = le16_to_cpu (desc -> ncols );
2207+ edlen = le16_to_cpu (desc -> edlen );
21982208
21992209 obj_add_uint (jdesc , "lid" , desc -> mstatus );
22002210 obj_add_uint (jdesc , "lane" , desc -> lane );
@@ -2214,16 +2224,18 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
22142224 continue ;
22152225
22162226 /* 2 hex chars + space per byte */
2217- _cleanup_free_ char * hexstr = malloc (edlen * 3 + 1 );
2227+ hexstr = malloc (edlen * 3 + 1 );
22182228
2219- if (!hexstr )
2229+ if (!hexstr ) {
2230+ json_free_object (jdesc );
22202231 return ;
2232+ }
22212233
22222234 /* Hex dump Vendor Specific Eye Data */
22232235 vsdataoffset = (nrows * ncols ) + sizeof (struct nvme_eom_lane_desc );
22242236 vsdata = (unsigned char * )((unsigned char * )desc + vsdataoffset );
22252237
2226- char * hexdata = hexstr ;
2238+ hexdata = hexstr ;
22272239
22282240 for (int offset = 0 ; offset < edlen ; offset ++ )
22292241 hexdata += sprintf (hexdata , "%02X " , vsdata [offset ]);
0 commit comments