From patchwork Wed Nov 18 08:15:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "tiantao (H)" X-Patchwork-Id: 11914151 X-Patchwork-Delegate: kuba@kernel.org 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 E7539C63798 for ; Wed, 18 Nov 2020 08:15:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9248022266 for ; Wed, 18 Nov 2020 08:15:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgKRIOz (ORCPT ); Wed, 18 Nov 2020 03:14:55 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7930 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726181AbgKRIOz (ORCPT ); Wed, 18 Nov 2020 03:14:55 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CbbFT6phLz6yM6; Wed, 18 Nov 2020 16:14:37 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Wed, 18 Nov 2020 16:14:42 +0800 From: Tian Tao To: , , , , , , , , , , , , Subject: [PATCH] net/core: use xx_zalloc instead xx_alloc and memset Date: Wed, 18 Nov 2020 16:15:08 +0800 Message-ID: <1605687308-57318-1-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org use kmem_cache_zalloc instead kmem_cache_alloc and memset. Signed-off-by: Tian Tao --- net/core/skbuff.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c9a5a3c..3449c1c 100644 --- 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; }