[PATCH v2 09/10] libvduse: Switch to unsigned int for inuse field in struct VduseVirtq

Marcel Holtmann posted 10 patches 3 years, 1 month ago
Maintainers: Xie Yongji <xieyongji@bytedance.com>, "Michael S. Tsirkin" <mst@redhat.com>
There is a newer version of this series
[PATCH v2 09/10] libvduse: Switch to unsigned int for inuse field in struct VduseVirtq
Posted by Marcel Holtmann 3 years, 1 month ago
It seems there is no need to keep the inuse field signed and end up with
compiler warnings for sign-compare.

  CC       libvduse.o
libvduse.c: In function ‘vduse_queue_pop’:
libvduse.c:789:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
  789 |     if (vq->inuse >= vq->vring.num) {
      |                   ^~

Instead of casting the comparison to unsigned int, just make the inuse
field unsigned int in the fist place.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 subprojects/libvduse/libvduse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/subprojects/libvduse/libvduse.c b/subprojects/libvduse/libvduse.c
index c871bd331a6b..338ad5e352e7 100644
--- a/subprojects/libvduse/libvduse.c
+++ b/subprojects/libvduse/libvduse.c
@@ -101,7 +101,7 @@ struct VduseVirtq {
     uint16_t signalled_used;
     bool signalled_used_valid;
     int index;
-    int inuse;
+    unsigned int inuse;
     bool ready;
     int fd;
     VduseDev *dev;
-- 
2.38.1


Re: [PATCH v2 09/10] libvduse: Switch to unsigned int for inuse field in struct VduseVirtq
Posted by Yongji Xie 3 years, 1 month ago
On Wed, Dec 21, 2022 at 3:27 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> It seems there is no need to keep the inuse field signed and end up with
> compiler warnings for sign-compare.
>
>   CC       libvduse.o
> libvduse.c: In function ‘vduse_queue_pop’:
> libvduse.c:789:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
>   789 |     if (vq->inuse >= vq->vring.num) {
>       |                   ^~
>
> Instead of casting the comparison to unsigned int, just make the inuse
> field unsigned int in the fist place.
>
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  subprojects/libvduse/libvduse.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Xie Yongji <xieyongji@bytedance.com>

Thanks,
Yongji