From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWs7D-0004Cg-Qp for qemu-devel@nongnu.org; Fri, 19 Feb 2016 15:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWs78-0007n0-Rr for qemu-devel@nongnu.org; Fri, 19 Feb 2016 15:57:27 -0500 References: <1455905587-4347-1-git-send-email-wei@redhat.com> From: Laszlo Ersek Message-ID: <56C781AE.5050004@redhat.com> Date: Fri, 19 Feb 2016 21:57:18 +0100 MIME-Version: 1.0 In-Reply-To: <1455905587-4347-1-git-send-email-wei@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/1] virtio-rng: fix condition checking on period_ms List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wei Huang , qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, mst@redhat.com 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 > --- > 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