From patchwork Sat Jul 22 16:43:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 124350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp913037vqg; Sat, 22 Jul 2023 10:34:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlH29Zcjb/nxH4mzaVw3g7AbH6tm9w5qxHcXDSeBMZqhgCTUsIdPMjK8YPOZlk9fI0YxPsQ2 X-Received: by 2002:a17:906:5303:b0:99b:7297:fbf0 with SMTP id h3-20020a170906530300b0099b7297fbf0mr3118755ejo.65.1690047253951; Sat, 22 Jul 2023 10:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690047253; cv=none; d=google.com; s=arc-20160816; b=wDHGoiJaFQ/dNhKXUWV1mmEj1/uKGiQqR0mwSE86PDCJvWppmUrTrc3UrtCeYfgRNt lpUZzqs6Awy/Nx7VJTGX8k+QBW8lEwtDdpYm5/79gDQVbjzB7RtpuBojqTHsXyoO0lL5 Z8nF842smWZN9Y1PpRASrjP6kMqNv7rGKHLlPo8atDDC+UcLemELE1DMZr8bFZubTCtn RR7PX22gg1Z6Yxc1kj9/q8RP6nNMwZalQ6RR5qWDH1KN3ekjzfeZgpm7Reirug2rqGfm 44B1P4Pmr12m8hQ28l07fAVTN+SaFR95uhaes+ocv53kjnaaoZ0rmmu5NhCOYd42oJHD 7KZg== 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=EvXOg9Wf3mDu5fhjycUMuKTbOj5nWm5mbNPIU3YSZCs=; fh=+YGy7aQmW5gIwqQmJLeM1JssAbHrK3xCsZBG8M8E1aI=; b=xVY+KE8mqFSqrTsyKPP1AWmG4Ld+T7MOJfWlJ1qoOnxpeSdVkE36cMIelUOHZb/05Q eKHhCKxkW8VX7zu94K1cg6ja9LiSEfFI27+iZEJS7PkxW61P0n7NrewgxnNEJqzTib4x 4nYmKQiQxY2UFPDHNQRJhMhj5FmCEcDRPq94Vq6imYYRiYzjJl7h3Slc6CPLijwRi5S8 sO2dpuDKszOOUQ6CeNLWAy6uMHxGmN/TdF9UrPsTSX2iSBpMYbD8roGrIz2d2Xrsq04V APgWdxmgAwa3sZMg/lYWQ2y+esBxPkaMe8RdX+sbEIQGjVPj2+0n3gf55OBUOuYwbLHB hmWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ly9sn9Y7; 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 d19-20020aa7d5d3000000b0051def0da189si3625068eds.547.2023.07.22.10.33.48; Sat, 22 Jul 2023 10:34:13 -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=ly9sn9Y7; 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 S229591AbjGVQn2 (ORCPT + 99 others); Sat, 22 Jul 2023 12:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjGVQn1 (ORCPT ); Sat, 22 Jul 2023 12:43:27 -0400 Received: from smtp.smtpout.orange.fr (smtp-16.smtpout.orange.fr [80.12.242.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FDC4E73 for ; Sat, 22 Jul 2023 09:43:26 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id NFhRqde8bqvVSNFhRqwXs7; Sat, 22 Jul 2023 18:43:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1690044204; bh=EvXOg9Wf3mDu5fhjycUMuKTbOj5nWm5mbNPIU3YSZCs=; h=From:To:Cc:Subject:Date; b=ly9sn9Y7k3+pn017fd72cAMjcY21k6cvEKg9DI1lB5dU3YAy1Q9aFNVMqbN8EjCie /oKCEBDvYSloKacW1ztKu0gPcslzvRmm7qWczny4s68Cx9z7Rxyn52ctyBXGlogx9C /ai579TbWtZ2FdzRISLFHVHrV3D1htFgVcURk7TCYTV/exdqq1+yUk3MF77d362vwh y6EGeiaaiaGKJc7ERrd0pMhcPIUW2LG7dSVRYmmGipGKxPzhpEgqpWJOJ+2Cx03dOh 6xT38O32RvD9yTkpTvuvtsNh9i2yvKfnJhDzo3Dd546nAtL7oMxkNLBsvzolxv8t20 FqCjXkSHQbVlQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 22 Jul 2023 18:43:24 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-rdma@vger.kernel.org Subject: [PATCH] IB/hfi1: Use struct_size() Date: Sat, 22 Jul 2023 18:43:18 +0200 Message-Id: <5631d2f1e20b48b27478275e8d3466e009ca1223.1690044181.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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772142503053079602 X-GMAIL-MSGID: 1772142989110220907 Use struct_size() instead of hand-writing it, when allocating a structure with a flex array. This is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET --- It will also be helpful if the __counted_by() annotation is added with a Coccinelle script such as: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=devel/counted_by&id=adc5b3cb48a049563dc673f348eab7b6beba8a9b --- drivers/infiniband/hw/hfi1/pio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c index 62e7dc9bea7b..5053d068399d 100644 --- a/drivers/infiniband/hw/hfi1/pio.c +++ b/drivers/infiniband/hw/hfi1/pio.c @@ -1893,9 +1893,7 @@ int pio_map_init(struct hfi1_devdata *dd, u8 port, u8 num_vls, u8 *vl_scontexts) vl_scontexts[i] = sc_per_vl + (extra > 0 ? 1 : 0); } /* build new map */ - newmap = kzalloc(sizeof(*newmap) + - roundup_pow_of_two(num_vls) * - sizeof(struct pio_map_elem *), + newmap = kzalloc(struct_size(newmap, map, roundup_pow_of_two(num_vls)), GFP_KERNEL); if (!newmap) goto bail;