Commit 6b35460c authored by Marek Vasut's avatar Marek Vasut

mxssb: Rework sb_token_to_long()

In the current setup, the sb_token_to_long() couldn't parse the full
range of unsigned values. Fix this by returning the converted value
via pointer reference and make the sb_token_to_long() return it's
return value properly.
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
parent 06575601
......@@ -474,7 +474,7 @@ static uint8_t sb_command_checksum(struct sb_command *inst)
return csum;
}
static long sb_token_to_long(char *tok)
static int sb_token_to_long(char *tok, long *rid)
{
char *endptr;
long id;
......@@ -498,7 +498,8 @@ static long sb_token_to_long(char *tok)
return -EINVAL;
}
return id;
*rid = id;
return 0;
}
static int sb_build_section(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
......@@ -524,11 +525,10 @@ static int sb_build_section(struct sb_image_ctx *ictx, struct sb_cmd_list *cmd)
}
/* Parse the section number. */
id = sb_token_to_long(tok);
if (id < 0) {
ret = sb_token_to_long(tok, &id);
if (ret) {
fprintf(stderr, "#%i ERR: Malformed section number!\n",
cmd->lineno);
ret = -EINVAL;
goto err_sect;
}
......@@ -692,11 +692,10 @@ static int sb_build_command_load(struct sb_image_ctx *ictx, struct sb_cmd_list *
}
/* Read load destination address. */
dest = sb_token_to_long(tok);
if (dest < 0) {
ret = sb_token_to_long(tok, &dest);
if (ret) {
fprintf(stderr, "#%i ERR: Incorrect LOAD address!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
......@@ -712,13 +711,13 @@ static int sb_build_command_load(struct sb_image_ctx *ictx, struct sb_cmd_list *
if (is_ivt) {
/* Handle IVT. */
struct sb_ivt_header *ivt;
long ivtep = sb_token_to_long(tok);
long ivtep;
ret = sb_token_to_long(tok, &ivtep);
if (ivtep < 0) {
if (ret) {
fprintf(stderr,
"#%i ERR: Incorrect IVT entry point!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
......@@ -805,11 +804,10 @@ static int sb_build_command_fill(struct sb_image_ctx *ictx, struct sb_cmd_list *
}
/* Read fill destination address. */
address = sb_token_to_long(tok);
if (address < 0) {
ret = sb_token_to_long(tok, &address);
if (ret) {
fprintf(stderr, "#%i ERR: Incorrect FILL address!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
......@@ -822,11 +820,10 @@ static int sb_build_command_fill(struct sb_image_ctx *ictx, struct sb_cmd_list *
}
/* Read fill pattern address. */
pattern = sb_token_to_long(tok);
if (pattern < 0) {
ret = sb_token_to_long(tok, &pattern);
if (ret) {
fprintf(stderr, "#%i ERR: Incorrect FILL pattern!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
......@@ -839,11 +836,10 @@ static int sb_build_command_fill(struct sb_image_ctx *ictx, struct sb_cmd_list *
}
/* Read fill pattern address. */
length = sb_token_to_long(tok);
if (length < 0) {
ret = sb_token_to_long(tok, &length);
if (ret) {
fprintf(stderr, "#%i ERR: Incorrect FILL length!\n",
cmd->lineno);
ret = -EINVAL;
goto err;
}
......@@ -920,22 +916,20 @@ static int sb_build_command_jump_call(struct sb_image_ctx *ictx,
}
}
/* Read load destination address. */
dest = sb_token_to_long(tok);
if (dest < 0) {
ret = sb_token_to_long(tok, &dest);
if (ret) {
fprintf(stderr, "#%i ERR: Incorrect %s address!\n",
cmd->lineno, cmdname);
ret = -EINVAL;
goto err;
}
tok = strtok(NULL, " ");
if (tok) {
arg = sb_token_to_long(tok);
if (arg < 0) {
ret = sb_token_to_long(tok, &arg);
if (ret) {
fprintf(stderr,
"#%i ERR: Incorrect %s argument!\n",
cmd->lineno, cmdname);
ret = -EINVAL;
goto err;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment