Skip to contentSkip to conversation

virtio-rng: fix condition checking on period_ms

PATCH In review Wei Huang 2 participants 4 messages Feb 19, 2016

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 virtio-rng: fix condition checking on period_ms

The condition checking on vrng->conf.period_ms appears to be wrong, conflicting with the error comment following it.

---
 hw/virtio/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-rng.c +1 -1
index 473c044..a06427c 100644
@@ -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;
     }
Signature · 1 line
2.4.3
#1 lore raw
Quoted 14 lines · Wei Huang

The condition checking on vrng->conf.period_ms appears to be wrong, conflicting with the error comment following it.

---
 hw/virtio/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-rng.c +0 -0
index 473c044..a06427c 100644

hw/virtio/virtio-rng.c static void virtio_rng_device_realize(DeviceState *dev, Error **errp) · line 155

Quoted 8 lines
hw/virtio/virtio-rng.c +1 -1
@@ -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

#2 lore raw
Quoted 30 lines · Laszlo Ersek
Quoted 14 lines · Wei Huang

The condition checking on vrng->conf.period_ms appears to be wrong, conflicting with the error comment following it.

---
 hw/virtio/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-rng.c +0 -0
index 473c044..a06427c 100644

hw/virtio/virtio-rng.c static void virtio_rng_device_realize(DeviceState *dev, Error **errp) · line 155

Quoted 8 lines
hw/virtio/virtio-rng.c +1 -1
@@ -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.

Quoted 7 lines

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 <[email protected]>
Date:   Thu Dec 11 13:17:42 2014 +0530

virtio-rng: fix check for period_ms validity

Thanks
Laszlo

author
#3 lore raw
Quoted 34 lines · Laszlo Ersek
Quoted 33 lines · Laszlo Ersek
Quoted 14 lines · Wei Huang

The condition checking on vrng->conf.period_ms appears to be wrong, conflicting with the error comment following it.

---
 hw/virtio/virtio-rng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-rng.c +0 -0
index 473c044..a06427c 100644

hw/virtio/virtio-rng.c static void virtio_rng_device_realize(DeviceState *dev, Error **errp) · line 155

Quoted 8 lines
hw/virtio/virtio-rng.c +1 -1
@@ -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.

Quoted 8 lines
Quoted 4 lines

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

Quoted 9 lines

commit a3a292c420d2fec3c07a7ca56fbb064cd57a298a

Author: Amit Shah <[email protected]>
Date:   Thu Dec 11 13:17:42 2014 +0530

virtio-rng: fix check for period_ms validity

Thanks
Laszlo