Skip to content

tools: rimage: return a negative error code from elf_error() - #11077

Open
abonislawski wants to merge 1 commit into
mainfrom
rimage_elf_err
Open

tools: rimage: return a negative error code from elf_error()#11077
abonislawski wants to merge 1 commit into
mainfrom
rimage_elf_err

Conversation

@abonislawski

Copy link
Copy Markdown
Member

elf_error() negates its argument, so an already negative code was turned into a positive value that callers testing "ret < 0" take for success.

elf_error() negates its argument, so an already negative code was turned
into a positive value that callers testing "ret < 0" take for success.

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an error-sign bug in tools/rimage where elf_error() could return a positive value when given an already-negative error code, causing callers that check ret < 0 to misinterpret failures as success.

Changes:

  • Update elf_error() to preserve negative error codes while still negating positive errno values.
  • Clarify the elf_error() Doxygen comment to document the expected sign of inputs/outputs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kv2019i kv2019i left a comment

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.

Documentation doesn't quite match the code change....?

* @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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants