Skip to contentSkip to conversation

virtio_ring: sparse warning fixup

PATCH In review Michael S. Tsirkin 2 participants 2 messages Jul 10, 2020 – Jul 13, 2020 virtio core

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio_ring: sparse warning fixup

virtio_store_mb was built with split ring in mind so it accepts __virtio16 arguments. Packed ring uses __le16 values, so sparse complains. It's just a store with some barriers so let's convert it to a macro, we don't loose too much type safety by doing that.

---
 include/linux/virtio_ring.h | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
include/linux/virtio_ring.h +9 -10
index 3dc70adfe5f5..b485b13fa50b 100644
@@ -46,16 +46,15 @@ static inline void virtio_wmb(bool weak_barriers)
 		dma_wmb();
 }
 
-static inline void virtio_store_mb(bool weak_barriers,
-				   __virtio16 *p, __virtio16 v)
-{
-	if (weak_barriers) {
-		virt_store_mb(*p, v);
-	} else {
-		WRITE_ONCE(*p, v);
-		mb();
-	}
-}
+#define virtio_store_mb(weak_barriers, p, v) \
+do { \
+	if (weak_barriers) { \
+		virt_store_mb(*p, v); \
+	} else { \
+		WRITE_ONCE(*p, v); \
+		mb(); \
+	} \
+} while (0) \
 
 struct virtio_device;
 struct virtqueue;
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 30 lines · Michael S. Tsirkin

virtio_store_mb was built with split ring in mind so it accepts __virtio16 arguments. Packed ring uses __le16 values, so sparse complains. It's just a store with some barriers so let's convert it to a macro, we don't loose too much type safety by doing that.

---
  include/linux/virtio_ring.h | 19 +++++++++----------
  1 file changed, 9 insertions(+), 10 deletions(-)
include/linux/virtio_ring.h +2 -10
index 3dc70adfe5f5..b485b13fa50b 100644
@@ -46,16 +46,15 @@ static inline void virtio_wmb(bool weak_barriers)
  		dma_wmb();
  }
 
-static inline void virtio_store_mb(bool weak_barriers,
-				   __virtio16 *p, __virtio16 v)
-{
-	if (weak_barriers) {
-		virt_store_mb(*p, v);
-	} else {
-		WRITE_ONCE(*p, v);
-		mb();
-	}
-}
+#define virtio_store_mb(weak_barriers, p, v) \
+do { \

include/linux/virtio_ring.h static inline void virtio_wmb(bool weak_barriers) · line 60

Quoted 10 lines
include/linux/virtio_ring.h +7 -0
+	if (weak_barriers) { \
+		virt_store_mb(*p, v); \
+	} else { \
+		WRITE_ONCE(*p, v); \
+		mb(); \
+	} \
+} while (0) \
 
  struct virtio_device;
  struct virtqueue;