[PATCH v3] device-tree: fix infinite loop issue in 'assign_shared_memory()'

Dmytro Prokopchuk1 posted 1 patch 1 month, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/41cbf42c319a95c92517b6042414de6d13dda077.1756718656.git.dmytro._5Fprokopchuk1@epam.com
xen/common/device-tree/static-shmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v3] device-tree: fix infinite loop issue in 'assign_shared_memory()'
Posted by Dmytro Prokopchuk1 1 month, 4 weeks ago
Fix an issue in the 'fail:' cleanup path of the 'assign_shared_memory()'
function where the use of an unsigned long 'i' with the condition
'--i >= 0' caused an infinite loop. Update the loop to use 'i--',
ensuring correct loop termination.

This change adheres to MISRA C Rule 14.3: "Controlling expressions shall
not be invariant."

Fixes: 041957bad382 ("xen/arm: Add additional reference to owner domain when the owner is allocated")
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Changes in v3:
- inserted right Fixes tag, pointed by Andrew Cooper

Link to v2:
https://patchew.org/Xen/0e562f695e5db87ab80dde69cbcc0cfa14f94b21.1756373770.git.dmytro._5Fprokopchuk1@epam.com/
---
 xen/common/device-tree/static-shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/device-tree/static-shmem.c b/xen/common/device-tree/static-shmem.c
index 8023c0a484..79f23caa77 100644
--- a/xen/common/device-tree/static-shmem.c
+++ b/xen/common/device-tree/static-shmem.c
@@ -185,7 +185,7 @@ static int __init assign_shared_memory(struct domain *d, paddr_t gbase,
     return 0;
 
  fail:
-    while ( --i >= 0 )
+    while ( i-- )
         put_page_nr(page + i, nr_borrowers);
     return ret;
 }
-- 
2.43.0
Re: [PATCH v3] device-tree: fix infinite loop issue in 'assign_shared_memory()'
Posted by Orzel, Michal 1 month, 4 weeks ago

On 01/09/2025 11:26, Dmytro Prokopchuk1 wrote:
> Fix an issue in the 'fail:' cleanup path of the 'assign_shared_memory()'
> function where the use of an unsigned long 'i' with the condition
> '--i >= 0' caused an infinite loop. Update the loop to use 'i--',
> ensuring correct loop termination.
> 
> This change adheres to MISRA C Rule 14.3: "Controlling expressions shall
> not be invariant."
> 
> Fixes: 041957bad382 ("xen/arm: Add additional reference to owner domain when the owner is allocated")
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
Acked-by: Michal Orzel <michal.orzel@amd.com>

~Michal