[RFC PATCH 17/25] hw/virtio: Use correct type sizes

Philippe Mathieu-Daudé posted 25 patches 4 years, 8 months ago
[RFC PATCH 17/25] hw/virtio: Use correct type sizes
Posted by Philippe Mathieu-Daudé 4 years, 8 months ago
Use uint16_t for unsigned 16-bit data and uint32_t for unsigned 32-bit.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/hw/virtio/virtio-access.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/hw/virtio/virtio-access.h b/include/hw/virtio/virtio-access.h
index 6818a23a2d3..ae8c9feffc5 100644
--- a/include/hw/virtio/virtio-access.h
+++ b/include/hw/virtio/virtio-access.h
@@ -120,7 +120,7 @@ static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
     }
 }
 
-static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
+static inline uint16_t virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
 {
     if (virtio_access_is_big_endian(vdev)) {
         return lduw_be_p(ptr);
@@ -129,7 +129,7 @@ static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
     }
 }
 
-static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
+static inline uint32_t virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
 {
     if (virtio_access_is_big_endian(vdev)) {
         return ldl_be_p(ptr);
-- 
2.26.3

Re: [RFC PATCH 17/25] hw/virtio: Use correct type sizes
Posted by Richard Henderson 4 years, 8 months ago
On 5/18/21 1:36 PM, Philippe Mathieu-Daudé wrote:
> -static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
> +static inline uint16_t virtio_lduw_p(VirtIODevice *vdev, const void *ptr)

While this one looks obviously correct,

> -static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
> +static inline uint32_t virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
>   {
>       if (virtio_access_is_big_endian(vdev)) {
>           return ldl_be_p(ptr);

this one isn't so obvious.

Are all of the users unsigned?  If so, should we rename it ldul?


r~


Re: [RFC PATCH 17/25] hw/virtio: Use correct type sizes
Posted by Philippe Mathieu-Daudé 4 years, 8 months ago
On 5/20/21 6:27 PM, Richard Henderson wrote:
> On 5/18/21 1:36 PM, Philippe Mathieu-Daudé wrote:
>> -static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
>> +static inline uint16_t virtio_lduw_p(VirtIODevice *vdev, const void
>> *ptr)
> 
> While this one looks obviously correct,
> 
>> -static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
>> +static inline uint32_t virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
>>   {
>>       if (virtio_access_is_big_endian(vdev)) {
>>           return ldl_be_p(ptr);
> 
> this one isn't so obvious.
> 
> Are all of the users unsigned?

All except this one for which I'm not sure:

hw/block/virtio-blk.c:137:            int p =
virtio_ldl_p(VIRTIO_DEVICE(s), &req->out.type);
hw/block/virtio-blk.c-138-            bool is_read = !(p &
VIRTIO_BLK_T_OUT);

--

hw/block/virtio-blk.c:183:    bool is_write_zeroes =
(virtio_ldl_p(VIRTIO_DEVICE(s), &req->out.type) &
hw/block/virtio-blk.c-184-
~VIRTIO_BLK_T_BARRIER) == VIRTIO_BLK_T_WRITE_ZEROES;
hw/block/virtio-blk.c-185-

/* Barrier before this op. */
#define VIRTIO_BLK_T_BARRIER    0x80000000

>  If so, should we rename it ldul?

OK.