[PATCH v4 04/11] hw/riscv/boot.c: exit early if filename is NULL in load_(kernel|initrd)

Daniel Henrique Barboza posted 11 patches 2 years, 8 months ago
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Cleber Rosa <crosa@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>
There is a newer version of this series
[PATCH v4 04/11] hw/riscv/boot.c: exit early if filename is NULL in load_(kernel|initrd)
Posted by Daniel Henrique Barboza 2 years, 8 months ago
riscv_load_kernel() and riscv_load_initrd() works under the assumption
that 'kernel_filename' and 'filename' are not NULL.

This is currently the case since all callers of both functions are
checking for NULL before calling them. Put an assert in both to make
sure that a NULL value for both cases would be considered a bug.

Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 hw/riscv/boot.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 98b80af51b..ad196f0fe4 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -177,6 +177,8 @@ target_ulong riscv_load_kernel(const char *kernel_filename,
 {
     uint64_t kernel_load_base, kernel_entry;
 
+    g_assert(kernel_filename != NULL);
+
     /*
      * NB: Use low address not ELF entry point to ensure that the fw_dynamic
      * behaviour when loading an ELF matches the fw_payload, fw_jump and BBL
@@ -209,6 +211,8 @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
 {
     ssize_t size;
 
+    g_assert(filename != NULL);
+
     /*
      * We want to put the initrd far enough into RAM that when the
      * kernel is uncompressed it will not clobber the initrd. However
-- 
2.38.1


Re: [PATCH v4 04/11] hw/riscv/boot.c: exit early if filename is NULL in load_(kernel|initrd)
Posted by Bin Meng 2 years, 8 months ago
On Fri, Dec 30, 2022 at 2:21 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> riscv_load_kernel() and riscv_load_initrd() works under the assumption
> that 'kernel_filename' and 'filename' are not NULL.

We should do the same in riscv_load_firmware()

>
> This is currently the case since all callers of both functions are
> checking for NULL before calling them. Put an assert in both to make
> sure that a NULL value for both cases would be considered a bug.
>
> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> ---
>  hw/riscv/boot.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 98b80af51b..ad196f0fe4 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -177,6 +177,8 @@ target_ulong riscv_load_kernel(const char *kernel_filename,
>  {
>      uint64_t kernel_load_base, kernel_entry;
>
> +    g_assert(kernel_filename != NULL);
> +
>      /*
>       * NB: Use low address not ELF entry point to ensure that the fw_dynamic
>       * behaviour when loading an ELF matches the fw_payload, fw_jump and BBL
> @@ -209,6 +211,8 @@ hwaddr riscv_load_initrd(const char *filename, uint64_t mem_size,
>  {
>      ssize_t size;
>
> +    g_assert(filename != NULL);
> +
>      /*
>       * We want to put the initrd far enough into RAM that when the
>       * kernel is uncompressed it will not clobber the initrd. However
> --

Regards,
Bin
Re: [PATCH v4 04/11] hw/riscv/boot.c: exit early if filename is NULL in load_(kernel|initrd)
Posted by Philippe Mathieu-Daudé 2 years, 8 months ago
On 30/12/22 09:58, Bin Meng wrote:
> On Fri, Dec 30, 2022 at 2:21 AM Daniel Henrique Barboza
> <dbarboza@ventanamicro.com> wrote:
>>
>> riscv_load_kernel() and riscv_load_initrd() works under the assumption
>> that 'kernel_filename' and 'filename' are not NULL.
> 
> We should do the same in riscv_load_firmware()

Can be done on top IMHO.

>> This is currently the case since all callers of both functions are
>> checking for NULL before calling them. Put an assert in both to make
>> sure that a NULL value for both cases would be considered a bug.
>>
>> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
>> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
>> ---
>>   hw/riscv/boot.c | 4 ++++
>>   1 file changed, 4 insertions(+)

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