Skip to contentSkip to conversation

virtio-mem: Work around format specifier mismatch for RISC-V

PATCH In review Bruce Rogers 3 participants 6 messages Jul 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-mem: Work around format specifier mismatch for RISC-V

This likely affects other, less popular host architectures as well. Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of type uintptr, which isn't compatible with the format specifier used to print a user message. Since this particular usage of the underlying data seems unique, the simple fix is to just cast it to the corresponding format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +1 -1
index c12e9f79b0..fd01ffd83e 100644
@@ -754,7 +754,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
 
     if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
         error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);
         return;
     } else if (!is_power_of_2(value)) {
         error_setg(errp, "'%s' property has to be a power of two", name);
Signature · 1 line
2.27.0
#1 lore raw
Quoted 18 lines · Bruce Rogers

This likely affects other, less popular host architectures as well. Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of type uintptr, which isn't compatible with the format specifier used to print a user message. Since this particular usage of the underlying data seems unique, the simple fix is to just cast it to the corresponding format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +0 -0
index c12e9f79b0..fd01ffd83e 100644

hw/virtio/virtio-mem.c static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, · line 757

Quoted 5 lines
hw/virtio/virtio-mem.c +1 -1
@@ -754,7 +754,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
 
     if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
         error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);

Since we use PRIx32, could be better to cast VIRTIO_MEM_MIN_BLOCK_SIZE to uint32_t?

Thanks,
Stefano

Quoted 7 lines
hw/virtio/virtio-mem.c +0 -0
         return;
     } else if (!is_power_of_2(value)) {
         error_setg(errp, "'%s' property has to be a power of two", name);
Signature · 1 line
2.27.0
#2 lore raw
Quoted 20 lines · Stefano Garzarella
Quoted 19 lines · Bruce Rogers

This likely affects other, less popular host architectures as well. Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of type uintptr, which isn't compatible with the format specifier used to print a user message. Since this particular usage of the underlying data seems unique, the simple fix is to just cast it to the corresponding format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +0 -0
index c12e9f79b0..fd01ffd83e 100644
@@ -754,7 +754,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
 
Quoted 7 lines

hw/virtio/virtio-mem.c static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, · line 757

Quoted 4 lines
hw/virtio/virtio-mem.c +1 -1
     if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
         error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);

Since we use PRIx32, could be better to cast VIRTIO_MEM_MIN_BLOCK_SIZE to uint32_t?

Yeah, I guess something like

-#define VIRTIO_MEM_MIN_BLOCK_SIZE QEMU_VMALLOC_ALIGN +#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN)

would be cleaner

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 34 lines · David Hildenbrand
Quoted 20 lines · Stefano Garzarella
Quoted 19 lines · Bruce Rogers

This likely affects other, less popular host architectures as well. Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of type uintptr, which isn't compatible with the format specifier used to print a user message. Since this particular usage of the underlying data seems unique, the simple fix is to just cast it to the corresponding format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +0 -0
index c12e9f79b0..fd01ffd83e 100644
@@ -754,7 +754,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
 
Quoted 7 lines

hw/virtio/virtio-mem.c static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, · line 757

Quoted 4 lines
hw/virtio/virtio-mem.c +1 -1
     if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
         error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);

Since we use PRIx32, could be better to cast VIRTIO_MEM_MIN_BLOCK_SIZE to uint32_t?

Yeah, I guess something like

(quoted diff) +1 -1
-#define VIRTIO_MEM_MIN_BLOCK_SIZE QEMU_VMALLOC_ALIGN
+#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN)
Quoted 1 line

would be cleaner

Yeah, it is cleaner.

Otherwise we could use PRIxPTR in the error message.

Thanks,
Stefano

#4 lore raw
Quoted 30 lines · Stefano Garzarella
Quoted 29 lines · David Hildenbrand
Quoted 27 lines · Stefano Garzarella
Quoted 18 lines · Bruce Rogers

This likely affects other, less popular host architectures as well. Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of type uintptr, which isn't compatible with the format specifier used to print a user message. Since this particular usage of the underlying data seems unique, the simple fix is to just cast it to the corresponding format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +0 -0
index c12e9f79b0..fd01ffd83e 100644

hw/virtio/virtio-mem.c static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, · line 757

Quoted 5 lines
hw/virtio/virtio-mem.c +1 -1
@@ -754,7 +754,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
 
     if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
         error_setg(errp, "'%s' property has to be at least 0x%" PRIx32, name,
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);

Since we use PRIx32, could be better to cast VIRTIO_MEM_MIN_BLOCK_SIZE to uint32_t?

Quoted 8 lines
Quoted 6 lines

Yeah, I guess something like

(quoted diff) +1 -1
-#define VIRTIO_MEM_MIN_BLOCK_SIZE QEMU_VMALLOC_ALIGN
+#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN)

would be cleaner

Yeah, it is cleaner.

Bruce, can you respin if you agree? Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw
Quoted 43 lines · David Hildenbrand
Quoted 42 lines · Stefano Garzarella
Quoted 41 lines · David Hildenbrand
Quoted 28 lines · Stefano Garzarella
Quoted 27 lines · Bruce Rogers

This likely affects other, less popular host architectures as well.
Less common host architectures under linux get QEMU_VMALLOC_ALIGN (from
which VIRTIO_MEM_MIN_BLOCK_SIZE is derived) define to a variable of
type uintptr, which isn't compatible with the format specifier used to
print a user message. Since this particular usage of the underlying data
seems unique, the simple fix is to just cast it to the corresponding
format specifier.

---
 hw/virtio/virtio-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-mem.c +0 -0
index c12e9f79b0..fd01ffd83e 100644
@@ -754,7 +754,7 @@ static void

virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,

Quoted 9 lines

hw/virtio/virtio-mem.c static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name, · line 757

Quoted 5 lines

if (value < VIRTIO_MEM_MIN_BLOCK_SIZE) {
error_setg(errp, "'%s' property has to be at least
0x%" PRIx32, name,

hw/virtio/virtio-mem.c +1 -1
-                   VIRTIO_MEM_MIN_BLOCK_SIZE);
+                   (unsigned int)VIRTIO_MEM_MIN_BLOCK_SIZE);

Since we use PRIx32, could be better to cast
VIRTIO_MEM_MIN_BLOCK_SIZE
to uint32_t?

Yeah, I guess something like

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
(quoted diff) +1 -1
-#define VIRTIO_MEM_MIN_BLOCK_SIZE QEMU_VMALLOC_ALIGN
+#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)QEMU_VMALLOC_ALIGN)

would be cleaner

Yeah, it is cleaner.

Bruce, can you respin if you agree? Thanks!

Agreed.

- Bruce