[infiniband] Eliminate variable-length stack allocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
pull/106/head
Michael Brown 2020-02-16 21:25:27 +00:00
parent c625681ca1
commit 6248ac396a
1 changed files with 18 additions and 6 deletions

View File

@ -498,14 +498,21 @@ static struct ib_srp_root_path_parser ib_srp_rp_parser[] = {
static int ib_srp_parse_root_path ( const char *rp_string,
struct ib_srp_root_path *rp ) {
struct ib_srp_root_path_parser *parser;
char rp_string_copy[ strlen ( rp_string ) + 1 ];
char *rp_comp[IB_SRP_NUM_RP_COMPONENTS];
char *rp_string_tmp = rp_string_copy;
char *rp_string_copy;
char *rp_string_tmp;
unsigned int i = 0;
int rc;
/* Create modifiable copy of root path */
rp_string_copy = strdup ( rp_string );
if ( ! rp_string_copy ) {
rc = -ENOMEM;
goto err_strdup;
}
rp_string_tmp = rp_string_copy;
/* Split root path into component parts */
strcpy ( rp_string_copy, rp_string );
while ( 1 ) {
rp_comp[i++] = rp_string_tmp;
if ( i == IB_SRP_NUM_RP_COMPONENTS )
@ -514,7 +521,8 @@ static int ib_srp_parse_root_path ( const char *rp_string,
if ( ! *rp_string_tmp ) {
DBG ( "IBSRP root path \"%s\" too short\n",
rp_string );
return -EINVAL_RP_TOO_SHORT;
rc = -EINVAL_RP_TOO_SHORT;
goto err_split;
}
}
*(rp_string_tmp++) = '\0';
@ -527,11 +535,15 @@ static int ib_srp_parse_root_path ( const char *rp_string,
DBG ( "IBSRP could not parse \"%s\" in root path "
"\"%s\": %s\n", rp_comp[i], rp_string,
strerror ( rc ) );
return rc;
goto err_parse;
}
}
return 0;
err_parse:
err_split:
free ( rp_string_copy );
err_strdup:
return rc;
}
/**