Commit e003310a76211c2a9bb1939db4633830594c35ba
Committed by
Tom Rini
1 parent
63c5bf48d5
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
bootstage: Tidy up error return values
We should return a proper error number instead of just -1. This helps the caller to determine what when wrong. Update a few functions to fix this. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 2 changed files with 14 additions and 12 deletions Side-by-side Diff
common/bootstage.c
... | ... | @@ -264,7 +264,7 @@ |
264 | 264 | */ |
265 | 265 | bootstage = fdt_add_subnode(blob, 0, "bootstage"); |
266 | 266 | if (bootstage < 0) |
267 | - return -1; | |
267 | + return -EINVAL; | |
268 | 268 | |
269 | 269 | /* |
270 | 270 | * Insert the timings to the device tree in the reverse order so |
271 | 271 | |
... | ... | @@ -284,13 +284,13 @@ |
284 | 284 | /* add properties to the node. */ |
285 | 285 | if (fdt_setprop_string(blob, node, "name", |
286 | 286 | get_record_name(buf, sizeof(buf), rec))) |
287 | - return -1; | |
287 | + return -EINVAL; | |
288 | 288 | |
289 | 289 | /* Check if this is a 'mark' or 'accum' record */ |
290 | 290 | if (fdt_setprop_cell(blob, node, |
291 | 291 | rec->start_us ? "accum" : "mark", |
292 | 292 | rec->time_us)) |
293 | - return -1; | |
293 | + return -EINVAL; | |
294 | 294 | } |
295 | 295 | |
296 | 296 | return 0; |
... | ... | @@ -371,7 +371,7 @@ |
371 | 371 | |
372 | 372 | if (hdr + 1 > (struct bootstage_hdr *)end) { |
373 | 373 | debug("%s: Not enough space for bootstage hdr\n", __func__); |
374 | - return -1; | |
374 | + return -ENOSPC; | |
375 | 375 | } |
376 | 376 | |
377 | 377 | /* Write an arbitrary version number */ |
... | ... | @@ -404,7 +404,7 @@ |
404 | 404 | /* Check for buffer overflow */ |
405 | 405 | if (ptr > end) { |
406 | 406 | debug("%s: Not enough space for bootstage stash\n", __func__); |
407 | - return -1; | |
407 | + return -ENOSPC; | |
408 | 408 | } |
409 | 409 | |
410 | 410 | /* Update total data size */ |
411 | 411 | |
412 | 412 | |
413 | 413 | |
414 | 414 | |
415 | 415 | |
... | ... | @@ -428,37 +428,37 @@ |
428 | 428 | |
429 | 429 | if (hdr + 1 > (struct bootstage_hdr *)end) { |
430 | 430 | debug("%s: Not enough space for bootstage hdr\n", __func__); |
431 | - return -1; | |
431 | + return -EPERM; | |
432 | 432 | } |
433 | 433 | |
434 | 434 | if (hdr->magic != BOOTSTAGE_MAGIC) { |
435 | 435 | debug("%s: Invalid bootstage magic\n", __func__); |
436 | - return -1; | |
436 | + return -ENOENT; | |
437 | 437 | } |
438 | 438 | |
439 | 439 | if (ptr + hdr->size > end) { |
440 | 440 | debug("%s: Bootstage data runs past buffer end\n", __func__); |
441 | - return -1; | |
441 | + return -ENOSPC; | |
442 | 442 | } |
443 | 443 | |
444 | 444 | if (hdr->count * sizeof(*rec) > hdr->size) { |
445 | 445 | debug("%s: Bootstage has %d records needing %lu bytes, but " |
446 | 446 | "only %d bytes is available\n", __func__, hdr->count, |
447 | 447 | (ulong)hdr->count * sizeof(*rec), hdr->size); |
448 | - return -1; | |
448 | + return -ENOSPC; | |
449 | 449 | } |
450 | 450 | |
451 | 451 | if (hdr->version != BOOTSTAGE_VERSION) { |
452 | 452 | debug("%s: Bootstage data version %#0x unrecognised\n", |
453 | 453 | __func__, hdr->version); |
454 | - return -1; | |
454 | + return -EINVAL; | |
455 | 455 | } |
456 | 456 | |
457 | 457 | if (data->rec_count + hdr->count > RECORD_COUNT) { |
458 | 458 | debug("%s: Bootstage has %d records, we have space for %d\n" |
459 | 459 | "- please increase CONFIG_BOOTSTAGE_USER_COUNT\n", |
460 | 460 | __func__, hdr->count, RECORD_COUNT - data->rec_count); |
461 | - return -1; | |
461 | + return -ENOSPC; | |
462 | 462 | } |
463 | 463 | |
464 | 464 | ptr += sizeof(*hdr); |
include/bootstage.h
... | ... | @@ -329,7 +329,9 @@ |
329 | 329 | * |
330 | 330 | * @param base Base address of memory buffer |
331 | 331 | * @param size Size of memory buffer (-1 if unknown) |
332 | - * @return 0 if unstashed ok, -1 if bootstage info not found, or out of space | |
332 | + * @return 0 if unstashed ok, -ENOENT if bootstage info not found, -ENOSPC if | |
333 | + * there is not space for read the stacked data, or other error if | |
334 | + * something else went wrong | |
333 | 335 | */ |
334 | 336 | int bootstage_unstash(void *base, int size); |
335 | 337 |