Skip to contentSkip to conversation

hw/unicore32: remove wrong assertion in puv machine init

PATCH In review Suramya Shah 4 participants 4 messages Mar 30, 2017 – Mar 31, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 hw/unicore32: remove wrong assertion in puv machine init

Running QEMU with qemu-system-unicore32 without the kernel parameter results in an assertion error. Assert should not be used to check user provided parameters. Report an error and exit instead

---
 hw/unicore32/puv3.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/unicore32/puv3.c +5 -2
index 032078f..2c17cc9 100644
@@ -93,8 +93,11 @@ static void puv3_load_kernel(const char *kernel_filename)
     if (kernel_filename == NULL && qtest_enabled()) {
         return;
     }
-    assert(kernel_filename != NULL);
-
+    if (kernel_filename == NULL) {
+        error_report("No kernel found");
+        exit(1);
+    }
+
     /* only zImage format supported */
     size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
             KERNEL_MAX_SIZE);
Signature · 1 line
2.9.3
Reviewed-by on v5 1/1
#1 lore raw
Quoted 16 lines · Suramya Shah

Running QEMU with qemu-system-unicore32 without the kernel parameter results in an assertion error. Assert should not be used to check user provided parameters. Report an error and exit instead

---
 hw/unicore32/puv3.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/unicore32/puv3.c +0 -0
index 032078f..2c17cc9 100644
@@ -93,8 +93,11 @@ static void puv3_load_kernel(const char *kernel_filename)
     if (kernel_filename == NULL && qtest_enabled()) {
         return;
     }

hw/unicore32/puv3.c static void puv3_load_kernel(const char *kernel_filename) · line 103

Quoted 10 lines
hw/unicore32/puv3.c +5 -2
-    assert(kernel_filename != NULL);
-
+    if (kernel_filename == NULL) {
+        error_report("No kernel found");
+        exit(1);
+    }
+
     /* only zImage format supported */
     size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
             KERNEL_MAX_SIZE);

Hi,

The patch looks good to me.

Thanks,
Marcel

Acked-by
#2 lore raw
Quoted 6 lines · Suramya Shah
Quoted 5 lines

Running QEMU with qemu-system-unicore32 without the kernel parameter results in an assertion error.
Assert should not be used to check user provided parameters. Report an error and exit instead

Thanks Suramya

Quoted 34 lines
Quoted 22 lines
---
 hw/unicore32/puv3.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/unicore32/puv3.c +5 -2
index 032078f..2c17cc9 100644
@@ -93,8 +93,11 @@ static void puv3_load_kernel(const char
 *kernel_filename)
     if (kernel_filename == NULL && qtest_enabled()) {
         return;
     }
-    assert(kernel_filename != NULL);
-
+    if (kernel_filename == NULL) {
+        error_report("No kernel found");
+        exit(1);
+    }
+
     /* only zImage format supported */
     size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
Quoted 2 lines
             KERNEL_MAX_SIZE);

Hi,

The patch looks good to me.

Thanks,
Marcel

#3 lore raw
In reply to Suramya Shah
Quoted 3 lines · Suramya Shah

Running QEMU with qemu-system-unicore32 without the kernel parameter results in an assertion error. Assert should not be used to check user provided parameters. Report an error and exit instead

Nit: There should be a blank line between the description and the "Signed-off-by" line.
And another nit: Since some people are still using 80-columns terminal windows, it's also nicer to wrap the description at the 80 columns barrier (or even 76 columns already) instead.

Quoted 9 lines
---
 hw/unicore32/puv3.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/unicore32/puv3.c +0 -0
index 032078f..2c17cc9 100644

hw/unicore32/puv3.c static void puv3_load_kernel(const char *kernel_filename) · line 97

Quoted 7 lines
hw/unicore32/puv3.c +2 -2
@@ -93,8 +93,11 @@ static void puv3_load_kernel(const char *kernel_filename)
     if (kernel_filename == NULL && qtest_enabled()) {
         return;
     }
-    assert(kernel_filename != NULL);
-
+    if (kernel_filename == NULL) {
+        error_report("No kernel found");

It's maybe better to give clear instructions to the user, like:
"Need a kernel, please provide one with the '-kernel' option"

hw/unicore32/puv3.c static void puv3_load_kernel(const char *kernel_filename) · line 103

Quoted 7 lines
hw/unicore32/puv3.c +3 -0
+        exit(1);
+    }
+
     /* only zImage format supported */
     size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
             KERNEL_MAX_SIZE);

Thomas