All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Felix Fietkau <nbd@openwrt.org>
Cc: Network Development <netdev@vger.kernel.org>,
	Hauke Mehrtens <hauke@hauke-m.de>
Subject: Re: [PATCH v6 7/9] bgmac: simplify dma init/cleanup
Date: Tue, 14 Apr 2015 09:24:35 +0200	[thread overview]
Message-ID: <CACna6rz+fY-MGKJw858-i47rx5_9ZKhW2ik-YEpDGyMSqALK=A@mail.gmail.com> (raw)
In-Reply-To: <1428968537-6181-7-git-send-email-nbd@openwrt.org>

On 14 April 2015 at 01:42, Felix Fietkau <nbd@openwrt.org> wrote:
> Instead of allocating buffers at device init time and initializing
> descriptors at device open, do both at the same time (during open).
> Free all buffers when closing the device.
>
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> ---
>  drivers/net/ethernet/broadcom/bgmac.c | 70 +++++++++++++++++------------------
>  1 file changed, 35 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
> index eafdbca..aad80a7 100644
> --- a/drivers/net/ethernet/broadcom/bgmac.c
> +++ b/drivers/net/ethernet/broadcom/bgmac.c
> @@ -557,18 +557,26 @@ static void bgmac_dma_ring_desc_free(struct bgmac *bgmac,
>                           ring->dma_base);
>  }
>
> -static void bgmac_dma_free(struct bgmac *bgmac)
> +static void bgmac_dma_cleanup(struct bgmac *bgmac)
>  {
>         int i;
>
> -       for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
> +       for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
>                 bgmac_dma_tx_ring_free(bgmac, &bgmac->tx_ring[i]);
> -               bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
> -       }
> -       for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
> +
> +       for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
>                 bgmac_dma_rx_ring_free(bgmac, &bgmac->rx_ring[i]);
> +}
> +
> +static void bgmac_dma_free(struct bgmac *bgmac)
> +{
> +       int i;
> +
> +       for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
> +               bgmac_dma_ring_desc_free(bgmac, &bgmac->tx_ring[i]);
> +
> +       for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
>                 bgmac_dma_ring_desc_free(bgmac, &bgmac->rx_ring[i]);
> -       }
>  }
>
>  static int bgmac_dma_alloc(struct bgmac *bgmac)
> @@ -693,8 +690,13 @@ static void bgmac_dma_init(struct bgmac *bgmac)
>                 if (ring->unaligned)
>                         bgmac_dma_rx_enable(bgmac, ring);
>
> -               for (j = 0; j < ring->num_slots; j++)
> +               for (j = 0; j < ring->num_slots; j++) {
> +                       err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[j]);
> +                       if (err)
> +                               return err;

I don't think I like this logic. Instead of allowing caller to just
detect an error and handle it, you require it to do a cleanup. I think
bgmac_dma_init shouldn't leave any mess after failing.

If you e.g. call alloc_netdev and it fails, you don't care about
freeing whatever is allocated before failing.

I think you should call bgmac_dma_cleanup directly in a bgmac_dma_init
in case of error.

  reply	other threads:[~2015-04-14  7:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 23:42 [PATCH v6 1/9] bgmac: simplify tx ring index handling Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 2/9] bgmac: leave interrupts disabled as long as there is work to do Felix Fietkau
2015-04-14  5:40   ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 3/9] bgmac: set received skb headroom to NET_SKB_PAD Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 4/9] bgmac: simplify/optimize rx DMA error handling Felix Fietkau
2015-04-14  5:55   ` Rafał Miłecki
2015-04-14  9:13     ` Felix Fietkau
2015-04-14  9:19       ` Rafał Miłecki
2015-04-14  9:26         ` Felix Fietkau
2015-04-14  9:32           ` Rafał Miłecki
2015-04-14  9:37           ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 5/9] bgmac: add check for oversized packets Felix Fietkau
2015-04-14  5:56   ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 6/9] bgmac: increase rx ring size from 511 to 512 Felix Fietkau
2015-04-14  5:57   ` Rafał Miłecki
2015-04-13 23:42 ` [PATCH v6 7/9] bgmac: simplify dma init/cleanup Felix Fietkau
2015-04-14  7:24   ` Rafał Miłecki [this message]
2015-04-13 23:42 ` [PATCH v6 8/9] bgmac: fix DMA rx corruption Felix Fietkau
2015-04-13 23:42 ` [PATCH v6 9/9] bgmac: drop ring->num_slots Felix Fietkau
2015-04-14  6:38   ` Rafał Miłecki
2015-04-14  5:38 ` [PATCH v6 1/9] bgmac: simplify tx ring index handling Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACna6rz+fY-MGKJw858-i47rx5_9ZKhW2ik-YEpDGyMSqALK=A@mail.gmail.com' \
    --to=zajec5@gmail.com \
    --cc=hauke@hauke-m.de \
    --cc=nbd@openwrt.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.