Thread (32 messages) flat view 32 messages, 3 authors, 2017-02-19
STALE3480d

Revision v1 of 4 in this series.

Revisions (4)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]

[PATCH net-next 11/13] net: ethernet: aquantia: Refactoring buffers copying.

From: Pavel Belous <hidden>
Date: 2017-02-15 20:03:43
Subsystem: aquantia ethernet driver (atlantic), networking drivers, the rest · Maintainers: Sukhdeep Singh, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

From: Pavel Belous <redacted>

This fix simplified copying data to the ring buffer.
Also, there was an error in the code when the second memcpy
is called with zero length. It didn't break the driver, but it's bad.

Signed-off-by: Pavel Belous <redacted>
---
 drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 25 ++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
index 4c40644..8ebed0d 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
@@ -108,18 +108,19 @@ void aq_ring_tx_append_buffs(struct aq_ring_s *self,
 			     struct aq_ring_buff_s *buffer,
 			     unsigned int buffers)
 {
-	if (likely(self->sw_tail + buffers < self->size)) {
-		memcpy(&self->buff_ring[self->sw_tail], buffer,
-		       sizeof(buffer[0]) * buffers);
-	} else {
-		unsigned int first_part = self->size - self->sw_tail;
-		unsigned int second_part = buffers - first_part;
-
-		memcpy(&self->buff_ring[self->sw_tail], buffer,
-		       sizeof(buffer[0]) * first_part);
-
-		memcpy(&self->buff_ring[0], &buffer[first_part],
-		       sizeof(buffer[0]) * second_part);
+	int buff_len = min(self->size - self->sw_tail, buffers);
+
+	memcpy(&self->buff_ring[self->sw_tail],
+	       buffer,
+	       sizeof(struct aq_ring_buff_s) * buff_len);
+
+	/* We are in the end of the ring.
+	 *  Copy remains data to beginning of the ring
+	 */
+	if (buffers > buff_len) {
+		memcpy(self->buff_ring,
+		       &buffer[buff_len],
+		       sizeof(struct aq_ring_buff_s) * (buffers - buff_len));
 	}
 }
 
-- 
2.7.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help