[Qemu-devel] [PATCH] virtion-net: Prefer is_power_of_2()

Michal Privoznik posted 1 patch 6 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/ae882d766ec76c57a7babc2798f16a5a31d64358.1499931846.git.mprivozn@redhat.com
Test FreeBSD passed
Test checkpatch passed
Test docker passed
Test s390x passed
hw/net/virtio-net.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Qemu-devel] [PATCH] virtion-net: Prefer is_power_of_2()
Posted by Michal Privoznik 6 years, 9 months ago
We have a function that checks if given number is power of two.
We should prefer it instead of expanding the check on our own.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 hw/net/virtio-net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 5630a9ec44..657d099c54 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1942,7 +1942,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
      */
     if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
         n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
-        (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
+        !is_power_of_2(n->net_conf.rx_queue_size)) {
         error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
                    "must be a power of 2 between %d and %d.",
                    n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE,
-- 
2.13.0


Re: [Qemu-devel] [PATCH] virtion-net: Prefer is_power_of_2()
Posted by Eric Blake 6 years, 9 months ago
On 07/13/2017 02:44 AM, Michal Privoznik wrote:

In the subject: s/virtion/virtio/

> We have a function that checks if given number is power of two.
> We should prefer it instead of expanding the check on our own.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  hw/net/virtio-net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 5630a9ec44..657d099c54 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -1942,7 +1942,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
>       */
>      if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
>          n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
> -        (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
> +        !is_power_of_2(n->net_conf.rx_queue_size)) {
>          error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
>                     "must be a power of 2 between %d and %d.",

As long as we're touching this, we should get rid of the trailing '.',
which error_setg() documents should not be used.

With those fixed, you can add:
Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH] virtion-net: Prefer is_power_of_2()
Posted by Jason Wang 6 years, 9 months ago

On 2017年07月13日 15:44, Michal Privoznik wrote:
> We have a function that checks if given number is power of two.
> We should prefer it instead of expanding the check on our own.
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>   hw/net/virtio-net.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 5630a9ec44..657d099c54 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -1942,7 +1942,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
>        */
>       if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
>           n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
> -        (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
> +        !is_power_of_2(n->net_conf.rx_queue_size)) {
>           error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
>                      "must be a power of 2 between %d and %d.",
>                      n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE,

Applied.

Thanks