Skip to contentSkip to conversation

Fix coverity issues for AST2700

PATCH Superseded Jamin Lin via 5 participants 9 messages Jun 25, 2024 Arm/Aspeed machine support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix coverity issues for AST2700

change from v1:
aspeed/soc: coverity defect: DIVIDE_BY_ZERO aspeed/sdmc: coverity defect: Control flow issues (DEADCODE)

change from v2:
add more commit log from reviewer, Cédric.

Jamin Lin (2):
aspeed/soc: Fix possible divide by zero
aspeed/sdmc: Remove extra R_MAIN_STATUS case

 hw/arm/aspeed_ast27x0.c | 6 ++++++
 hw/misc/aspeed_sdmc.c   | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 aspeed/soc: Fix possible divide by zero

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

Fixes Coverity CID 1547113
[ clg: Rewrote commit log ]
---
 hw/arm/aspeed_ast27x0.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/arm/aspeed_ast27x0.c +6 -0
index b6876b4862..d14a46df6f 100644
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data,
     ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
                                         &error_abort);
 
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+
     /*
      * Emulate ddr capacity hardware behavior.
      * If writes the data to the address which is beyond the ram size,
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Hi

Quoted 19 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

Fixes Coverity CID 1547113
[ clg: Rewrote commit log ]
---
  hw/arm/aspeed_ast27x0.c | 6 ++++++
  1 file changed, 6 insertions(+)
hw/arm/aspeed_ast27x0.c +0 -0
index b6876b4862..d14a46df6f 100644

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 219

Quoted 9 lines
hw/arm/aspeed_ast27x0.c +6 -0
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data,
      ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
                                          &error_abort);
 
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Quoted 3 lines
hw/arm/aspeed_ast27x0.c +0 -0
      /*
       * Emulate ddr capacity hardware behavior.
       * If writes the data to the address which is beyond the ram size,
#3 lore raw

Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 17 lines · cmd

Hi

Quoted 14 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

Fixes Coverity CID 1547113
[ clg: Rewrote commit log ]

---
  hw/arm/aspeed_ast27x0.c | 6 ++++++

  1 file changed, 6 insertions(+)
Quoted 14 lines

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 218

Quoted 13 lines
hw/arm/aspeed_ast27x0.c +6 -0
index b6876b4862..d14a46df6f 100644
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data,
       ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
                                           &error_abort);
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Yes. That is what Peter suggested. This needs to be changed.

Thanks,

C.

Quoted 3 lines
Quoted 3 lines
hw/arm/aspeed_ast27x0.c +0 -0
       /*
        * Emulate ddr capacity hardware behavior.
        * If writes the data to the address which is beyond the ram size,
#4 lore raw

Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 34 lines · Cédric Le Goater
Quoted 17 lines · cmd

Hi

Quoted 14 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

Fixes Coverity CID 1547113
[ clg: Rewrote commit log ]

---
  hw/arm/aspeed_ast27x0.c | 6 ++++++

  1 file changed, 6 insertions(+)
Quoted 15 lines
Quoted 5 lines
hw/arm/aspeed_ast27x0.c +0 -0
index b6876b4862..d14a46df6f 100644

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void · line 219

Quoted 9 lines
hw/arm/aspeed_ast27x0.c +6 -0
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void 
 *opaque, hwaddr addr, uint64_t data,
       ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
                                           &error_abort);
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Quoted 7 lines

Yes. That is what Peter suggested. This needs to be changed.

Thanks,

C.

Ok fine, I didn't see the message, sorry!

Thanks

Quoted 8 lines

cmd

Quoted 3 lines
Quoted 3 lines
hw/arm/aspeed_ast27x0.c +0 -0
       /*
        * Emulate ddr capacity hardware behavior.
        * If writes the data to the address which is beyond the ram size,
#5 lore raw

RE: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Hi cmd, Cedric and Peter,

Quoted 32 lines

-----Original Message-----
From: cmd <[email protected]>
Sent: Tuesday, June 25, 2024 2:07 PM
To: Cédric Le Goater <[email protected]>; Jamin Lin <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 18 lines · Cédric Le Goater
Quoted 17 lines · cmd

Hi

Quoted 14 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

log ]

---
  hw/arm/aspeed_ast27x0.c | 6 ++++++

  1 file changed, 6 insertions(+)
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0 -0

b6876b4862..d14a46df6f 100644

hw/arm/aspeed_ast27x0.c +0 -0
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void
 *opaque, hwaddr addr, uint64_t data,
       ram_size = object_property_get_uint(OBJECT(&s->sdmc),
 "ram-size",

                                          &error_a

bort);

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__); +        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Yes. That is what Peter suggested. This needs to be changed.

Thanks for review and suggestion.
How about this change?

assert(ram_size > 0);

If you agree, I will send v3 patch.
Thanks-Jamin

Quoted 18 lines
Quoted 5 lines

Thanks,

C.

Ok fine, I didn't see the message, sorry!

Thanks

Quoted 9 lines

cmd

Quoted 4 lines
Quoted 4 lines

      /*
       * Emulate ddr capacity hardware behavior.
       * If writes the data to the address which is beyond the ram size,

#6 lore raw

Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 53 lines · Jamin Lin

Hi cmd, Cedric and Peter,

Quoted 51 lines

-----Original Message-----
From: cmd <[email protected]>
Sent: Tuesday, June 25, 2024 2:07 PM
To: Cédric Le Goater <[email protected]>; Jamin Lin <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 18 lines · Cédric Le Goater
Quoted 17 lines · cmd

Hi

Quoted 14 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

log ]

---
   hw/arm/aspeed_ast27x0.c | 6 ++++++
   1 file changed, 6 insertions(+)
Quoted 9 lines
Quoted 9 lines

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void · line 214

Quoted 9 lines
hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0 -0

b6876b4862..d14a46df6f 100644

hw/arm/aspeed_ast27x0.c +0 -0
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void
 *opaque, hwaddr addr, uint64_t data,
       ram_size = object_property_get_uint(OBJECT(&s->sdmc),
 "ram-size",
                                           &error_a

bort);

Quoted 9 lines
Quoted 8 lines

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 219

Quoted 6 lines
hw/arm/aspeed_ast27x0.c +6 -0
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Yes. That is what Peter suggested. This needs to be changed.

Thanks for review and suggestion.
How about this change?

assert(ram_size > 0);

yes.

I will send another patch fixing a long standing issue in the SDMC model not checking the ram_size value in the realize handler. It relies on the "ram-size" property being set.

Thanks,

C.

Quoted 21 lines

If you agree, I will send v3 patch.
Thanks-Jamin

Quoted 18 lines
Quoted 5 lines

Thanks,

C.

Ok fine, I didn't see the message, sorry!

Thanks

Quoted 9 lines

cmd

Quoted 4 lines
Quoted 4 lines
hw/arm/aspeed_ast27x0.c +0 -0
       /*
        * Emulate ddr capacity hardware behavior.

       * If writes the data to the address which is beyond the ram
size,

#7 lore raw

RE: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Hi Cedric,

Quoted 76 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Tuesday, June 25, 2024 2:38 PM
To: Jamin Lin <[email protected]>; cmd <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 8 lines · Jamin Lin

Hi cmd, Cedric and Peter,

Quoted 6 lines

-----Original Message-----
From: cmd <[email protected]>
Sent: Tuesday, June 25, 2024 2:07 PM
To: Cédric Le Goater <[email protected]>; Jamin Lin <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee

<[email protected]>;

Quoted 26 lines
Quoted 26 lines

Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH v2 1/2] aspeed/soc: Fix possible divide by zero

Quoted 18 lines · Cédric Le Goater
Quoted 17 lines · cmd

Hi

Quoted 14 lines · Jamin Lin via

Coverity reports a possible DIVIDE_BY_ZERO issue regarding the "ram_size" object property. This can not happen because RAM has predefined valid sizes per SoC. Nevertheless, add a test to close the issue.

commit log ]

---
   hw/arm/aspeed_ast27x0.c | 6 ++++++
   1 file changed, 6 insertions(+)
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void · line 214

Quoted 9 lines
hw/arm/aspeed_ast27x0.c +0 -0
index b6876b4862..d14a46df6f 100644
@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void
 *opaque, hwaddr addr, uint64_t data,
       ram_size = object_property_get_uint(OBJECT(&s->sdmc),
 "ram-size",
                                           &erro

r_a

Quoted 10 lines
Quoted 10 lines

bort);

Quoted 9 lines
Quoted 8 lines

hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 219

Quoted 6 lines
hw/arm/aspeed_ast27x0.c +6 -0
+    if (!ram_size) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "%s: ram_size is zero",  __func__);
+        return;
+    }
+

If we are sure that the error cannot happen, shouldn't we assert instead?

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Yes. That is what Peter suggested. This needs to be changed.

Thanks for review and suggestion.
How about this change?

assert(ram_size > 0);

Quoted 8 lines

yes.

I will send another patch fixing a long standing issue in the SDMC model not checking the ram_size value in the realize handler. It relies on the "ram-size" property being set.

Thanks,

Will send v3 patch and thanks for your review and help. Jamin

Quoted 24 lines

C.

Quoted 21 lines

If you agree, I will send v3 patch.
Thanks-Jamin

Quoted 18 lines
Quoted 5 lines

Thanks,

C.

Ok fine, I didn't see the message, sorry!

Thanks

Quoted 9 lines

cmd

Quoted 4 lines
Quoted 4 lines
hw/arm/aspeed_ast27x0.c +0 -0
       /*
        * Emulate ddr capacity hardware behavior.

       * If writes the data to the address which is beyond the
ram size,

#8 lore raw

PATCH v2 2/2 aspeed/sdmc: Remove extra R_MAIN_STATUS case

In reply to Jamin Lin via

Coverity reports that the newly added 'case R_MAIN_STATUS' is DEADCODE because it can not be reached. This is because R_MAIN_STATUS is handled before in the "Unprotected registers" switch statement. Remove it.

Fixes Coverity CID 1547112
[ clg: Rewrote commit log ]
---
 hw/misc/aspeed_sdmc.c | 1 -
 1 file changed, 1 deletion(-)
hw/misc/aspeed_sdmc.c +0 -1
index 93e2e29ead..94eed9264d 100644
@@ -589,7 +589,6 @@ static void aspeed_2700_sdmc_write(AspeedSDMCState *s, uint32_t reg,
     case R_INT_STATUS:
     case R_INT_CLEAR:
     case R_INT_MASK:
-    case R_MAIN_STATUS:
     case R_ERR_STATUS:
     case R_ECC_FAIL_STATUS:
     case R_ECC_FAIL_ADDR:
Signature · 1 line
2.25.1