[PATCH for 9.2 1/2] hw/core/machine-smp: Initialize caches_bitmap before reading

Zhao Liu posted 2 patches 1 week, 6 days ago
[PATCH for 9.2 1/2] hw/core/machine-smp: Initialize caches_bitmap before reading
Posted by Zhao Liu 1 week, 6 days ago
The caches_bitmap is defined in machine_parse_smp_cache(), but it was
not initialized.

Initialize caches_bitmap by clearing all its bits to zero.

Resolves: Coverity CID 1565389
Fixes: 4e88e7e3403d ("qapi/qom: Define cache enumeration and properties for machine")
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/core/machine-smp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
index 640b2114b429..b87637c78f6f 100644
--- a/hw/core/machine-smp.c
+++ b/hw/core/machine-smp.c
@@ -290,6 +290,7 @@ bool machine_parse_smp_cache(MachineState *ms,
     const SmpCachePropertiesList *node;
     DECLARE_BITMAP(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX);
 
+    bitmap_zero(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX);
     for (node = caches; node; node = node->next) {
         /* Prohibit users from repeating settings. */
         if (test_bit(node->value->cache, caches_bitmap)) {
-- 
2.34.1
Re: [PATCH for 9.2 1/2] hw/core/machine-smp: Initialize caches_bitmap before reading
Posted by Philippe Mathieu-Daudé 4 days, 4 hours ago
On 10/11/24 16:09, Zhao Liu wrote:
> The caches_bitmap is defined in machine_parse_smp_cache(), but it was
> not initialized.
> 
> Initialize caches_bitmap by clearing all its bits to zero.
> 
> Resolves: Coverity CID 1565389
> Fixes: 4e88e7e3403d ("qapi/qom: Define cache enumeration and properties for machine")
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---
>   hw/core/machine-smp.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
> index 640b2114b429..b87637c78f6f 100644
> --- a/hw/core/machine-smp.c
> +++ b/hw/core/machine-smp.c
> @@ -290,6 +290,7 @@ bool machine_parse_smp_cache(MachineState *ms,
>       const SmpCachePropertiesList *node;
>       DECLARE_BITMAP(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX);

Alternatively:

      DECLARE_BITMAP(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX) = { };

>   
> +    bitmap_zero(caches_bitmap, CACHE_LEVEL_AND_TYPE__MAX);
>       for (node = caches; node; node = node->next) {
>           /* Prohibit users from repeating settings. */
>           if (test_bit(node->value->cache, caches_bitmap)) {

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>