qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable
@ 2013-06-03  9:20 Michael Tokarev
  2013-06-03 12:34 ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2013-06-03  9:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Michael Tokarev

Initially the code ensured that we have exactly one of
data= or file= option for -acpitable.  But after some
transformations, the condition becomes

  if (has_data == has_file) { error }

to mean, probably, that both should not be set at the same
time.  But this condition does not cover the case when
neither is set, and we generate bogus acpi table in this
case.

Instead, check if sum of the two is exactly 1.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 hw/acpi/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 42eeace..2815d8c 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -249,7 +249,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
     if (err) {
         goto out;
     }
-    if (hdrs->has_file == hdrs->has_data) {
+    if (!hdrs->has_file + !hdrs->has_data != 1) {
         error_setg(&err, "'-acpitable' requires one of 'data' or 'file'");
         goto out;
     }
-- 
1.7.10.4

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

* Re: [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable
  2013-06-03  9:20 [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable Michael Tokarev
@ 2013-06-03 12:34 ` Eric Blake
  2013-06-03 12:42   ` Michael Tokarev
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2013-06-03 12:34 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-trivial, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]

On 06/03/2013 03:20 AM, Michael Tokarev wrote:
> Initially the code ensured that we have exactly one of
> data= or file= option for -acpitable.  But after some
> transformations, the condition becomes
> 
>   if (has_data == has_file) { error }
> 
> to mean, probably, that both should not be set at the same
> time.  But this condition does not cover the case when
> neither is set, and we generate bogus acpi table in this
> case.
> 
> Instead, check if sum of the two is exactly 1.
> 
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  hw/acpi/core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> index 42eeace..2815d8c 100644
> --- a/hw/acpi/core.c
> +++ b/hw/acpi/core.c
> @@ -249,7 +249,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
>      if (err) {
>          goto out;
>      }
> -    if (hdrs->has_file == hdrs->has_data) {

NACK.

hdrs->has_file and hdrs->has_data are both bool.  Pre-patch, the table
of possible combinations is:

false == false => error message, zero given
false == true => okay, exactly one given
true == false => okay, exactly one given
true == true => error message, two given

which is already what you want.

> +    if (!hdrs->has_file + !hdrs->has_data != 1) {

Meanwhile, the post-patch logic is harder to read, in my opinion.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

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

* Re: [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable
  2013-06-03 12:34 ` Eric Blake
@ 2013-06-03 12:42   ` Michael Tokarev
  2013-06-03 18:19     ` Laszlo Ersek
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Tokarev @ 2013-06-03 12:42 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-trivial, qemu-devel

03.06.2013 16:34, Eric Blake wrote:
> On 06/03/2013 03:20 AM, Michael Tokarev wrote:
>> Initially the code ensured that we have exactly one of data= or file= option for -acpitable.  But after some transformations, the condition becomes
>> 
>> if (has_data == has_file) { error }
>> 
>> to mean, probably, that both should not be set at the same time.  But this condition does not cover the case when neither is set, and we generate bogus acpi table in this case.
>> 
>> Instead, check if sum of the two is exactly 1.
>> 
>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> --- hw/acpi/core.c |    2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/hw/acpi/core.c b/hw/acpi/core.c index 42eeace..2815d8c 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -249,7 +249,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp) if (err) { goto out; } -    if (hdrs->has_file == hdrs->has_data) {
> 
> NACK.
> 
> hdrs->has_file and hdrs->has_data are both bool.

Yup.

> Pre-patch, the table of possible combinations is:
> 
> false == false => error message, zero given false == true => okay, exactly one given true == false => okay, exactly one given true == true => error message, two given
> 
> which is already what you want.

Ok, you're right.  Thank you for spotting this!

This function has another error -- if the file specified
(either for data= or file=) can't be read, it happily
continues instead of erroring out.  _That_ is the bug
I tried to hunt but catched something else entirely ;)

Will send a real fix later today... :)

Thanks,

/mjt

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

* Re: [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable
  2013-06-03 12:42   ` Michael Tokarev
@ 2013-06-03 18:19     ` Laszlo Ersek
  2013-06-04  3:36       ` Michael Tokarev
  0 siblings, 1 reply; 5+ messages in thread
From: Laszlo Ersek @ 2013-06-03 18:19 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-trivial, qemu-devel

On 06/03/13 14:42, Michael Tokarev wrote:
> 03.06.2013 16:34, Eric Blake wrote:
>> On 06/03/2013 03:20 AM, Michael Tokarev wrote:
>>> Initially the code ensured that we have exactly one of data= or file= option for -acpitable.  But after some transformations, the condition becomes
>>>
>>> if (has_data == has_file) { error }
>>>
>>> to mean, probably, that both should not be set at the same time.  But this condition does not cover the case when neither is set, and we generate bogus acpi table in this case.
>>>
>>> Instead, check if sum of the two is exactly 1.
>>>
>>> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> --- hw/acpi/core.c |    2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/hw/acpi/core.c b/hw/acpi/core.c index 42eeace..2815d8c 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -249,7 +249,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp) if (err) { goto out; } -    if (hdrs->has_file == hdrs->has_data) {
>>
>> NACK.
>>
>> hdrs->has_file and hdrs->has_data are both bool.
> 
> Yup.
> 
>> Pre-patch, the table of possible combinations is:
>>
>> false == false => error message, zero given false == true => okay, exactly one given true == false => okay, exactly one given true == true => error message, two given
>>
>> which is already what you want.
> 
> Ok, you're right.  Thank you for spotting this!
> 
> This function has another error -- if the file specified
> (either for data= or file=) can't be read, it happily
> continues instead of erroring out.  _That_ is the bug
> I tried to hunt but catched something else entirely ;)
> 
> Will send a real fix later today... :)

Please CC me; IIRC I sought to test this code reasonably deeply when I
wrote / transformed it. I'm curious.

Thanks,
Laszlo

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

* Re: [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable
  2013-06-03 18:19     ` Laszlo Ersek
@ 2013-06-04  3:36       ` Michael Tokarev
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Tokarev @ 2013-06-04  3:36 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: qemu-devel

03.06.2013 22:19, Laszlo Ersek wrote:
> On 06/03/13 14:42, Michael Tokarev wrote:
[]
>> This function has another error -- if the file specified
>> (either for data= or file=) can't be read, it happily
>> continues instead of erroring out.  _That_ is the bug
>> I tried to hunt but catched something else entirely ;)
>>
>> Will send a real fix later today... :)
> 
> Please CC me; IIRC I sought to test this code reasonably deeply when I
> wrote / transformed it. I'm curious.

It looks like I used wrong version when encountered this bug.
I can't reproduce it with current source, and by inspecting
the source I don't see any issues with that either.  It made
me to find a non-existing bug earlier, apparently.

Thanks!

/mjt

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

end of thread, other threads:[~2013-06-04  3:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-03  9:20 [Qemu-devel] [PATCH trivial] acpi: actually require either data= or file= for -acpitable Michael Tokarev
2013-06-03 12:34 ` Eric Blake
2013-06-03 12:42   ` Michael Tokarev
2013-06-03 18:19     ` Laszlo Ersek
2013-06-04  3:36       ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).