Fix coverity issues for AST2700
cover Fix coverity issues for AST2700
change from v1:
aspeed/soc: coverity defect: DIVIDE_BY_ZERO aspeed/sdmc: coverity defect: Control flow issues (DEADCODE)
Jamin Lin (2):
aspeed/soc: fix coverity issue
aspeed/sdmc: fix coverity issue
hw/arm/aspeed_ast27x0.c | 6 ++++++ hw/misc/aspeed_sdmc.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
PATCH 1/2 aspeed/soc: fix coverity issue
Fix coverity defect: DIVIDE_BY_ZERO.
--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)
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 ; + } +/* * Emulate ddr capacity hardware behavior. * If writes the data to the address which is beyond the ram size,
Signature · 1 line
2.34.1
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
Quoted 3 lines · Jamin Lin
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>
I have rewritten the commit log :
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.
with that,
Thanks,
C.
Quoted 21 lines
--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)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 ; + } +/* * Emulate ddr capacity hardware behavior. * If writes the data to the address which is beyond the ram size,
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
In reply to Jamin Lin viaQuoted 13 lines · Jamin Lin
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/arm/aspeed_ast27x0.c +0
-0
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 ; + } +
Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize method) that the ram-size property is valid, and then here we can just assert(ram_size != 0).
thanks
-- PMM
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Jamin Lin
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)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_abort);
Quoted 12 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 ; + } +Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize method) that the ram-size property is valid,
That's the case in aspeed_sdmc_set_ram_size() which is called from the aspeed machine init routine when the ram size is set.
Setting the machine ram size to zero on the command line doesn't report an error though and the size is the default.
Quoted 1 line
and then here we can just
assert(ram_size != 0).
Yes.
Jamin, could you please send a v2 with the commit logs update I proposed ? See the patches on my aspeed-9.1 branch.
Thanks,
C.
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
Quoted 32 lines · Cédric Le Goater
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Jamin Lin
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)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_abort);Quoted 12 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 ; + } +Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize method) that the ram-size property is valid,
Quoted 2 lines
That's the case in
aspeed_sdmc_set_ram_size()which is called from the aspeed machine init routine when the ram size is set.
True, but if the property is never set at all then the struct field will be left at whatever value it had, which is 0, I think. So if that's not valid then it either needs to be a different default or else the realize method should complain that the property was never set.
thanks
-- PMM
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
Quoted 33 lines · Peter Maydell
Quoted 32 lines · Cédric Le Goater
Quoted 29 lines · Peter Maydell
Quoted 13 lines · Jamin Lin
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/arm/aspeed_ast27x0.c +0
-0hw/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 ; + } +Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize method) that the ram-size property is valid,
Quoted 8 lines
Quoted 2 lines
That's the case in
aspeed_sdmc_set_ram_size()which is called from the aspeed machine init routine when the ram size is set.True, but if the property is never set at all then the struct field will be left at whatever value it had, which is 0, I think. So if that's not valid then it either needs to be a different default or else the realize method should complain that the property was never set.
Ah, yes, and the issue has been there for while. I will send a separate patch for this.
Thanks,
C.
RE: [PATCH v1 1/2] aspeed/soc: fix coverity issue
In reply to Cédric Le GoaterHi Cedric,
Quoted 52 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, June 24, 2024 9:58 PM
To: Peter Maydell <[email protected]>; Jamin Lin <[email protected]>
Cc: 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]>; Troy Lee <[email protected]>; Yunlin Tang <[email protected]>
Subject: Re: [PATCH v1 1/2] aspeed/soc: fix coverity issueQuoted 1 line · Peter Maydell
On Wed, 19 Jun 2024 at 10:35, Jamin Lin <[email protected]>
Quoted 8 lines · wrote:
Quoted 8 lines
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 5 lines
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void
Quoted 5 lines
hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0
-0
b6876b4862..d14a46df6f100644hw/arm/aspeed_ast27x0.c +0
-0@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void*opaque, hwaddr addr,
uint64_tdata,Quoted 1 line
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void · line 211
Quoted 1 line
hw/arm/aspeed_ast27x0.c +0
-0ram_size = object_property_get_uint(OBJECT(&s->sdmc),"ram-size",
Quoted 9 lines
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 219
Quoted 8 lines
hw/arm/aspeed_ast27x0.c +6
-0&error_abort); +if (!ram_size) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: ram_size is zero" , __func__); +return ; + } +Quoted 5 lines
Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize
method) that the ram-size property is valid,That's the case in
aspeed_sdmc_set_ram_size()which is called from the aspeed machine init routine when the ram size is set.Setting the machine ram size to zero on the command line doesn't report an error though and the size is the default.
Quoted 6 lines
Quoted 1 line
and then here we can just
assert(ram_size != 0).Yes.
Jamin, could you please send a v2 with the commit logs update I proposed ? See the patches on my aspeed-9.1 branch.
I resend v2 patch with your commit log, https://www.mail-archive.com/[email protected]/msg1050302.html
Do we need to drop this patch, https://www.mail-archive.com/[email protected]/msg1050301.html?
Thanks-Jamin
Quoted 4 lines
Thanks,
C.
Re: [PATCH v1 1/2] aspeed/soc: fix coverity issue
Hello
Quoted 53 lines · Jamin Lin
Hi Cedric,
Quoted 52 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, June 24, 2024 9:58 PM
To: Peter Maydell <[email protected]>; Jamin Lin <[email protected]>
Cc: 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]>; Troy Lee <[email protected]>; Yunlin Tang <[email protected]>
Subject: Re: [PATCH v1 1/2] aspeed/soc: fix coverity issueQuoted 1 line · Peter Maydell
On Wed, 19 Jun 2024 at 10:35, Jamin Lin <[email protected]>
Quoted 8 lines · wrote:
Quoted 8 lines
Fix coverity defect:
DIVIDE_BY_ZERO.Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast27x0.c | 6 ++++++ 1 file changed, 6 insertions(+)Quoted 5 lines
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void
Quoted 5 lines
hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0
-0
b6876b4862..d14a46df6f100644hw/arm/aspeed_ast27x0.c +0
-0@@ -211,6 +211,12 @@ static void aspeed_ram_capacity_write(void*opaque, hwaddr addr,
uint64_tdata,Quoted 1 line
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void · line 211
Quoted 1 line
hw/arm/aspeed_ast27x0.c +0
-0ram_size = object_property_get_uint(OBJECT(&s->sdmc),"ram-size",
Quoted 9 lines
hw/arm/aspeed_ast27x0.c static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, · line 219
Quoted 8 lines
hw/arm/aspeed_ast27x0.c +6
-0&error_abort); +if (!ram_size) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: ram_size is zero" , __func__); +return ; + } +Quoted 5 lines
Isn't this a QEMU bug rather than a guest error? The RAM size presumably should never be zero unless the board set the ram-size property on the SDMC incorrectly. So the SDMC device should check (and return an error from its realize
method) that the ram-size property is valid,That's the case in
aspeed_sdmc_set_ram_size()which is called from the aspeed machine init routine when the ram size is set.Setting the machine ram size to zero on the command line doesn't report an error though and the size is the default.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
and then here we can just
assert(ram_size != 0).Yes.
Jamin, could you please send a v2 with the commit logs update I proposed ? See the patches on my aspeed-9.1 branch.
I resend v2 patch with your commit log, https://www.mail-archive.com/[email protected]/msg1050302.html
We'll need a v3 with the assert. No hurries. We still have some time before the soft freeze.
Thanks,
C.
Quoted 7 lines
Do we need to drop this patch, https://www.mail-archive.com/[email protected]/msg1050301.html?
Thanks-Jamin
Quoted 4 lines
Thanks,
C.
PATCH 2/2 aspeed/sdmc: fix coverity issue
In reply to Jamin Lin viaFix coverity defect: Control flow issues (DEADCODE)
--- hw/misc/aspeed_sdmc.c | 1 - 1 file changed, 1 deletion(-)
hw/misc/aspeed_sdmc.c +0 -1
@@ -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.34.1
Re: [PATCH v1 2/2] aspeed/sdmc: fix coverity issue
Quoted 1 line · Jamin Lin
Fix coverity defect: Control flow issues (DEADCODE)
aspeed/sdmc: Remove extra R_MAIN_STATUS case
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.
with that,
Thanks,
C.
Quoted 18 lines
Signed-off-by Jamin Lin <[email protected]>--- hw/misc/aspeed_sdmc.c | 1 - 1 file changed, 1 deletion(-)hw/misc/aspeed_sdmc.c +0
-1@@ -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 :