[PATCH v4] common/efi: fix Rule 2.1 violation in read_file()

Dmytro Prokopchuk1 posted 1 patch 2 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/1e5a31fe588f58bd2b5c7835773fdf7899ff5511.1756047981.git.dmytro._5Fprokopchuk1@epam.com
xen/common/efi/boot.c | 1 -
1 file changed, 1 deletion(-)
[PATCH v4] common/efi: fix Rule 2.1 violation in read_file()
Posted by Dmytro Prokopchuk1 2 months, 1 week ago
MISRA C Rule 2.1 states: "A project shall not contain unreachable code."

The return statements in the 'read_file()' function is unreachable due
to function 'PrintErrMesg()' which has 'noreturn' attribute:
        PrintErrMesg(name, ret);
        /* not reached */
        return false;
    }

No explicit return statement is needed here because 'PrintErrMesg()' is
marked as 'noreturn', which guarantees that it never returns control to
the caller. If the 'noreturn' attribute of 'PrintErrMesg()' is removed
in the future, compiler will emit an error about the missing return
statement (build-time safeguard).
No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
Reviewed-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
Changes in v4:
- verbose code comment was moved into commit message
- kept the old comment that was already there in read_file()
- added Marek's tag

Link to v3:
https://patchew.org/Xen/4a1a4a3406d227348afa1ad2ce90dc5264fdb44a.1755783750.git.dmytro._5Fprokopchuk1@epam.com/
---
 xen/common/efi/boot.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 50ff1d1bd2..b7fdb031d0 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -853,7 +853,6 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     PrintErrMesg(name, ret);
 
     /* not reached */
-    return false;
 }
 
 static bool __init read_section(const EFI_LOADED_IMAGE *image,
-- 
2.43.0
Re: [PATCH v4] common/efi: fix Rule 2.1 violation in read_file()
Posted by Jan Beulich 2 months ago
On 24.08.2025 17:10, Dmytro Prokopchuk1 wrote:
> MISRA C Rule 2.1 states: "A project shall not contain unreachable code."
> 
> The return statements in the 'read_file()' function is unreachable due

Especially due to the (imo wrong) use of plural, this continues to be
ambiguous. I'd suggest switching to singular and inserting "final" or
"main". Happy to adjust while committing, provided you agree.

Jan
Re: [PATCH v4] common/efi: fix Rule 2.1 violation in read_file()
Posted by Dmytro Prokopchuk1 2 months ago

On 8/25/25 13:12, Jan Beulich wrote:
> On 24.08.2025 17:10, Dmytro Prokopchuk1 wrote:
>> MISRA C Rule 2.1 states: "A project shall not contain unreachable code."
>>
>> The return statements in the 'read_file()' function is unreachable due
> 
> Especially due to the (imo wrong) use of plural, this continues to be
> ambiguous. I'd suggest switching to singular and inserting "final" or
> "main". Happy to adjust while committing, provided you agree.
> 
> Jan

I don't mind.
Thank you.

Dmytro.