* [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms
@ 2016-02-19 18:13 Wei Huang
2016-02-19 20:57 ` Laszlo Ersek
0 siblings, 1 reply; 4+ messages in thread
From: Wei Huang @ 2016-02-19 18:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, mst
The condition checking on vrng->conf.period_ms appears to be wrong,
conflicting with the error comment following it.
Signed-off-by: Wei Huang <wei@redhat.com>
---
hw/virtio/virtio-rng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 473c044..a06427c 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -149,7 +149,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
VirtIORNG *vrng = VIRTIO_RNG(dev);
Error *local_err = NULL;
- if (!vrng->conf.period_ms > 0) {
+ if (!(vrng->conf.period_ms > 0)) {
error_setg(errp, "'period' parameter expects a positive integer");
return;
}
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms
2016-02-19 18:13 [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms Wei Huang
@ 2016-02-19 20:57 ` Laszlo Ersek
2016-02-19 20:59 ` Laszlo Ersek
0 siblings, 1 reply; 4+ messages in thread
From: Laszlo Ersek @ 2016-02-19 20:57 UTC (permalink / raw)
To: Wei Huang, qemu-devel; +Cc: qemu-trivial, mst
On 02/19/16 19:13, Wei Huang wrote:
> The condition checking on vrng->conf.period_ms appears to be wrong,
> conflicting with the error comment following it.
>
> Signed-off-by: Wei Huang <wei@redhat.com>
> ---
> hw/virtio/virtio-rng.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
> index 473c044..a06427c 100644
> --- a/hw/virtio/virtio-rng.c
> +++ b/hw/virtio/virtio-rng.c
> @@ -149,7 +149,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
> VirtIORNG *vrng = VIRTIO_RNG(dev);
> Error *local_err = NULL;
>
> - if (!vrng->conf.period_ms > 0) {
> + if (!(vrng->conf.period_ms > 0)) {
> error_setg(errp, "'period' parameter expects a positive integer");
> return;
> }
>
The current condition is absolutely weird, but I think it happens to
work correctly:
Period_ms has type uint32_t. If it is positive, then !period_ms is zero.
0>0 is false, hence the error message is not printed.
If period_ms is zero, then !period_ms is 1. 1>0 is true, hence the error
message is printed.
I would rewrite the check as
if (vrng->conf.period_ms == 0) {
error_setg(...)
Thanks
Laszlo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms
2016-02-19 20:57 ` Laszlo Ersek
@ 2016-02-19 20:59 ` Laszlo Ersek
2016-02-19 21:07 ` Wei Huang
0 siblings, 1 reply; 4+ messages in thread
From: Laszlo Ersek @ 2016-02-19 20:59 UTC (permalink / raw)
To: Wei Huang, qemu-devel; +Cc: qemu-trivial, mst
On 02/19/16 21:57, Laszlo Ersek wrote:
> On 02/19/16 19:13, Wei Huang wrote:
>> The condition checking on vrng->conf.period_ms appears to be wrong,
>> conflicting with the error comment following it.
>>
>> Signed-off-by: Wei Huang <wei@redhat.com>
>> ---
>> hw/virtio/virtio-rng.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
>> index 473c044..a06427c 100644
>> --- a/hw/virtio/virtio-rng.c
>> +++ b/hw/virtio/virtio-rng.c
>> @@ -149,7 +149,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
>> VirtIORNG *vrng = VIRTIO_RNG(dev);
>> Error *local_err = NULL;
>>
>> - if (!vrng->conf.period_ms > 0) {
>> + if (!(vrng->conf.period_ms > 0)) {
>> error_setg(errp, "'period' parameter expects a positive integer");
>> return;
>> }
>>
>
> The current condition is absolutely weird, but I think it happens to
> work correctly:
>
> Period_ms has type uint32_t. If it is positive, then !period_ms is zero.
> 0>0 is false, hence the error message is not printed.
>
> If period_ms is zero, then !period_ms is 1. 1>0 is true, hence the error
> message is printed.
>
> I would rewrite the check as
>
> if (vrng->conf.period_ms == 0) {
> error_setg(...)
... actually, what the heck are you looking at? :) This has been fixed
up in:
commit a3a292c420d2fec3c07a7ca56fbb064cd57a298a
Author: Amit Shah <amit.shah@redhat.com>
Date: Thu Dec 11 13:17:42 2014 +0530
virtio-rng: fix check for period_ms validity
Thanks
Laszlo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms
2016-02-19 20:59 ` Laszlo Ersek
@ 2016-02-19 21:07 ` Wei Huang
0 siblings, 0 replies; 4+ messages in thread
From: Wei Huang @ 2016-02-19 21:07 UTC (permalink / raw)
To: Laszlo Ersek, qemu-devel; +Cc: qemu-trivial, mst
On 02/19/2016 02:59 PM, Laszlo Ersek wrote:
> On 02/19/16 21:57, Laszlo Ersek wrote:
>> On 02/19/16 19:13, Wei Huang wrote:
>>> The condition checking on vrng->conf.period_ms appears to be wrong,
>>> conflicting with the error comment following it.
>>>
>>> Signed-off-by: Wei Huang <wei@redhat.com>
>>> ---
>>> hw/virtio/virtio-rng.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
>>> index 473c044..a06427c 100644
>>> --- a/hw/virtio/virtio-rng.c
>>> +++ b/hw/virtio/virtio-rng.c
>>> @@ -149,7 +149,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
>>> VirtIORNG *vrng = VIRTIO_RNG(dev);
>>> Error *local_err = NULL;
>>>
>>> - if (!vrng->conf.period_ms > 0) {
>>> + if (!(vrng->conf.period_ms > 0)) {
>>> error_setg(errp, "'period' parameter expects a positive integer");
>>> return;
>>> }
>>>
>>
>> The current condition is absolutely weird, but I think it happens to
>> work correctly:
>>
>> Period_ms has type uint32_t. If it is positive, then !period_ms is zero.
>> 0>0 is false, hence the error message is not printed.
>>
>> If period_ms is zero, then !period_ms is 1. 1>0 is true, hence the error
>> message is printed.
>>
>> I would rewrite the check as
>>
>> if (vrng->conf.period_ms == 0) {
>> error_setg(...)
>
> ... actually, what the heck are you looking at? :) This has been fixed
> up in:
>
Oops. It looks like I was looking at an older HEAD. :-( Please ignore
it. Sorry for the noise and thanks for pointing it out.
-Wei
> commit a3a292c420d2fec3c07a7ca56fbb064cd57a298a
> Author: Amit Shah <amit.shah@redhat.com>
> Date: Thu Dec 11 13:17:42 2014 +0530
>
> virtio-rng: fix check for period_ms validity
>
> Thanks
> Laszlo
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-19 21:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 18:13 [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms Wei Huang
2016-02-19 20:57 ` Laszlo Ersek
2016-02-19 20:59 ` Laszlo Ersek
2016-02-19 21:07 ` Wei Huang
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).