[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 085/136] hw/net: Avoid casting non-const pointer, use address_spac
From: |
Paolo Bonzini |
Subject: |
[PULL 085/136] hw/net: Avoid casting non-const pointer, use address_space_write() |
Date: |
Tue, 25 Feb 2020 12:50:15 +0100 |
From: Philippe Mathieu-Daudé <address@hidden>
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é <address@hidden>
---
hw/net/dp8393x.c | 3 +--
hw/net/i82596.c | 4 ++--
scripts/coccinelle/exec_rw_const.cocci | 14 ++++++++++++++
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
index a134d43..580ae44 100644
--- a/hw/net/dp8393x.c
+++ b/hw/net/dp8393x.c
@@ -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);
diff --git a/hw/net/i82596.c b/hw/net/i82596.c
index 3a0e1ec..a292984 100644
--- a/hw/net/i82596.c
+++ b/hw/net/i82596.c
@@ -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;
diff --git a/scripts/coccinelle/exec_rw_const.cocci
b/scripts/coccinelle/exec_rw_const.cocci
index 7e42682..87897dd 100644
--- a/scripts/coccinelle/exec_rw_const.cocci
+++ b/scripts/coccinelle/exec_rw_const.cocci
@@ -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;
--
1.8.3.1
- [PULL 060/136] ppc/mac_newworld: use memdev for RAM, (continued)
- [PULL 060/136] ppc/mac_newworld: use memdev for RAM, Paolo Bonzini, 2020/02/25
- [PULL 071/136] sparc/niagara: use memdev for RAM, Paolo Bonzini, 2020/02/25
- [PULL 069/136] sparc/leon3: use memdev for RAM, Paolo Bonzini, 2020/02/25
- [PULL 076/136] hostmem: introduce "prealloc-threads" property, Paolo Bonzini, 2020/02/25
- [PULL 078/136] tests/numa-test: make top level args dynamic and g_autofree(cli) cleanups, Paolo Bonzini, 2020/02/25
- [PULL 074/136] exec: drop bogus mem_path from qemu_ram_alloc_from_fd(), Paolo Bonzini, 2020/02/25
- [PULL 068/136] ppc/virtex_ml507: use memdev for RAM, Paolo Bonzini, 2020/02/25
- [PULL 075/136] make mem_path local variable, Paolo Bonzini, 2020/02/25
- [PULL 081/136] hw: Remove unnecessary cast when calling dma_memory_read(), Paolo Bonzini, 2020/02/25
- [PULL 083/136] exec: Let flatview API take void pointer arguments, Paolo Bonzini, 2020/02/25
- [PULL 085/136] hw/net: Avoid casting non-const pointer, use address_space_write(),
Paolo Bonzini <=
- [PULL 077/136] hostmem: fix strict bind policy, Paolo Bonzini, 2020/02/25
- [PULL 073/136] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize(), Paolo Bonzini, 2020/02/25
- [PULL 079/136] tests:numa-test: use explicit memdev to specify node RAM, Paolo Bonzini, 2020/02/25
- [PULL 070/136] sparc/sun4m: use memdev for RAM, Paolo Bonzini, 2020/02/25
- [PULL 072/136] remove no longer used memory_region_allocate_system_memory(), Paolo Bonzini, 2020/02/25
- [PULL 080/136] scripts/git.orderfile: Display Cocci scripts before code modifications, Paolo Bonzini, 2020/02/25
- [PULL 082/136] exec: Rename ram_ptr variable, Paolo Bonzini, 2020/02/25
- [PULL 084/136] exec: Let the address_space API use void pointer arguments, Paolo Bonzini, 2020/02/25
- [PULL 087/136] exec: Let the cpu_[physical]_memory API use void pointer arguments, Paolo Bonzini, 2020/02/25
- [PULL 089/136] hw/ide/internal: Remove unused DMARestartFunc typedef, Paolo Bonzini, 2020/02/25