From patchwork Sat Oct 14 06:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 152900 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2332269vqb; Fri, 13 Oct 2023 23:35:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZP75FJ+FyCiTulIDBaU4h2OMsQW2SxJ3Rr82cDw7ZdsN+kZQL2+ugVG8UVHzpXyH/TRTJ X-Received: by 2002:a05:6a20:3d04:b0:13d:d5bd:758f with SMTP id y4-20020a056a203d0400b0013dd5bd758fmr35223599pzi.6.1697265320667; Fri, 13 Oct 2023 23:35:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697265320; cv=none; d=google.com; s=arc-20160816; b=w6s4uMqQJ/2QjVlw93kslHLG0F6+cjae7DB6Zh1Ef7oiKq1cYMldU/XhPH7J2mv4iv 6XRuRYZpIRYxSe1u26tmA5wae8DWMHkfEoagLAUWppjtFfXrzU7yhJaq0d9duo3cs/ID 7b84i3v3EpT5YNAUmY8S+JZJbGCrtR7y4AM/xzuHmDKEUVU75rmJEFM5m3LtgU+hCHmu C6GHSvUnONrOTBNjurI9b9tdI5QmjYGmaB33oSWhx9kSmcXInYyWG9vzQ5kmtcss/z51 +OZb7Cez0Ec95zp1IKEeCKyY/GUwa1LfTbTIhLyoksFBgLUMizS+9UfLAP5PA+umDLrx K9oA== 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:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q24-20020a63f958000000b0057cbd803b30si6062206pgk.654.2023.10.13.23.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 23:35:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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:7 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 C2C4080C5FBD; Fri, 13 Oct 2023 23:35:19 -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 S232810AbjJNGfM (ORCPT + 20 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 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS autolearn=no 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]); Fri, 13 Oct 2023 23:35:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779711680984842453 X-GMAIL-MSGID: 1779711680984842453 Use struct_size() instead of hand writing it. This is less verbose and more robust. Signed-off-by: Christophe JAILLET Reviewed-by: Simon Horman --- 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,