[libvirt PATCH] qemu: Do not pass negative ncpus to virCapabilitiesClearHostNUMACellCPUTopology

Jiri Denemark posted 1 patch 2 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/876a27a6f72e8f5455b65959021d1408071b2d71.1636052091.git.jdenemar@redhat.com
src/conf/capabilities.c | 1 +
1 file changed, 1 insertion(+)
[libvirt PATCH] qemu: Do not pass negative ncpus to virCapabilitiesClearHostNUMACellCPUTopology
Posted by Jiri Denemark 2 years, 5 months ago
It won't cause any harm as cpus is NULL when we pass a negative ncpus,
but doing so when the function expects unsigned value is not right.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/capabilities.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index a3e68741a9..cea4803fc8 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1954,6 +1954,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps)
             if (ncpus == -2)
                 continue;
 
+            ncpus = 0;
             goto cleanup;
         }
 
-- 
2.33.1

Re: [libvirt PATCH] qemu: Do not pass negative ncpus to virCapabilitiesClearHostNUMACellCPUTopology
Posted by Michal Prívozník 2 years, 5 months ago
On 11/4/21 7:54 PM, Jiri Denemark wrote:
> It won't cause any harm as cpus is NULL when we pass a negative ncpus,
> but doing so when the function expects unsigned value is not right.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/conf/capabilities.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
> index a3e68741a9..cea4803fc8 100644
> --- a/src/conf/capabilities.c
> +++ b/src/conf/capabilities.c
> @@ -1954,6 +1954,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps)
>              if (ncpus == -2)
>                  continue;
>  
> +            ncpus = 0;
>              goto cleanup;
>          }
>  
> 

Alternatively, we may just 'return -1' instead of 'goto cleanup'.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal