All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
@ 2021-07-14  7:22 ` Alistair Francis
  0 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-07-14  7:22 UTC (permalink / raw)
  To: qemu-devel, qemu-riscv
  Cc: peter.maydell, alistair.francis, bmeng.cn, palmer, alistair23

Coverity reports that we don't check the error result of fdt_pack(), so
let's save the result and assert that it is 0.

Fixes: Coverity CID 1458136
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 hw/riscv/boot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 0d38bb7426..25406a3f67 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
 {
     uint32_t temp, fdt_addr;
     hwaddr dram_end = dram_base + mem_size;
-    int fdtsize = fdt_totalsize(fdt);
+    int ret, fdtsize = fdt_totalsize(fdt);
 
     if (fdtsize <= 0) {
         error_report("invalid device-tree");
@@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
     temp = MIN(dram_end, 3072 * MiB);
     fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
 
-    fdt_pack(fdt);
+    ret = fdt_pack(fdt);
+    g_assert(ret == 0);
     /* copy in the device tree */
     qemu_fdt_dumpdtb(fdt, fdtsize);
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
@ 2021-07-14  7:22 ` Alistair Francis
  0 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-07-14  7:22 UTC (permalink / raw)
  To: qemu-devel, qemu-riscv
  Cc: bmeng.cn, palmer, alistair.francis, alistair23, peter.maydell

Coverity reports that we don't check the error result of fdt_pack(), so
let's save the result and assert that it is 0.

Fixes: Coverity CID 1458136
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 hw/riscv/boot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 0d38bb7426..25406a3f67 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
 {
     uint32_t temp, fdt_addr;
     hwaddr dram_end = dram_base + mem_size;
-    int fdtsize = fdt_totalsize(fdt);
+    int ret, fdtsize = fdt_totalsize(fdt);
 
     if (fdtsize <= 0) {
         error_report("invalid device-tree");
@@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
     temp = MIN(dram_end, 3072 * MiB);
     fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
 
-    fdt_pack(fdt);
+    ret = fdt_pack(fdt);
+    g_assert(ret == 0);
     /* copy in the device tree */
     qemu_fdt_dumpdtb(fdt, fdtsize);
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
  2021-07-14  7:22 ` Alistair Francis
@ 2021-07-14  7:31   ` Bin Meng
  -1 siblings, 0 replies; 8+ messages in thread
From: Bin Meng @ 2021-07-14  7:31 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Peter Maydell, Palmer Dabbelt, open list:RISC-V,
	qemu-devel@nongnu.org Developers, Alistair Francis

On Wed, Jul 14, 2021 at 3:22 PM Alistair Francis
<alistair.francis@wdc.com> wrote:
>
> Coverity reports that we don't check the error result of fdt_pack(), so
> let's save the result and assert that it is 0.
>
> Fixes: Coverity CID 1458136
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  hw/riscv/boot.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
@ 2021-07-14  7:31   ` Bin Meng
  0 siblings, 0 replies; 8+ messages in thread
From: Bin Meng @ 2021-07-14  7:31 UTC (permalink / raw)
  To: Alistair Francis
  Cc: qemu-devel@nongnu.org Developers, open list:RISC-V,
	Palmer Dabbelt, Alistair Francis, Peter Maydell

On Wed, Jul 14, 2021 at 3:22 PM Alistair Francis
<alistair.francis@wdc.com> wrote:
>
> Coverity reports that we don't check the error result of fdt_pack(), so
> let's save the result and assert that it is 0.
>
> Fixes: Coverity CID 1458136
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  hw/riscv/boot.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
  2021-07-14  7:22 ` Alistair Francis
@ 2021-07-14  8:45   ` Peter Maydell
  -1 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2021-07-14  8:45 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Palmer Dabbelt, Bin Meng, open list:RISC-V, QEMU Developers,
	Alistair Francis

On Wed, 14 Jul 2021 at 08:22, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> Coverity reports that we don't check the error result of fdt_pack(), so
> let's save the result and assert that it is 0.
>
> Fixes: Coverity CID 1458136
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  hw/riscv/boot.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 0d38bb7426..25406a3f67 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
>  {
>      uint32_t temp, fdt_addr;
>      hwaddr dram_end = dram_base + mem_size;
> -    int fdtsize = fdt_totalsize(fdt);
> +    int ret, fdtsize = fdt_totalsize(fdt);
>
>      if (fdtsize <= 0) {
>          error_report("invalid device-tree");
> @@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
>      temp = MIN(dram_end, 3072 * MiB);
>      fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
>
> -    fdt_pack(fdt);
> +    ret = fdt_pack(fdt);
> +    g_assert(ret == 0);
>      /* copy in the device tree */
>      qemu_fdt_dumpdtb(fdt, fdtsize);

Are we in the same situation as spapr.c where we believe the call
will only fail if the fdt was corrupt somehow? If so, it would be
nice to also have the comment from spapr.c:
        /* Should only fail if we've built a corrupted tree */

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
@ 2021-07-14  8:45   ` Peter Maydell
  0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2021-07-14  8:45 UTC (permalink / raw)
  To: Alistair Francis
  Cc: QEMU Developers, open list:RISC-V, Bin Meng, Palmer Dabbelt,
	Alistair Francis

On Wed, 14 Jul 2021 at 08:22, Alistair Francis <alistair.francis@wdc.com> wrote:
>
> Coverity reports that we don't check the error result of fdt_pack(), so
> let's save the result and assert that it is 0.
>
> Fixes: Coverity CID 1458136
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  hw/riscv/boot.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 0d38bb7426..25406a3f67 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
>  {
>      uint32_t temp, fdt_addr;
>      hwaddr dram_end = dram_base + mem_size;
> -    int fdtsize = fdt_totalsize(fdt);
> +    int ret, fdtsize = fdt_totalsize(fdt);
>
>      if (fdtsize <= 0) {
>          error_report("invalid device-tree");
> @@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
>      temp = MIN(dram_end, 3072 * MiB);
>      fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
>
> -    fdt_pack(fdt);
> +    ret = fdt_pack(fdt);
> +    g_assert(ret == 0);
>      /* copy in the device tree */
>      qemu_fdt_dumpdtb(fdt, fdtsize);

Are we in the same situation as spapr.c where we believe the call
will only fail if the fdt was corrupt somehow? If so, it would be
nice to also have the comment from spapr.c:
        /* Should only fail if we've built a corrupted tree */

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
  2021-07-14  8:45   ` Peter Maydell
@ 2021-07-15  6:57     ` Alistair Francis
  -1 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-07-15  6:57 UTC (permalink / raw)
  To: Peter Maydell
  Cc: open list:RISC-V, Palmer Dabbelt, Bin Meng, Alistair Francis,
	QEMU Developers

On Wed, Jul 14, 2021 at 6:46 PM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Wed, 14 Jul 2021 at 08:22, Alistair Francis <alistair.francis@wdc.com> wrote:
> >
> > Coverity reports that we don't check the error result of fdt_pack(), so
> > let's save the result and assert that it is 0.
> >
> > Fixes: Coverity CID 1458136
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >  hw/riscv/boot.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> > index 0d38bb7426..25406a3f67 100644
> > --- a/hw/riscv/boot.c
> > +++ b/hw/riscv/boot.c
> > @@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
> >  {
> >      uint32_t temp, fdt_addr;
> >      hwaddr dram_end = dram_base + mem_size;
> > -    int fdtsize = fdt_totalsize(fdt);
> > +    int ret, fdtsize = fdt_totalsize(fdt);
> >
> >      if (fdtsize <= 0) {
> >          error_report("invalid device-tree");
> > @@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
> >      temp = MIN(dram_end, 3072 * MiB);
> >      fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
> >
> > -    fdt_pack(fdt);
> > +    ret = fdt_pack(fdt);
> > +    g_assert(ret == 0);
> >      /* copy in the device tree */
> >      qemu_fdt_dumpdtb(fdt, fdtsize);
>
> Are we in the same situation as spapr.c where we believe the call
> will only fail if the fdt was corrupt somehow? If so, it would be
> nice to also have the comment from spapr.c:
>         /* Should only fail if we've built a corrupted tree */

Yes, we are the same. I added the comment.

Alistair

>
> thanks
> -- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack()
@ 2021-07-15  6:57     ` Alistair Francis
  0 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-07-15  6:57 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Alistair Francis, QEMU Developers, open list:RISC-V, Bin Meng,
	Palmer Dabbelt

On Wed, Jul 14, 2021 at 6:46 PM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Wed, 14 Jul 2021 at 08:22, Alistair Francis <alistair.francis@wdc.com> wrote:
> >
> > Coverity reports that we don't check the error result of fdt_pack(), so
> > let's save the result and assert that it is 0.
> >
> > Fixes: Coverity CID 1458136
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >  hw/riscv/boot.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> > index 0d38bb7426..25406a3f67 100644
> > --- a/hw/riscv/boot.c
> > +++ b/hw/riscv/boot.c
> > @@ -182,7 +182,7 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
> >  {
> >      uint32_t temp, fdt_addr;
> >      hwaddr dram_end = dram_base + mem_size;
> > -    int fdtsize = fdt_totalsize(fdt);
> > +    int ret, fdtsize = fdt_totalsize(fdt);
> >
> >      if (fdtsize <= 0) {
> >          error_report("invalid device-tree");
> > @@ -198,7 +198,8 @@ uint32_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt)
> >      temp = MIN(dram_end, 3072 * MiB);
> >      fdt_addr = QEMU_ALIGN_DOWN(temp - fdtsize, 16 * MiB);
> >
> > -    fdt_pack(fdt);
> > +    ret = fdt_pack(fdt);
> > +    g_assert(ret == 0);
> >      /* copy in the device tree */
> >      qemu_fdt_dumpdtb(fdt, fdtsize);
>
> Are we in the same situation as spapr.c where we believe the call
> will only fail if the fdt was corrupt somehow? If so, it would be
> nice to also have the comment from spapr.c:
>         /* Should only fail if we've built a corrupted tree */

Yes, we are the same. I added the comment.

Alistair

>
> thanks
> -- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-07-15  6:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14  7:22 [PATCH v1 1/1] hw/riscv/boot: Check the error of fdt_pack() Alistair Francis
2021-07-14  7:22 ` Alistair Francis
2021-07-14  7:31 ` Bin Meng
2021-07-14  7:31   ` Bin Meng
2021-07-14  8:45 ` Peter Maydell
2021-07-14  8:45   ` Peter Maydell
2021-07-15  6:57   ` Alistair Francis
2021-07-15  6:57     ` Alistair Francis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.