mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 11:00:27 +03:00
[infiniband] Eliminate variable-length stack allocation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -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,
|
static int ib_srp_parse_root_path ( const char *rp_string,
|
||||||
struct ib_srp_root_path *rp ) {
|
struct ib_srp_root_path *rp ) {
|
||||||
struct ib_srp_root_path_parser *parser;
|
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_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;
|
unsigned int i = 0;
|
||||||
int rc;
|
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 */
|
/* Split root path into component parts */
|
||||||
strcpy ( rp_string_copy, rp_string );
|
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
rp_comp[i++] = rp_string_tmp;
|
rp_comp[i++] = rp_string_tmp;
|
||||||
if ( i == IB_SRP_NUM_RP_COMPONENTS )
|
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 ) {
|
if ( ! *rp_string_tmp ) {
|
||||||
DBG ( "IBSRP root path \"%s\" too short\n",
|
DBG ( "IBSRP root path \"%s\" too short\n",
|
||||||
rp_string );
|
rp_string );
|
||||||
return -EINVAL_RP_TOO_SHORT;
|
rc = -EINVAL_RP_TOO_SHORT;
|
||||||
|
goto err_split;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(rp_string_tmp++) = '\0';
|
*(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 "
|
DBG ( "IBSRP could not parse \"%s\" in root path "
|
||||||
"\"%s\": %s\n", rp_comp[i], rp_string,
|
"\"%s\": %s\n", rp_comp[i], rp_string,
|
||||||
strerror ( rc ) );
|
strerror ( rc ) );
|
||||||
return rc;
|
goto err_parse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
err_parse:
|
||||||
|
err_split:
|
||||||
|
free ( rp_string_copy );
|
||||||
|
err_strdup:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user