[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4262ef98-4ba5-3f1a-5b72-208be51bdd6f@gmx.de>
Date: Wed, 15 Feb 2017 22:31:18 +0100
From: Lino Sanfilippo <LinoSanfilippo@....de>
To: Pavel Belous <Pavel.Belous@...antia.com>,
"David S . Miller" <davem@...emloft.net>
Cc: netdev@...r.kernel.org,
Simon Edelhaus <Simon.Edelhaus@...antia.com>,
Alexey Andriyanov <Alexey.Andriyanov@...antia.com>
Subject: Re: [PATCH net-next 11/13] net: ethernet: aquantia: Refactoring
buffers copying.
On 15.02.2017 21:01, Pavel Belous wrote:
> From: Pavel Belous <pavel.belous@...antia.com>
>
> 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 <pavel.belous@...antia.com>
> ---
> 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));
> }
> }
Well, you should really try to avoid copying the tx buffers _at all_.
E.g. by passing self->buff_ring to aq_ring_tx_append_buffs() instead of
the temporary array.
Regards,
Lino
buffer array.
Powered by blists - more mailing lists