]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/net: Avoid casting non-const pointer, use address_space_write()
authorPhilippe Mathieu-Daudé <philmd@redhat.com>
Thu, 20 Feb 2020 10:25:40 +0000 (11:25 +0100)
committerPhilippe Mathieu-Daudé <philmd@redhat.com>
Thu, 20 Feb 2020 13:47:08 +0000 (14:47 +0100)
The NetReceive prototype gets a const buffer:

  typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);

We already have the address_space_write() method to write a const
buffer to an address space. Use it to avoid:

  hw/net/i82596.c: In function ‘i82596_receive’:
  hw/net/i82596.c:644:54: error: passing argument 4 of ‘address_space_rw’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]

This commit was produced with the included Coccinelle script
scripts/coccinelle/exec_rw_const.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
hw/net/dp8393x.c
hw/net/i82596.c
scripts/coccinelle/exec_rw_const.cocci

index a134d431ae3fd2721493206390fdda0c3b0ee3f0..580ae4437eaba9f8983c894592bcf5aabde732b9 100644 (file)
@@ -787,8 +787,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
     /* Put packet into RBA */
     DPRINTF("Receive packet at %08x\n", dp8393x_crba(s));
     address = dp8393x_crba(s);
-    address_space_rw(&s->as, address,
-        MEMTXATTRS_UNSPECIFIED, (uint8_t *)buf, rx_len, 1);
+    address_space_write(&s->as, address, MEMTXATTRS_UNSPECIFIED, buf, rx_len);
     address += rx_len;
     address_space_rw(&s->as, address,
         MEMTXATTRS_UNSPECIFIED, (uint8_t *)&checksum, 4, 1);
index 3a0e1ec4c05b070f900ba651e057f1bde1107bbb..a292984e06f01cd6dda41c0ce87e80222458399b 100644 (file)
@@ -640,8 +640,8 @@ ssize_t i82596_receive(NetClientState *nc, const uint8_t *buf, size_t sz)
             }
             rba = get_uint32(rbd + 8);
             /* printf("rba is 0x%x\n", rba); */
-            address_space_rw(&address_space_memory, rba,
-                MEMTXATTRS_UNSPECIFIED, (void *)buf, num, 1);
+            address_space_write(&address_space_memory, rba,
+                                MEMTXATTRS_UNSPECIFIED, buf, num);
             rba += num;
             buf += num;
             len -= num;
index 7e42682240c76dcf75b10d958822df3ce5f9999e..87897dd1b36eb64eece4c9267e93fe23201026c9 100644 (file)
@@ -9,6 +9,20 @@
            --dir .
 */
 
+// Use address_space_write instead of casting to non-const
+@@
+type T;
+const T *V;
+expression E1, E2, E3, E4;
+@@
+(
+- address_space_rw(E1, E2, E3, (T *)V, E4, 1)
++ address_space_write(E1, E2, E3, V, E4)
+|
+- address_space_rw(E1, E2, E3, (void *)V, E4, 1)
++ address_space_write(E1, E2, E3, V, E4)
+)
+
 // Remove useless cast
 @@
 expression E1, E2, E3, E4;