mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Tian Tao <tiantao6@hisilicon.com>,
	davem@davemloft.net, kuba@kernel.org, linmiaohe@huawei.com,
	martin.varghese@nokia.com, pshelar@ovn.org, pabeni@redhat.com,
	fw@strlen.de, viro@zeniv.linux.org.uk, gnault@redhat.com,
	steffen.klassert@secunet.com, kyk.segfault@gmail.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net/core: use xx_zalloc instead xx_alloc and memset
Date: Wed, 18 Nov 2020 00:31:10 -0800	[thread overview]
Message-ID: <af05dec1ea9366c2374cb35a559a1156cf605b80.camel@perches.com> (raw)
In-Reply-To: <1605687308-57318-1-git-send-email-tiantao6@hisilicon.com>

On Wed, 2020-11-18 at 16:15 +0800, Tian Tao wrote:
> use kmem_cache_zalloc instead kmem_cache_alloc and memset.
[]
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
[]
> @@ -313,12 +313,10 @@ struct sk_buff *__build_skb(void *data, unsigned int frag_size)
>  {
>  	struct sk_buff *skb;
>  
> -	skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
> +	skb = kmem_cache_zalloc(skbuff_head_cache, GFP_ATOMIC);
>  	if (unlikely(!skb))
>  		return NULL;
>  
> -	memset(skb, 0, offsetof(struct sk_buff, tail));
> -
>  	return __build_skb_around(skb, data, frag_size);
>  }
>  
> 
> @@ -6170,12 +6168,10 @@ static void *skb_ext_get_ptr(struct skb_ext *ext, enum skb_ext_id id)
>   */
>  struct skb_ext *__skb_ext_alloc(gfp_t flags)
>  {
> -	struct skb_ext *new = kmem_cache_alloc(skbuff_ext_cache, flags);
> +	struct skb_ext *new = kmem_cache_zalloc(skbuff_ext_cache, flags);
>  
> -	if (new) {
> -		memset(new->offset, 0, sizeof(new->offset));
> +	if (new)
>  		refcount_set(&new->refcnt, 1);
> -	}
>  
>  	return new;
>  }

I think it'd be nicer to use the same form for both of these functions.
This could be:

struct skb_ext *__skb_ext_alloc(gfp_t flags)
{
	struct skb_ext *new;

	new = kmem_cache_zalloc(skbbuff_ext_cache, flags);
	if (unlikely(!new))
		return NULL;

	refcount_set(&new->refcnt, 1);

	return new;
}



  reply	other threads:[~2020-11-18  8:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18  8:15 Tian Tao
2020-11-18  8:31 ` Joe Perches [this message]
2020-11-18 10:47 ` Paolo Abeni

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=af05dec1ea9366c2374cb35a559a1156cf605b80.camel@perches.com \
    --to=joe@perches.com \
    --cc=davem@davemloft.net \
    --cc=fw@strlen.de \
    --cc=gnault@redhat.com \
    --cc=kuba@kernel.org \
    --cc=kyk.segfault@gmail.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.varghese@nokia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@ovn.org \
    --cc=steffen.klassert@secunet.com \
    --cc=tiantao6@hisilicon.com \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®