From patchwork Fri May 19 17:42:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 96568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1416362vqo; Fri, 19 May 2023 10:52:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6McoRlf66oXDxSqWn3tel+5eWgQw1WZvMANVuE7K/jFwzs71mlv6bQUo5bRXo+4H0dTSt0 X-Received: by 2002:a05:6a20:a58f:b0:104:2200:8933 with SMTP id bc15-20020a056a20a58f00b0010422008933mr2738471pzb.62.1684518765704; Fri, 19 May 2023 10:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684518765; cv=none; d=google.com; s=arc-20160816; b=QJDxipCUF92vdfOjXVzwh7ujnlnbqUT6mufWFb4YmvNDu5tRIIc9h74z7Ndpndi9iR +8jUsow1Zi9HegbRFCk15I8ukMnoyt2FYy6AFwDccAVAoIiOG7Xu4POBzNFfu+N75W4C sQFeaHfzu7C8TJZqJfSKI6/ln/1O1HTGyKb2pkAvB8xf3Ej8DtK4wLcb7+0y2GplYlmL xoA5yKvM0Di7jfWVGYosp+ICIpHzgSWGJHHXRkHhob+LCCim2F9q4UsbRF20H6GyluIK pgSewKJeldSxfwQsU74BudWVkDom0qBt2K4+AkugkRm8bpQsH5VabISpk1EtIPAKUCKM x/zQ== 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=mAaO/WBbYiwwJShzEiCb+5IddAiptsLyN04MdP2OqLA=; b=hvuR2YDdLqgoDnAC9naCR3jEozOJqWkKXUwyLW2ZxUEZo7igIlOgsGbBSAyk9KqFQU qQbL6z9EDeFv8w+3IHYtvfduXYhGcu7YslrLV/0xTXrxjQeERFgVjGUwa5aiX1kHM74o W3Orsh+95wU5FdSglROmLwlKjfljnWSnY1ihDfjwT72pFXkSGmodVm/i4SNxzA0ar85W DD3WBCk/6glOTZiDi9dRSZzqNauPsp/p14Ij/FZ4+ljhSD5aCio+k5QC50p8GAbcYPNX ny1EpDkzS/rfMA9hsmv5QUv3jtEa5JwSuRYGXcptjk50gNn8O2VI3EhuvtFb41IIpxUR U2kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=H3CtDD3+; 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 r11-20020a632b0b000000b0051b32aa267asi3760890pgr.671.2023.05.19.10.52.26; Fri, 19 May 2023 10:52:45 -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=H3CtDD3+; 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 S230178AbjESRmj (ORCPT + 99 others); Fri, 19 May 2023 13:42:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjESRmh (ORCPT ); Fri, 19 May 2023 13:42:37 -0400 Received: from smtp.smtpout.orange.fr (smtp-30.smtpout.orange.fr [80.12.242.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5C210F for ; Fri, 19 May 2023 10:42:34 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 047Zqh2d1ln91047ZqYTB1; Fri, 19 May 2023 19:42:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1684518152; bh=mAaO/WBbYiwwJShzEiCb+5IddAiptsLyN04MdP2OqLA=; h=From:To:Cc:Subject:Date; b=H3CtDD3+Pj6GAN5+IziYhhQ43auTun8QEHu+PODCpbpFNWxka/yOMP5BimHMJhh5s lBHmslKC7aU9q4GFO/15SKg9uZWve9BNm75A8VSTMUEOpeNlVcD9fwJAHmExobhQK6 q16gz/LLg4Bhl2UFCVn2BlgX7GiPrxMxFiDwLRduECWS1vfsEC6bah6Aq7KR1X8jr5 TUmXEXfVw51CEGaR39ZYxTzVDnC/3mN02yhJEV98H8zQbRCfa3j+HxSvd0GBYcCLCT APQPim1923PLfgxiJ13Pn6+RHh9m7EwnG7k4mGlV5oM/Fmg9GVnPksi788Y4/yHFdv wsfmwtALvcfmA== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 19 May 2023 19:42:32 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-pci@vger.kernel.org Subject: [PATCH] x86/PCI: Use struct_size() Date: Fri, 19 May 2023 19:42:28 +0200 Message-Id: <00a5cc2cd322e7dea26579916ac6dda9c637aa57.1684518118.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?1766345949421108731?= X-GMAIL-MSGID: =?utf-8?q?1766345949421108731?= Use struct_size() instead of hand-writing it. It is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET --- arch/x86/pci/irq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c index a498b847d740..0de436316a1d 100644 --- a/arch/x86/pci/irq.c +++ b/arch/x86/pci/irq.c @@ -136,14 +136,14 @@ static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr, if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < ir->used) return NULL; - size = sizeof(*ir) + ir->used * sizeof(ir->slots[0]); + size = struct_size(ir, slots, ir->used); if (size > limit - addr) return NULL; DBG(KERN_DEBUG "PCI: $IRT Interrupt Routing Table found at 0x%lx\n", __pa(ir)); - size = sizeof(*rt) + ir->used * sizeof(rt->slots[0]); + size = struct_size(rt, slots, ir->used); rt = kzalloc(size, GFP_KERNEL); if (!rt) return NULL;