exec: Remove the duplicated check in parse_cpu_option()
PATCH 1/1 exec: Remove the duplicated check in parse_cpu_option()
The @cpu_option shouldn't be NULL, otherwise assertion from g_strsplit() should be raised as below message indicates. So it's meaningless to validate @model_pices[0] in parse_cpu_option() as it shouldn't be NULL either.
qemu-system-aarch64: GLib: g_strsplit: assertion 'string != NULL' failed
This just removes the check and unused message.
--- exec.c | 5 ----- 1 file changed, 5 deletions(-)
exec.c +0 -5
@@ -963,11 +963,6 @@ const char *parse_cpu_option(const char *cpu_option)const char *cpu_type; model_pieces =g_strsplit (cpu_option,"," ,2 ); -if (!model_pieces[0 ]) { -error_report ("-cpu option cannot be empty" ); -exit (1 ); - } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]);if (oc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);
Signature · 1 line
2.23.0
Quoted 8 lines · On Fri, 6 Dec 2019 17:33:37 +1100 Gavin Shan <[email protected]> wrote:
The @cpu_option shouldn't be NULL, otherwise assertion from
g_strsplit()should be raised as below message indicates. So it's meaningless to validate @model_pices[0] inparse_cpu_option()as it shouldn't be NULL either.qemu-system-aarch64: GLib:
g_strsplit: assertion 'string != NULL' failedThis just removes the check and unused message.
Hrm... the check isn't about @cpu_option being NULL. It is about filtering out invalid syntaxes like:
-cpu ''
or
-cpu ,some-prop
Quoted 21 lines
Signed-off-by Gavin Shan <[email protected]>--- exec.c | 5 ----- 1 file changed, 5 deletions(-)exec.c +0
-5@@ -963,11 +963,6 @@ const char *parse_cpu_option(const char *cpu_option)const char *cpu_type; model_pieces =g_strsplit (cpu_option,"," ,2 ); -if (!model_pieces[0 ]) { -error_report ("-cpu option cannot be empty" ); -exit (1 ); - } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]);if (oc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);
Quoted 12 lines · Greg Kurz
Quoted 8 lines · On Fri, 6 Dec 2019 17:33:37 +1100 Gavin Shan <[email protected]> wrote:
The @cpu_option shouldn't be NULL, otherwise assertion from
g_strsplit()should be raised as below message indicates. So it's meaningless to validate @model_pices[0] inparse_cpu_option()as it shouldn't be NULL either.qemu-system-aarch64: GLib: g_strsplit: assertion 'string != NULL' failedThis just removes the check and unused message.
Quoted 9 lines
Hrm... the check isn't about @cpu_option being NULL. It is about filtering out invalid syntaxes like:
-cpu ''
or
-cpu ,some-prop
Greg, Thanks for your review on this trivial patch.
@cpu_option[0] is NULL when we have "-cpu ''". We run into assertion raised by subsequent cpu_class_by_name(). However, @cpu_option[0] isn't NULL with something like "-cpu ,xxx", but the CPU model specific class can't be found at last.
So the validation mostly relies on cpu_class_by_name() if I'm correct. It's fine to remove the check. However, it provides explicit error message, which isn't bad though:
error_report("-cpu option cannot be empty");Quoted 12 lines
Quoted 12 lines
Signed-off-by Gavin Shan <[email protected]>--- exec.c | 5 ----- 1 file changed, 5 deletions(-)exec.c +0
-0@@ -963,11 +963,6 @@ const char *parse_cpu_option(const char *cpu_option)const char *cpu_type;
Quoted 10 lines
exec.c const char *parse_cpu_option(const char *cpu_option) · line 968
Quoted 9 lines
exec.c +0
-5model_pieces =g_strsplit (cpu_option,"," ,2 ); -if (!model_pieces[0 ]) { -error_report ("-cpu option cannot be empty" ); -exit (1 ); - } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]);if (oc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);
Regards,
Gavin
Quoted 25 lines · On Sat, 7 Dec 2019 23:56:55 +1100 Gavin Shan <[email protected]> wrote:
Quoted 12 lines · Greg Kurz
Quoted 8 lines · On Fri, 6 Dec 2019 17:33:37 +1100 Gavin Shan <[email protected]> wrote:
The @cpu_option shouldn't be NULL, otherwise assertion from
g_strsplit()should be raised as below message indicates. So it's meaningless to validate @model_pices[0] inparse_cpu_option()as it shouldn't be NULL either.qemu-system-aarch64: GLib: g_strsplit: assertion 'string != NULL' failedThis just removes the check and unused message.
Quoted 9 lines
Hrm... the check isn't about @cpu_option being NULL. It is about filtering out invalid syntaxes like:
-cpu ''
or
-cpu ,some-prop
Greg, Thanks for your review on this trivial patch.
Quoted 5 lines
@cpu_option[0] is NULL when we have "-cpu ''". We run into assertion raised by subsequent
cpu_class_by_name(). However, @cpu_option[0] isn't NULL with something like "-cpu ,xxx", but the CPU model specific class can't be found at last.
You're right, the case with a leading ',' is caught by the other check.
Quoted 6 lines
So the validation mostly relies on
cpu_class_by_name()if I'm correct. It's fine to remove the check. However, it provides explicit error message, which isn't bad though:error_report("-cpu option cannot be empty");
It's definitely not fine to remove an error message that clearly explains to the user what he has done wrong in favor of QEMU aborting and printing something cryptic like:
cpu_class_by_name: Assertion `cpu_model && cc->class_by_name' failed.
Assertions are for bugs, not for bad command line usage.
Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
Signed-off-by Gavin Shan <[email protected]>--- exec.c | 5 ----- 1 file changed, 5 deletions(-)exec.c +0
-0@@ -963,11 +963,6 @@ const char *parse_cpu_option(const char *cpu_option)const char *cpu_type;Quoted 10 lines
exec.c const char *parse_cpu_option(const char *cpu_option) · line 968
Quoted 9 lines
exec.c +0
-5model_pieces =g_strsplit (cpu_option,"," ,2 ); -if (!model_pieces[0 ]) { -error_report ("-cpu option cannot be empty" ); -exit (1 ); - } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]);if (oc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);
Quoted 3 lines
Regards,
Gavin
Cheers,
--
Greg
Quoted 43 lines · Greg Kurz
Quoted 25 lines · On Sat, 7 Dec 2019 23:56:55 +1100 Gavin Shan <[email protected]> wrote:
Quoted 12 lines · Greg Kurz
Quoted 8 lines · On Fri, 6 Dec 2019 17:33:37 +1100 Gavin Shan <[email protected]> wrote:
The @cpu_option shouldn't be NULL, otherwise assertion from
g_strsplit()should be raised as below message indicates. So it's meaningless to validate @model_pices[0] inparse_cpu_option()as it shouldn't be NULL either.qemu-system-aarch64: GLib: g_strsplit: assertion 'string != NULL' failedThis just removes the check and unused message.
Quoted 9 lines
Hrm... the check isn't about @cpu_option being NULL. It is about filtering out invalid syntaxes like:
-cpu ''
or
-cpu ,some-prop
Greg, Thanks for your review on this trivial patch.
Quoted 5 lines
@cpu_option[0] is NULL when we have "-cpu ''". We run into assertion raised by subsequent
cpu_class_by_name(). However, @cpu_option[0] isn't NULL with something like "-cpu ,xxx", but the CPU model specific class can't be found at last.You're right, the case with a leading ',' is caught by the other check.
Quoted 6 lines
So the validation mostly relies on
cpu_class_by_name()if I'm correct. It's fine to remove the check. However, it provides explicit error message, which isn't bad though:error_report("-cpu option cannot be empty");
Quoted 8 lines
It's definitely not fine to remove an error message that clearly explains to the user what he has done wrong in favor of QEMU aborting and printing something cryptic like:
cpu_class_by_name: Assertion `cpu_model && cc->class_by_name' failed.Assertions are for bugs, not for bad command line usage.
Yes, Agree as explained previously. The explicit message is a bonus at least. So please ignore this trivial patch and sorry for the noise.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Signed-off-by Gavin Shan <[email protected]>--- exec.c | 5 ----- 1 file changed, 5 deletions(-)exec.c +0
-0@@ -963,11 +963,6 @@ const char *parse_cpu_option(const char *cpu_option)const char *cpu_type;
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
exec.c const char *parse_cpu_option(const char *cpu_option) · line 968
Quoted 9 lines
exec.c +0
-5model_pieces =g_strsplit (cpu_option,"," ,2 ); -if (!model_pieces[0 ]) { -error_report ("-cpu option cannot be empty" ); -exit (1 ); - } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]);if (oc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);
Regards,
Gavin