From patchwork Sun Oct 1 11:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 147082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp841479vqb; Sun, 1 Oct 2023 05:17:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQx+x862lJlCcx7ybe06lC0Ym5WV3JFGrW9Hd8aeDCngSGPD8mm1fPjuJpjskJdtEkNLRg X-Received: by 2002:a05:6870:a706:b0:196:45b7:9385 with SMTP id g6-20020a056870a70600b0019645b79385mr10609224oam.27.1696162675738; Sun, 01 Oct 2023 05:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696162675; cv=none; d=google.com; s=arc-20160816; b=owX8VdYL2y5maeXm30zKJKSIj7xa4Ne7QlGArrVhCHW4aTVTE9qC6L5IpBBqYJp8aB mgnfUqoWnenqlYEQ8RrxxD3kpHsTgQAmE3kzGs8BjirJjzy66lZCIpP7t8/7pccTROaW 3n4QSKa+eq035qBi6Oy/mPd+wyayC2D9YBfvesSmoFeVDOB4xVdMLixmk2UWc6hyBSGg fb8AYh/j8kXm3opRrQAeLL5PnmGmrnbzQR0762nZ2J+op96FF7IpQ6LH20XVVlcizquX jTRs4G5eyRiISya6gcrgMOiQ5qaG3UokAD2cF+N+GCScyRo3Q1pATKMCJibM0MQV4WGR 1xRg== 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=vnDdg5+DzhgdjgHe7taJV26QihvlT8zptPXcuelUK94=; fh=KxHMk//6qYJ++e6pngwlhB64GPqdNhTrWpurz2QyY6Y=; b=CIkFSL4t+Mntw6k7p+BXnZpnOYxzIJWF+5KZyHFu1i7kKI6Ke1ha0i66p7Rr38nhTg ehsQl8D4+uotblNHfK1HjkXXsqjUMLIVykwiS9C6oynOs3utpkoANLe8KgPH7bsm0mlh mwqwTQaZwEM+ZdyhzMbOinx09zQ0tz2/1XgYO+9o4P445P9Z0vJy9J2wLnz5t1VZg3rj kG75OujNzNCwm1KvgElgpNgOZxSlvIa6EAOJ2RwPRyNhLVW4tAsCPg4scgoD8K60wxCr uWIHFvVv8a/KHZbg+n+ODqJK90qvYw0znCsYfo9PDbct6VjxDdFJfA/JGCZSXSPiEIcI iuMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=nPaerTM6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e5-20020a636905000000b0057754fd6270si22609668pgc.651.2023.10.01.05.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 05:17:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=nPaerTM6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6B271802FBA8; Sun, 1 Oct 2023 04:10:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234871AbjJALHj (ORCPT + 19 others); Sun, 1 Oct 2023 07:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234821AbjJALHh (ORCPT ); Sun, 1 Oct 2023 07:07:37 -0400 Received: from smtp.smtpout.orange.fr (smtp-25.smtpout.orange.fr [80.12.242.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE033C2 for ; Sun, 1 Oct 2023 04:07:32 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id muIKqTqNAm6tamuIKq8U2z; Sun, 01 Oct 2023 13:07:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1696158450; bh=vnDdg5+DzhgdjgHe7taJV26QihvlT8zptPXcuelUK94=; h=From:To:Cc:Subject:Date; b=nPaerTM624Q5KEjxgJswqeFpq5OhcBol67sFbIhkVF77GVRMUBXpY0DwuSsqJOOTn wVoZtLnsn5JrD9WKvVwo47eqbRqe37LfBdvE372lstTMcBReVX5Ne/KYW0ECHitHIG BiMgTnyMEZlatR/fk9sP4bO8zUmQE/nRZaUza69inlUDs29S+7LqSv5TUVY2+byAZC /Qt14ebRducV3Or2yaSeyn1BR8eYoPair4dsek646jESx9lLw/nO4p8QGHI/x4YLqX ER03VapFfVsNtESQi5WqNOJlKhxDMhW6E9sBbuojDeRTBQzTP5nH/O0hBrRrgtmmf1 iNgvxfBcgFv+A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 01 Oct 2023 13:07:30 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: keescook@chromium.org, Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netdev@vger.kernel.org, dev@openvswitch.org Subject: [PATCH net-next 1/2] net: openvswitch: Use struct_size() Date: Sun, 1 Oct 2023 13:07:22 +0200 Message-Id: <8be59c9e06fca8eff2f264abb4c2f74db0b19a9e.1696156198.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 01 Oct 2023 04:10:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778555473386036612 X-GMAIL-MSGID: 1778555473386036612 Use struct_size() instead of hand writing it. This is less verbose and more robust. Signed-off-by: Christophe JAILLET --- This is IMHO more readable, even if not perfect. However (untested): + new = kzalloc(size_add(struct_size(new, masks, size), size_mul(sizeof(u64), size)), GFP_KERNEL); looks completely unreadable to me. --- net/openvswitch/flow_table.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c index 4f3b1798e0b2..d108ae0bd0ee 100644 --- a/net/openvswitch/flow_table.c +++ b/net/openvswitch/flow_table.c @@ -220,16 +220,13 @@ static struct mask_array *tbl_mask_array_alloc(int size) struct mask_array *new; size = max(MASK_ARRAY_SIZE_MIN, size); - new = kzalloc(sizeof(struct mask_array) + - sizeof(struct sw_flow_mask *) * size + + new = kzalloc(struct_size(new, masks, size) + sizeof(u64) * size, GFP_KERNEL); if (!new) return NULL; new->masks_usage_zero_cntr = (u64 *)((u8 *)new + - sizeof(struct mask_array) + - sizeof(struct sw_flow_mask *) * - size); + struct_size(new, masks, size)); new->masks_usage_stats = __alloc_percpu(sizeof(struct mask_array_stats) + sizeof(u64) * size,