Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1844929lqo; Sun, 19 May 2024 01:06:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXEYGlYzlClvLCMK2PL6YpBEyLrzu94hJw7rGCxlnVHWOoPfiTk+HA2gv5XMikzA5hWvwLlFO/v563D5D6DBFFVtQoZ+5wALebPm2OEdQ== X-Google-Smtp-Source: AGHT+IFw2b291yABebjDoOiiqL6wpRSJo6kn7tvi170CFosJmL1SnW6O5NguyDUi8IHboUVcIK3Q X-Received: by 2002:a50:c044:0:b0:572:7014:230a with SMTP id 4fb4d7f45d1cf-5752b4c8d66mr2823389a12.14.1716105984971; Sun, 19 May 2024 01:06:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716105984; cv=pass; d=google.com; s=arc-20160816; b=s/AV2PTOLDUruk+BGFJor9sooEvPFhJ3xuGpTUQERtHyS40xpgLz2+wl4XjSC/88hR dG9N7TkJX3PHFqy6TaDsT492MZlqlJPP2UzND1k4UTJ/tLi82svZt8ZBFDuBLbL2APG4 drFTPUtwnh9McjOHc5CRPyIJI7x+bwS6G/vDUr5meY3UlXmPlk3806DgSi5bYWagmev0 JmFAPRgYj8qDGB9Z7ghkehQuMWrIdXEr6yCRPVDxCnqWZLy8EZIZdcAbYd5zJmJtQy+L OzRE91e/Sz7HusNp0cnlyvHBflDPLqk6nJMTGTR+qviW5Gtq8l/fBg5YFIuFKDF1PVSJ Qlrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=17wjD51cm+BPeBrAvICXXERovsnzXo7hkI8s3mqy7uc=; fh=RMgoId0mRIe323kPcVjmKZWSxfYIzal4DdGv+LgbH4I=; b=ram80xSsk50B4RyQLBKcVE8skXNrbsAz7E/ilEjSm0w6iAoumn5rK+CvC2+M6PWhFi emZEd+z2d32N46UGFdH+Sixuu7CUgQcCWJmiT3gHUqK26F/We9lXOgVSs0DybgHcUk/9 76seCsiFUg+Am9Jf2lGA1VlxptIs9PHxRip74ltvFtPCc+hKMxBIPSf7MptKTgvB1cdy /SLZqiFZRf9r9CDdGPP5ukKXM9zLfXlntfiUW2A6FGlvK3yGRLGaFjlbCUbvJqNMWRvS lAQ/fJsVlUklA/uGftu4H4C8nqUeavk1QLRNNAPwvhO4wkUOdgfghoqi6TvcJzf9ZBqe 2izg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Q2JEOcG5; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-183050-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183050-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-574ec57e526si5936657a12.219.2024.05.19.01.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 01:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183050-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Q2JEOcG5; arc=pass (i=1 spf=pass spfdomain=wanadoo.fr dkim=pass dkdomain=wanadoo.fr dmarc=pass fromdomain=wanadoo.fr); spf=pass (google.com: domain of linux-kernel+bounces-183050-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183050-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AE86A1F2137F for ; Sun, 19 May 2024 08:06:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0994918E25; Sun, 19 May 2024 08:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="Q2JEOcG5" Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7896D4C8E; Sun, 19 May 2024 08:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716105971; cv=none; b=pqch8FohxpqOzv+erkG2wHCGUoj+MJfWq890EjhsIezfpXiT6RwEymL9Zc93R/UVlaKkBWBK8BbTpKTlkqfbVFUogpy7l7fqY0PzkXGwtT+YDh12rOw44kHauPO6DQ4eAunizxiu2jB5l94fwue3Sk1LtpoBTB6wqLhYM8FuEp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716105971; c=relaxed/simple; bh=PBVa6gwyfI7ikzqB0Jg4jElxnuzleVFC8ZWnH20UwdA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Jpc7EKiDkG/x4SoHbAzn99vNk18Cpf6m1l+Ld+fbne3fhdmH3wHmdeXUqcqdbFnGxkxWvV389Wt42XtcN/bVwv3I3WPVrVHd69DWnM2D6kZ72aoQgmN4ZLOJTINBE5+JfNhF/lilvy1gNAEFK2GPMArQUTH5igJjda1LbnUHROo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=Q2JEOcG5; arc=none smtp.client-ip=80.12.242.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Received: from localhost.localdomain ([86.243.17.157]) by smtp.orange.fr with ESMTPA id 8bYQsFlLZyBie8bYQsSbPx; Sun, 19 May 2024 10:06:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1716105964; bh=17wjD51cm+BPeBrAvICXXERovsnzXo7hkI8s3mqy7uc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Q2JEOcG5SYy7MaeNp+AoUSFfvDgpj6jv4aQ8JPEhtoD6Fqejjf/03tlor+Hs0Hgz+ ttC+w+LEBXXo6v8ClbDUKcx0mrG6tzsPHV/KBKbMpwOVZ0uth9bTs3JKAHgniSWyIR wnKILMeWfNEGiyTFyrJ9Mi5b3q4p1W8OzHmQ/XxFQP8FnXJdZDjqDxDccwgL+VbkJ/ yIStTF0YoHQAhoPyFF6sj6X/b9tuBi+Ht/4rIid9YBdj4s1QAtwho0+umhi21qjJKb zr63SHmRS8foi1/i7KD5CWmUpF+i5u249ytQjdTRsR1J5wnIpDK+bs1/ieaXgRH4EM 8Ogx66LxGWlgg== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 19 May 2024 10:06:04 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-scsi@vger.kernel.org Subject: [PATCH] scsi: bnx2fc: Use a flexible array at the end of struct bnx2fc_cmd_mgr Date: Sun, 19 May 2024 10:05:54 +0200 Message-ID: X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The 'cmds' field in "struct bnx2fc_cmd_mgr" can be turned into a flexible array. This: - makes the code more readable and safer because struct_size() can now be used - saves the size of a pointer when allocating struct bnx2fc_cmd_mgr in bnx2fc_cmd_mgr_alloc() - avoid some pointer arithmetic when computing "cmgr->cmds" - saves an indirection when using the 'cmds array Signed-off-by: Christophe JAILLET --- Compile tested only --- drivers/scsi/bnx2fc/bnx2fc.h | 2 +- drivers/scsi/bnx2fc/bnx2fc_io.c | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h index 7e74f77da14f..dfe7e0e8fdbd 100644 --- a/drivers/scsi/bnx2fc/bnx2fc.h +++ b/drivers/scsi/bnx2fc/bnx2fc.h @@ -281,7 +281,7 @@ struct bnx2fc_cmd_mgr { struct list_head *free_list; spinlock_t *free_list_lock; struct io_bdt **io_bdt_pool; - struct bnx2fc_cmd **cmds; + struct bnx2fc_cmd *cmds[]; }; struct bnx2fc_rport { diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c index 33057908f147..8e381081e487 100644 --- a/drivers/scsi/bnx2fc/bnx2fc_io.c +++ b/drivers/scsi/bnx2fc/bnx2fc_io.c @@ -213,7 +213,6 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba) struct bnx2fc_cmd_mgr *cmgr; struct io_bdt *bdt_info; struct bnx2fc_cmd *io_req; - size_t len; u32 mem_size; u16 xid; int i; @@ -231,10 +230,8 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba) BNX2FC_MISC_DBG("min xid 0x%x, max xid 0x%x\n", min_xid, max_xid); num_ios = max_xid - min_xid + 1; - len = (num_ios * (sizeof(struct bnx2fc_cmd *))); - len += sizeof(struct bnx2fc_cmd_mgr); - cmgr = kzalloc(len, GFP_KERNEL); + cmgr = kzalloc(struct_size(cmgr, cmds, num_ios), GFP_KERNEL); if (!cmgr) { printk(KERN_ERR PFX "failed to alloc cmgr\n"); return NULL; @@ -257,8 +254,6 @@ struct bnx2fc_cmd_mgr *bnx2fc_cmd_mgr_alloc(struct bnx2fc_hba *hba) goto mem_err; } - cmgr->cmds = (struct bnx2fc_cmd **)(cmgr + 1); - for (i = 0; i < arr_sz; i++) { INIT_LIST_HEAD(&cmgr->free_list[i]); spin_lock_init(&cmgr->free_list_lock[i]); -- 2.45.1