[PATCH] hypfs: remove unreachable statement in the 'hypfs_get_entry_rel()'

Dmytro Prokopchuk1 posted 1 patch 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/341811ced2943fb79d0235c27781c564c7bdaf02.1775749146.git.dmytro._5Fprokopchuk1@epam.com
xen/common/hypfs.c | 2 --
1 file changed, 2 deletions(-)
[PATCH] hypfs: remove unreachable statement in the 'hypfs_get_entry_rel()'
Posted by Dmytro Prokopchuk1 3 months ago
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
Re: [PATCH] hypfs: remove unreachable statement in the 'hypfs_get_entry_rel()'
Posted by Jan Beulich 2 months, 3 weeks ago
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
Re: [PATCH] hypfs: remove unreachable statement in the 'hypfs_get_entry_rel()'
Posted by Dmytro Prokopchuk1 2 months, 2 weeks ago

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
Re: [PATCH] hypfs: remove unreachable statement in the 'hypfs_get_entry_rel()'
Posted by Jürgen Groß 3 months ago
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