The statement 'return ERR_PTR(-ENOENT);' on the final line of the function
'hypfs_get_entry_rel()' is unreachable because the logic within the infinite
loop 'for (;;)' provides all possible exit paths for the function. So there
is no execution path to exit the loop and reach the final that statement.
Remove that statement. This also fixes MISRA C Rule 2.1 which states:
"A project shall not contain unreachable code".
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2440991088
---
xen/common/hypfs.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/xen/common/hypfs.c b/xen/common/hypfs.c
index cdf4ee0171..fea74d66e1 100644
--- a/xen/common/hypfs.c
+++ b/xen/common/hypfs.c
@@ -347,8 +347,6 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir,
path = end + 1;
dir = container_of(entry, struct hypfs_entry_dir, e);
}
-
- return ERR_PTR(-ENOENT);
}
static struct hypfs_entry *hypfs_get_entry(const char *path)
--
2.43.0
On 09.04.2026 17:55, Dmytro Prokopchuk1 wrote: > --- a/xen/common/hypfs.c > +++ b/xen/common/hypfs.c > @@ -347,8 +347,6 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, > path = end + 1; > dir = container_of(entry, struct hypfs_entry_dir, e); > } > - > - return ERR_PTR(-ENOENT); > } How certain are we that no supported compiler in any mode of compilation might issue a diagnostic for the then missing "return" at the end of a function returning non-void? Imo we might be better off adding ASSERT_UNREACHABLE() and keeping the "return" that's there. Jan
On 4/16/26 11:14, Jan Beulich wrote: > On 09.04.2026 17:55, Dmytro Prokopchuk1 wrote: >> --- a/xen/common/hypfs.c >> +++ b/xen/common/hypfs.c >> @@ -347,8 +347,6 @@ static struct hypfs_entry *hypfs_get_entry_rel(struct hypfs_entry_dir *dir, >> path = end + 1; >> dir = container_of(entry, struct hypfs_entry_dir, e); >> } >> - >> - return ERR_PTR(-ENOENT); >> } > > How certain are we that no supported compiler in any mode of compilation might > issue a diagnostic for the then missing "return" at the end of a function > returning non-void? Imo we might be better off adding ASSERT_UNREACHABLE() and > keeping the "return" that's there. You have a good point. While I don't think modern compilers are naive enough to miss this, but I completely agree with you that being explicit with ASSERT_UNREACHABLE() is better approach. I'll update the patch. BR, Dmytro. > > Jan
On 09.04.26 17:55, Dmytro Prokopchuk1 wrote: > The statement 'return ERR_PTR(-ENOENT);' on the final line of the function > 'hypfs_get_entry_rel()' is unreachable because the logic within the infinite > loop 'for (;;)' provides all possible exit paths for the function. So there > is no execution path to exit the loop and reach the final that statement. > > Remove that statement. This also fixes MISRA C Rule 2.1 which states: > "A project shall not contain unreachable code". > > Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen
© 2016 - 2026 Red Hat, Inc.