* [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size()
@ 2018-10-30 17:03 Peter Maydell
2018-10-30 22:40 ` BALATON Zoltan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Peter Maydell @ 2018-10-30 17:03 UTC (permalink / raw)
To: qemu-devel; +Cc: David Gibson, Alexander Graf, qemu-ppc, BALATON Zoltan
Coverity points out in CID 1390588 that the test for sh == 0
in sdram_size() can never fire, because we calculate sh with
sh = 1024 - ((bcr >> 6) & 0x3ff);
which must result in a value between 1 and 1024 inclusive.
Without the relevant manual for the SoC, we're not completely
sure of the correct behaviour here, but we can remove the
dead code without changing how QEMU currently behaves.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
We had a discussion about this coverity error a while back:
https://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg05187.html
I'd just like to squash the Coverity warning, I think.
hw/ppc/ppc440_uc.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
index 09ccda548f3..9360f781cef 100644
--- a/hw/ppc/ppc440_uc.c
+++ b/hw/ppc/ppc440_uc.c
@@ -559,11 +559,7 @@ static target_ulong sdram_size(uint32_t bcr)
int sh;
sh = 1024 - ((bcr >> 6) & 0x3ff);
- if (sh == 0) {
- size = -1;
- } else {
- size = 8 * MiB * sh;
- }
+ size = 8 * MiB * sh;
return size;
}
--
2.19.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size()
2018-10-30 17:03 [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size() Peter Maydell
@ 2018-10-30 22:40 ` BALATON Zoltan
2018-10-31 13:43 ` [Qemu-devel] [Qemu-ppc] " Laurent Vivier
2018-11-07 4:24 ` [Qemu-devel] " David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: BALATON Zoltan @ 2018-10-30 22:40 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, David Gibson, Alexander Graf, qemu-ppc
On Tue, 30 Oct 2018, Peter Maydell wrote:
> Coverity points out in CID 1390588 that the test for sh == 0
> in sdram_size() can never fire, because we calculate sh with
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> which must result in a value between 1 and 1024 inclusive.
>
> Without the relevant manual for the SoC, we're not completely
> sure of the correct behaviour here, but we can remove the
> dead code without changing how QEMU currently behaves.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> We had a discussion about this coverity error a while back:
> https://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg05187.html
> I'd just like to squash the Coverity warning, I think.
As I told back then, feel free to go ahead and avoid the warning if it's
in your way.
As for the proper fix, I'm still not sure how it works on real SoC but the
current formula is likely wrong and this U-Boot commit may provide some
hints instead:
https://git.denx.de/?p=u-boot.git;a=commitdiff;h=8ac41e3e37c3080c6b1d9461d654161cfe2aa492
Here RAM sizes are encoded in some strange way and I think this function
(and the ppc460ex_sdram_bank_sizes array in sam460ex.c) might need to be
changed to work according to this but I don't get this enough to be able
to write a patch that I'm confident won't break anything else. (Also this
is the reason why RAM size is limited to 1GB on the sam460ex emulation
currently so fixing this would also allow RAM up to 4 GB as on real
hardware.)
If this makes more sense to someone or there's someone who knows how it
works on the 460EX SoC, help is appreciated as I likely won't be able to
spend enough time to try to understand and fix this based on just the
U-Boot source without more proper docs anytime soon.
Regards,
BALATON Zoltan
> hw/ppc/ppc440_uc.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
> index 09ccda548f3..9360f781cef 100644
> --- a/hw/ppc/ppc440_uc.c
> +++ b/hw/ppc/ppc440_uc.c
> @@ -559,11 +559,7 @@ static target_ulong sdram_size(uint32_t bcr)
> int sh;
>
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> - if (sh == 0) {
> - size = -1;
> - } else {
> - size = 8 * MiB * sh;
> - }
> + size = 8 * MiB * sh;
>
> return size;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [Qemu-ppc] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size()
2018-10-30 17:03 [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size() Peter Maydell
2018-10-30 22:40 ` BALATON Zoltan
@ 2018-10-31 13:43 ` Laurent Vivier
2018-11-07 4:24 ` [Qemu-devel] " David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2018-10-31 13:43 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: BALATON Zoltan, qemu-ppc, David Gibson
On 30/10/2018 18:03, Peter Maydell wrote:
> Coverity points out in CID 1390588 that the test for sh == 0
> in sdram_size() can never fire, because we calculate sh with
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> which must result in a value between 1 and 1024 inclusive.
>
> Without the relevant manual for the SoC, we're not completely
> sure of the correct behaviour here, but we can remove the
> dead code without changing how QEMU currently behaves.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> We had a discussion about this coverity error a while back:
> https://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg05187.html
> I'd just like to squash the Coverity warning, I think.
>
> hw/ppc/ppc440_uc.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
> index 09ccda548f3..9360f781cef 100644
> --- a/hw/ppc/ppc440_uc.c
> +++ b/hw/ppc/ppc440_uc.c
> @@ -559,11 +559,7 @@ static target_ulong sdram_size(uint32_t bcr)
> int sh;
>
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> - if (sh == 0) {
> - size = -1;
> - } else {
> - size = 8 * MiB * sh;
> - }
> + size = 8 * MiB * sh;
>
> return size;
> }
>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size()
2018-10-30 17:03 [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size() Peter Maydell
2018-10-30 22:40 ` BALATON Zoltan
2018-10-31 13:43 ` [Qemu-devel] [Qemu-ppc] " Laurent Vivier
@ 2018-11-07 4:24 ` David Gibson
2 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2018-11-07 4:24 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, Alexander Graf, qemu-ppc, BALATON Zoltan
[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]
On Tue, Oct 30, 2018 at 05:03:53PM +0000, Peter Maydell wrote:
> Coverity points out in CID 1390588 that the test for sh == 0
> in sdram_size() can never fire, because we calculate sh with
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> which must result in a value between 1 and 1024 inclusive.
>
> Without the relevant manual for the SoC, we're not completely
> sure of the correct behaviour here, but we can remove the
> dead code without changing how QEMU currently behaves.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Applied to ppc-for-3.1, thanks.
> ---
> We had a discussion about this coverity error a while back:
> https://lists.nongnu.org/archive/html/qemu-devel/2018-04/msg05187.html
> I'd just like to squash the Coverity warning, I think.
>
> hw/ppc/ppc440_uc.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
> index 09ccda548f3..9360f781cef 100644
> --- a/hw/ppc/ppc440_uc.c
> +++ b/hw/ppc/ppc440_uc.c
> @@ -559,11 +559,7 @@ static target_ulong sdram_size(uint32_t bcr)
> int sh;
>
> sh = 1024 - ((bcr >> 6) & 0x3ff);
> - if (sh == 0) {
> - size = -1;
> - } else {
> - size = 8 * MiB * sh;
> - }
> + size = 8 * MiB * sh;
>
> return size;
> }
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-07 4:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-30 17:03 [Qemu-devel] [PATCH for-3.1] hw/ppc/ppc440_uc: Remove dead code in sdram_size() Peter Maydell
2018-10-30 22:40 ` BALATON Zoltan
2018-10-31 13:43 ` [Qemu-devel] [Qemu-ppc] " Laurent Vivier
2018-11-07 4:24 ` [Qemu-devel] " David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).