Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tools/rimage/src/elf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ static struct name_val p_flags[] = {
*
* @param elf elf file structure
* @param msg error message
* @param error error code to return
* @return error code
* @param error positive errno value, or an already negative error code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, code on L104 seems to always return a negative number or zero), so this documentation seems wrong. positive errno is never returned.

Callers seem to check for non-zero, so maybe this should be "0 on success", or keep the code logic and "0 on success, negative error"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about param which could be positive (and it is in one single call).
The next line is about return value (negative error code).

In this path caller checks only <0 (rimage.c#L249), this could be changed but anyway elf_error return -ENOMEM in elf_section_read, and then its again switched from -ENOMEM to ENOMEM in elf_strings_read_by_index.

Its just stupid and must to be fixed somewhere so I decided to make a simple check to avoid inconsistent behavior (negative or positive error code)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abonislawski my bad, it's ok after all

* @return negative error code
*/
static int elf_error(const struct elf_file *elf, const char *msg, int error)
{
fprintf(stderr, "Error: %s: %s\n", elf->filename, msg);
return -error;
return error < 0 ? error : -error;
}

/**
Expand Down
Loading