Re: [PATCH v2 net-next 05/15] net: sgi: ioc3-eth: allocate space for desc rings only once

From: Jakub Kicinski
Date: Thu Aug 29 2019 - 18:05:33 EST


On Fri, 30 Aug 2019 00:00:58 +0200, Thomas Bogendoerfer wrote:
> On Thu, 29 Aug 2019 14:05:37 -0700
> Jakub Kicinski <jakub.kicinski@xxxxxxxxxxxxx> wrote:
>
> > On Thu, 29 Aug 2019 17:50:03 +0200, Thomas Bogendoerfer wrote:
> > > + if (skb)
> > > + dev_kfree_skb_any(skb);
> >
> > I think dev_kfree_skb_any() accepts NULL
>
> yes, I'll drop the if
>
> > > +
> > > + /* Allocate and rx ring. 4kb = 512 entries */
> > > + ip->rxr = (unsigned long *)get_zeroed_page(GFP_ATOMIC);
> > > + if (!ip->rxr) {
> > > + pr_err("ioc3-eth: rx ring allocation failed\n");
> > > + err = -ENOMEM;
> > > + goto out_stop;
> > > + }
> > > +
> > > + /* Allocate tx rings. 16kb = 128 bufs. */
> > > + ip->txr = (struct ioc3_etxd *)__get_free_pages(GFP_KERNEL, 2);
> > > + if (!ip->txr) {
> > > + pr_err("ioc3-eth: tx ring allocation failed\n");
> > > + err = -ENOMEM;
> > > + goto out_stop;
> > > + }
> >
> > Please just use kcalloc()/kmalloc_array() here,
>
> both allocation will be replaced in patch 11 with dma_direct_alloc_pages.
> So I hope I don't need to change it here.

Ah, missed that!

> Out of curiosity does kcalloc/kmalloc_array give me the same guarantees about
> alignment ? rx ring needs to be 4KB aligned, tx ring 16KB aligned.

I don't think so, actually, I was mostly worried you are passing
address from get_page() into kfree() here ;) But patch 11 cures that,
so that's good, too.

> >, and make sure the flags
> > are set to GFP_KERNEL whenever possible. Here and in ioc3_alloc_rings()
> > it looks like GFP_ATOMIC is unnecessary.
>
> yes, I'll change it