Skip to content

Commit 9561a8c

Browse files
pm215Michael Tokarev
authored andcommitted
hw/net/npcm_gmac.c: Send the right data for second packet in a row
The transmit loop in gmac_try_send_next_packet() is constructed in a way that means it will send incorrect data if it it sends more than one packet. The function assembles the outbound data in a dynamically allocated block of memory which is pointed to by tx_send_buffer. We track the first point in this block of memory which is not yet used with the prev_buf_size offset, initially zero. We track the size of the packet we're sending with the length variable, also initially zero. As we read chunks of data out of guest memory, we write them to tx_send_buffer[prev_buf_size], and then increment both prev_buf_size and length. (We might dynamically reallocate the buffer if needed.) When we send a packet, we checksum and send length bytes, starting at tx_send_buffer, and then we reset length to 0. This gives the right data for the first packet. But we don't reset prev_buf_size. This means that if we process more descriptors with further data for the next packet, that data will continue to accumulate at offset prev_buf_size, i.e. after the data for the first packet. But when we transmit that second packet, we send length bytes from tx_send_buffer, so we will send a packet which has the length of the second packet but the data of the first one. The fix for this is to also clear prev_buf_size after the packet has been sent -- we never need the data from packet one after we've sent it, so we can write packet two's data starting at the beginning of the buffer. Cc: [email protected] Signed-off-by: Peter Maydell <[email protected]> Signed-off-by: Jason Wang <[email protected]> (cherry picked from commit 871a6e5b339f0b5e71925ec7d3f452944a1c82d3) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 24778b1 commit 9561a8c

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

hw/net/npcm_gmac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ static void gmac_try_send_next_packet(NPCMGMACState *gmac)
615615
trace_npcm_gmac_packet_sent(DEVICE(gmac)->canonical_path, length);
616616
buf = tx_send_buffer;
617617
length = 0;
618+
prev_buf_size = 0;
618619
}
619620

620621
/* step 6 */

0 commit comments

Comments
 (0)