Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1390978rdg; Fri, 13 Oct 2023 23:35:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0Y+BYKzG2apR4c3iMah10wucmjm/h548BF3VLKQI3gsuhpl8Wf1KZ3SVT1BUXsnfBZFpS X-Received: by 2002:a17:90a:1e:b0:27d:3a34:2194 with SMTP id 30-20020a17090a001e00b0027d3a342194mr3563343pja.14.1697265325157; Fri, 13 Oct 2023 23:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697265325; cv=none; d=google.com; s=arc-20160816; b=hXY0E3tOn0Q+aN/n2QIu6J5bmH/GFwR0t660Rk0yPMpw7Gs161xpcdmltXO5icw8a6 c70r/vfdmjQCSxeJ+Sik4d3pvJmSk4M287jvwPh9DIgIBt1ALqlil68tSqSGGwrIhBFP dNv86cLHN2CAP4Z3PGAwytSw13uhdWF7lLDyAqA6ZWFOIHYOxHBa43v6EXhEdfCOStCc 0BfJY90NKjUOVM2zUHnL5muleBezykwK2JdoDZijDNKN69bRWI4BcLxiCwDyVW9OUXsn MrOwxUuHPmCKFNKYJolUeOS/RExyN8WJeU6A/Z9HC5CxM4kCIQQZ2NSTkGe3r3PLUmM2 8l7A== 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=CxADXXhhxjM3tj/eg2DX7kLfA3AdAqKP4iJHaVmLDhs=; fh=ygUOvN60TzSrHmYn97n/jVNXZVSdP7Gk3Qexb2pf3/s=; b=iKZrrHR2ai+ccYNCaOI81eAdm6M+5PZ+Fgh2zd0ATMVCWFikqMOz1WyYziLBBnamq1 lashSQMW2x61WiRhfPTaizV3Q4ab7XUazNpCd4c39WfTz6B6TrDesd1FXrD4SO6k2tZ4 HdyeJMdo01LWXrfU6BGa/X1K0l9mO+5WPRUFY/zAxSdi7bnUwBZy1u7moBCziA+6cgiz 2NLt1wxzF39SBAab7nnEWQBcfg9S9+fo63+A+xT1Qe/U+XFuAxp+rFbUVM4QIEyh+ctQ GWhfsZj7MVazR9FU0JvZ+QGAxK+pxQVRghxA4G0cdNjIKPa+rFrD987+7B8OHZnihcbx bFJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ILrQ4XJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id w4-20020a17090abc0400b0027d0b9c0b90si1650745pjr.153.2023.10.13.23.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 23:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ILrQ4XJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 5B5B582DFD21; Fri, 13 Oct 2023 23:35:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbjJNGfM (ORCPT + 99 others); Sat, 14 Oct 2023 02:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJNGfL (ORCPT ); Sat, 14 Oct 2023 02:35:11 -0400 Received: from smtp.smtpout.orange.fr (smtp-13.smtpout.orange.fr [80.12.242.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65547C2 for ; Fri, 13 Oct 2023 23:35:03 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id rYEiqpnupvhM3rYEiqYMnU; Sat, 14 Oct 2023 08:35:01 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1697265301; bh=CxADXXhhxjM3tj/eg2DX7kLfA3AdAqKP4iJHaVmLDhs=; h=From:To:Cc:Subject:Date; b=ILrQ4XJbS8aVq6H2ZU6HW0E5LFiW+PZDIamMUNxW2ttR9mqFi48qE2Kkzf2egfDsQ l+RoM4OHVWa9Lv7u5o/qSMUVL4Romq48Z9BfW43m0SczUedDrNW1bXX2kwEOUnRK9P 0r3hrsp/tYGbCn3ekbTAXnyu40mqE2oEBNLiPsfa3MANvqrrNiHJfSNRidlNvfFEoc 4U1X+13yFgBcoWJNIg07jP5b6/d/xLQRTRCmX0B8xNj+gfKYa9dtsg0jK3mdFm0lu3 GfPjdxZ4jMTs+PQBozZx/Zg7GhCmnshc9xkBcSl73W/DfkR2zYNnR/1HE7zleI6WNb yjVWG1rGushcA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 14 Oct 2023 08:35:01 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netdev@vger.kernel.org, dev@openvswitch.org Subject: [PATCH v2 1/2] net: openvswitch: Use struct_size() Date: Sat, 14 Oct 2023 08:34:52 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Fri, 13 Oct 2023 23:35:22 -0700 (PDT) Use struct_size() instead of hand writing it. This is less verbose and more robust. Signed-off-by: Christophe JAILLET --- v2: No change v1: https://lore.kernel.org/all/8be59c9e06fca8eff2f264abb4c2f74db0b19a9e.1696156198.git.christophe.jaillet@wanadoo.fr/ 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, -- 2.34.1