From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A8D9C5519F for ; Wed, 18 Nov 2020 08:31:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB8F8246AE for ; Wed, 18 Nov 2020 08:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727776AbgKRIbQ (ORCPT ); Wed, 18 Nov 2020 03:31:16 -0500 Received: from smtprelay0251.hostedemail.com ([216.40.44.251]:55854 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727154AbgKRIbP (ORCPT ); Wed, 18 Nov 2020 03:31:15 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 36C4818021461; Wed, 18 Nov 2020 08:31:14 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: horse56_4e0bd9427338 X-Filterd-Recvd-Size: 2407 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA; Wed, 18 Nov 2020 08:31:11 +0000 (UTC) Message-ID: Subject: Re: [PATCH] net/core: use xx_zalloc instead xx_alloc and memset From: Joe Perches To: Tian Tao , 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 Date: Wed, 18 Nov 2020 00:31:10 -0800 In-Reply-To: <1605687308-57318-1-git-send-email-tiantao6@hisilicon.com> References: <1605687308-57318-1-git-send-email-tiantao6@hisilicon.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; }