Skip to contentSkip to conversation

libvhost-user: Switch to unsigned int for inuse field in struct VuVirtq

PATCH In review Marcel Holtmann 3 participants 5 messages Dec 19, 2022 – Dec 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 7/7 libvhost-user: Switch to unsigned int for inuse field in struct VuVirtq

It seems there is no need to keep the inuse field signed and end up with compiler warnings for sign-compare.

CC libvhost-user.o
libvhost-user.c: In function ‘vu_queue_pop’:
libvhost-user.c:2763:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
2763 | if (vq->inuse >= vq->vring.num) {
| ^~
libvhost-user.c: In function ‘vu_queue_rewind’:
libvhost-user.c:2808:13: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
2808 | if (num > vq->inuse) {
| ^

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

---
 subprojects/libvhost-user/libvhost-user.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.h +1 -1
index aea7ec5061d5..8cda9b8f577a 100644
@@ -343,7 +343,7 @@ typedef struct VuVirtq {
     /* Notification enabled? */
     bool notification;
 
-    int inuse;
+    unsigned int inuse;
 
     vu_queue_handler_cb handler;
 
Signature · 1 line
2.38.1
Reviewed-by on v1 7/7
#1 lore raw
Quoted 26 lines · Marcel Holtmann

It seems there is no need to keep the inuse field signed and end up with compiler warnings for sign-compare.

CC libvhost-user.o
libvhost-user.c: In function ‘vu_queue_pop’:
libvhost-user.c:2763:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
2763 | if (vq->inuse >= vq->vring.num) {
| ^~
libvhost-user.c: In function ‘vu_queue_rewind’:
libvhost-user.c:2808:13: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
2808 | if (num > vq->inuse) {
| ^

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

---
  subprojects/libvhost-user/libvhost-user.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.h +0 -0
index aea7ec5061d5..8cda9b8f577a 100644

subprojects/libvhost-user/libvhost-user.h typedef struct VuVirtq { · line 346

Quoted 5 lines
subprojects/libvhost-user/libvhost-user.h +1 -1
@@ -343,7 +343,7 @@ typedef struct VuVirtq {
      /* Notification enabled? */
      bool notification;
 
-    int inuse;
+    unsigned int inuse;

Another use in subprojects/libvduse/libvduse.c.

Possibly both could be renamed refcount which is more meaningful.

Anyhow,

#2 lore raw

Hi Philippe,

Quoted 29 lines
Quoted 22 lines

It seems there is no need to keep the inuse field signed and end up with
compiler warnings for sign-compare.
CC libvhost-user.o
libvhost-user.c: In function ‘vu_queue_pop’:
libvhost-user.c:2763:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
2763 | if (vq->inuse >= vq->vring.num) {
| ^~
libvhost-user.c: In function ‘vu_queue_rewind’:
libvhost-user.c:2808:13: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
2808 | if (num > vq->inuse) {
| ^
Instead of casting the comparision to unsigned int, just make the inuse
field unsigned int in the fist place.

---
 subprojects/libvhost-user/libvhost-user.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.h +0 -0
index aea7ec5061d5..8cda9b8f577a 100644

subprojects/libvhost-user/libvhost-user.h typedef struct VuVirtq { · line 346

Quoted 4 lines
subprojects/libvhost-user/libvhost-user.h +1 -0
@@ -343,7 +343,7 @@ typedef struct VuVirtq {
     /* Notification enabled? */
     bool notification;
 -    int inuse;
+    unsigned int inuse;

Another use in subprojects/libvduse/libvduse.c.

Quoted 1 line

Possibly both could be renamed refcount which is more meaningful.

I quickly tried libvduse.[ch] and it has clearly less warnings than libvhost-user, but some things could be applied there as well.

I looks like only the _GNU_SOURCE and the unsigned int inuse are applicable, but there is a strict-aliasing issue that I first have to fully understand.

If patches are acceptable, I send them as well for libvduse.

Regards

Marcel

#3 lore raw
In reply to Marcel Holtmann
Quoted 13 lines · Marcel Holtmann

It seems there is no need to keep the inuse field signed and end up with compiler warnings for sign-compare.

CC libvhost-user.o
libvhost-user.c: In function ‘vu_queue_pop’:
libvhost-user.c:2763:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
2763 | if (vq->inuse >= vq->vring.num) {
| ^~
libvhost-user.c: In function ‘vu_queue_rewind’:
libvhost-user.c:2808:13: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
2808 | if (num > vq->inuse) {
| ^

Quoted 4 lines

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

Is this a part of a patchset? No threading visible and I'd rather not guess.

Quoted 22 lines
---
 subprojects/libvhost-user/libvhost-user.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
subprojects/libvhost-user/libvhost-user.h +1 -1
index aea7ec5061d5..8cda9b8f577a 100644
@@ -343,7 +343,7 @@ typedef struct VuVirtq {
     /* Notification enabled? */
     bool notification;
 
-    int inuse;
+    unsigned int inuse;
 
     vu_queue_handler_cb handler;
 
Signature · 1 line
2.38.1
#4 lore raw

Hi Michael,

Quoted 13 lines
Quoted 13 lines

It seems there is no need to keep the inuse field signed and end up with compiler warnings for sign-compare.

CC libvhost-user.o
libvhost-user.c: In function ‘vu_queue_pop’:
libvhost-user.c:2763:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Werror=sign-compare]
2763 | if (vq->inuse >= vq->vring.num) {
| ^~
libvhost-user.c: In function ‘vu_queue_rewind’:
libvhost-user.c:2808:13: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
2808 | if (num > vq->inuse) {
| ^

Quoted 8 lines
Quoted 4 lines

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

Is this a part of a patchset? No threading visible and I'd rather not guess.

I am going to re-send both series as v2.

Regards

Marcel