* [PATCH] exec: Remove the duplicated check in parse_cpu_option()
@ 2019-12-06 6:33 Gavin Shan
2019-12-06 16:58 ` Greg Kurz
0 siblings, 1 reply; 5+ messages in thread
From: Gavin Shan @ 2019-12-06 6:33 UTC (permalink / raw)
To: qemu-devel; +Cc: gshan
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.
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
exec.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/exec.c b/exec.c
index ffdb518535..3cff459e43 100644
--- a/exec.c
+++ b/exec.c
@@ -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]);
--
2.23.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] exec: Remove the duplicated check in parse_cpu_option()
2019-12-06 6:33 [PATCH] exec: Remove the duplicated check in parse_cpu_option() Gavin Shan
@ 2019-12-06 16:58 ` Greg Kurz
2019-12-07 12:56 ` Gavin Shan
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2019-12-06 16:58 UTC (permalink / raw)
To: Gavin Shan; +Cc: qemu-devel
On Fri, 6 Dec 2019 17:33:37 +1100
Gavin Shan <gshan@redhat.com> 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] 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.
>
Hrm... the check isn't about @cpu_option being NULL. It is about filtering out
invalid syntaxes like:
-cpu ''
or
-cpu ,some-prop
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
> exec.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index ffdb518535..3cff459e43 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -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]);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exec: Remove the duplicated check in parse_cpu_option()
2019-12-06 16:58 ` Greg Kurz
@ 2019-12-07 12:56 ` Gavin Shan
2019-12-07 16:51 ` Greg Kurz
0 siblings, 1 reply; 5+ messages in thread
From: Gavin Shan @ 2019-12-07 12:56 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-devel
On 12/7/19 3:58 AM, Greg Kurz wrote:
> On Fri, 6 Dec 2019 17:33:37 +1100
> Gavin Shan <gshan@redhat.com> 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] 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.
>>
>
> 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");
>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>> ---
>> exec.c | 5 -----
>> 1 file changed, 5 deletions(-)
>>
>> diff --git a/exec.c b/exec.c
>> index ffdb518535..3cff459e43 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -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]);
>
Regards,
Gavin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exec: Remove the duplicated check in parse_cpu_option()
2019-12-07 12:56 ` Gavin Shan
@ 2019-12-07 16:51 ` Greg Kurz
2019-12-08 21:45 ` Gavin Shan
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2019-12-07 16:51 UTC (permalink / raw)
To: Gavin Shan; +Cc: qemu-devel
On Sat, 7 Dec 2019 23:56:55 +1100
Gavin Shan <gshan@redhat.com> wrote:
> On 12/7/19 3:58 AM, Greg Kurz wrote:
> > On Fri, 6 Dec 2019 17:33:37 +1100
> > Gavin Shan <gshan@redhat.com> 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] 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.
> >>
> >
> > 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.
>
You're right, the case with a leading ',' is caught by the other check.
> 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.
> >> Signed-off-by: Gavin Shan <gshan@redhat.com>
> >> ---
> >> exec.c | 5 -----
> >> 1 file changed, 5 deletions(-)
> >>
> >> diff --git a/exec.c b/exec.c
> >> index ffdb518535..3cff459e43 100644
> >> --- a/exec.c
> >> +++ b/exec.c
> >> @@ -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]);
> >
>
> Regards,
> Gavin
>
Cheers,
--
Greg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exec: Remove the duplicated check in parse_cpu_option()
2019-12-07 16:51 ` Greg Kurz
@ 2019-12-08 21:45 ` Gavin Shan
0 siblings, 0 replies; 5+ messages in thread
From: Gavin Shan @ 2019-12-08 21:45 UTC (permalink / raw)
To: Greg Kurz; +Cc: qemu-devel
On 12/8/19 3:51 AM, Greg Kurz wrote:
> On Sat, 7 Dec 2019 23:56:55 +1100
> Gavin Shan <gshan@redhat.com> wrote:
>
>> On 12/7/19 3:58 AM, Greg Kurz wrote:
>>> On Fri, 6 Dec 2019 17:33:37 +1100
>>> Gavin Shan <gshan@redhat.com> 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] 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.
>>>>
>>>
>>> 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.
>>
>
> You're right, the case with a leading ',' is caught by the other check.
>
>> 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.
>
Yes, Agree as explained previously. The explicit message is a bonus at least.
So please ignore this trivial patch and sorry for the noise.
>>>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>>>> ---
>>>> exec.c | 5 -----
>>>> 1 file changed, 5 deletions(-)
>>>>
>>>> diff --git a/exec.c b/exec.c
>>>> index ffdb518535..3cff459e43 100644
>>>> --- a/exec.c
>>>> +++ b/exec.c
>>>> @@ -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]);
>>>
Regards,
Gavin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-12-08 21:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 6:33 [PATCH] exec: Remove the duplicated check in parse_cpu_option() Gavin Shan
2019-12-06 16:58 ` Greg Kurz
2019-12-07 12:56 ` Gavin Shan
2019-12-07 16:51 ` Greg Kurz
2019-12-08 21:45 ` Gavin Shan
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.