From patchwork Fri May 5 21:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 90589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp704548vqo; Fri, 5 May 2023 14:42:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4p8G8YcFruX/YO8U0EJYzTs334CNnkDfkXV/1LWeL6jHXsTD4/LCrF/guyLINjriVk86gE X-Received: by 2002:a17:902:d34b:b0:1a6:386f:39a3 with SMTP id l11-20020a170902d34b00b001a6386f39a3mr2924717plk.31.1683322955030; Fri, 05 May 2023 14:42:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683322955; cv=none; d=google.com; s=arc-20160816; b=RrPwc++d+XQAB3XBlSxyPyso12ZXbOrjJG8H7MuT5UMEs1jOvYY4Tqn0SbX/WTP1jA CxAaf16SrWd65PxiJJ59jyyLI98UimRC2lxX9EqUj6k8GYzaDGbOSOxlUFYuuH/N2dh8 HFdhHHTR+ir9uRrOWrAMleAElSU2AZ9mfB12ki+O/aIORPNuc7ILv9nv1gYfh7HG+6Ew LV7AmeSCOe213J6DGGWaljHB0UfSH50CaRwGeEuJ6tMZ5Ghd8FeqZDKDOm9Zuect09aY olHnqPnrdysT2CRls7nMjbjqnCI3saDQqiG5J13pGeyyPPZdvSjKyyEDZfd2sh0YrJEV 4REw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=E2v+yIcHWIZqIecJEid9w22BOXg0tscR0zgy0Dp1DYA=; b=ur0sDzA+aXrbEZsli0nRZ6cLiPtlD9DWvCoSIOD+4guw51uU73HnETMfPEdQIaLUhl o72VgaH6BCbe+dx+e/JtG8n/h8u8UInUlAL0Gi8ho4pIXi8OrmtrcCnxG+0waqxFRskh s5wfmoEWesx/WhiQgEpObHNlGXOVnckq9GOmIl5gJ6H8yDaO3Vi/OQdyQxI4D4hEyksC g9ASu4hRR5ezeLv/k1S7aaL+/iRVykgE2atV3fOqYAxtURB3NByqEmVzmMdm+V5KN8CK AeG2aD2fumu3JapOKlUQOly4DOT42nwuWGRENkrxLeq7o6bUcC/3HJy24aMh0JpZquV6 jQLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=LeMZR1zP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a170902d2c700b0019f33cb669asi2819550plc.615.2023.05.05.14.42.20; Fri, 05 May 2023 14:42:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=LeMZR1zP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233553AbjEEV1F (ORCPT + 99 others); Fri, 5 May 2023 17:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233500AbjEEV0u (ORCPT ); Fri, 5 May 2023 17:26:50 -0400 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC1555BA8 for ; Fri, 5 May 2023 14:26:40 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id v2wmpgtTUjS6ev2wmpHBJS; Fri, 05 May 2023 23:26:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1683321998; bh=E2v+yIcHWIZqIecJEid9w22BOXg0tscR0zgy0Dp1DYA=; h=From:To:Cc:Subject:Date; b=LeMZR1zPtPMdM61turqmYF1aIOD9UBzNZ2wATj6ZBtx1ZbUJEqpyugjFah6wVA8rI iLf0xbXuhrZTroKF/NrQ09nT/Xj8CFidKYwR9HoJokXzFiIBwdQaOs0S3UUJwEjgJd vCwh6FZdlao7Grr44RazyzIPSMQOOnqOw8THagp9bcxwwZ7c/kPxQ8FlrE4z1J7t9S NfmmqZhjxdfY661SdJnt4hqidfdHfreKlZujo40oZsr63t7T8RkUjxSzppWOUV7M0L Ey6xyFGZm0Ofdjb2JCkbtKCRBfwvk8SJXh+1Quw8DokmM7YPDG9ALVGXfDcctDYDXS mr7mZhvgQGpTw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 05 May 2023 23:26:38 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Subject: [PATCH v2 net-next] netfilter: nft_set_pipapo: Use struct_size() Date: Fri, 5 May 2023 23:26:34 +0200 Message-Id: <687973f7f0f77a456ee2ebabd75cec61cba2eb98.1683321933.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765092029975074564?= X-GMAIL-MSGID: =?utf-8?q?1765092050893772353?= Use struct_size() instead of hand writing it. This is less verbose and more informative. Signed-off-by: Christophe JAILLET Reviewed-by: Simon Horman --- It will also help scripts when __counted_by macro will be added. See [1]. [1]: https://lore.kernel.org/all/6453f739.170a0220.62695.7785@mx.google.com/ v2: Fix another occurrence --- net/netfilter/nft_set_pipapo.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index 06d46d182634..34c684e121d3 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -1274,8 +1274,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) struct nft_pipapo_match *new; int i; - new = kmalloc(sizeof(*new) + sizeof(*dst) * old->field_count, - GFP_KERNEL); + new = kmalloc(struct_size(new, f, old->field_count), GFP_KERNEL); if (!new) return ERR_PTR(-ENOMEM); @@ -2059,8 +2058,7 @@ static int nft_pipapo_init(const struct nft_set *set, if (field_count > NFT_PIPAPO_MAX_FIELDS) return -EINVAL; - m = kmalloc(sizeof(*priv->match) + sizeof(*f) * field_count, - GFP_KERNEL); + m = kmalloc(struct_size(m, f, field_count), GFP_KERNEL); if (!m) return -ENOMEM;