public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: qedf: Use kzalloc() and add check for bdt_info
@ 2025-01-31 19:54 Jiasheng Jiang
  2025-01-31 20:32 ` Bart Van Assche
  0 siblings, 1 reply; 33+ messages in thread
From: Jiasheng Jiang @ 2025-01-31 19:54 UTC (permalink / raw)
  To: skashyap, jhasan, GR-QLogic-Storage-Upstream, James.Bottomley,
	martin.petersen, manish.rangankar, nilesh.javali, arun.easi
  Cc: linux-scsi, linux-kernel, Jiasheng Jiang

Replace kmalloc_array() with kzalloc() to avoid old (dirty) data being
used/freed.
Moreover, add a check for "bdt_info". Otherwise, if one of the allocations
for cmgr->io_bdt_pool[i] fails, "bdt_info->bd_tbl" will cause a NULL
pointer dereference.

Fixes: 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/scsi/qedf/qedf_io.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index fcfc3bed02c6..a5970fee6851 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -125,7 +125,7 @@ void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr)
 	bd_tbl_sz = QEDF_MAX_BDS_PER_CMD * sizeof(struct scsi_sge);
 	for (i = 0; i < num_ios; i++) {
 		bdt_info = cmgr->io_bdt_pool[i];
-		if (bdt_info->bd_tbl) {
+		if (bdt_info && bdt_info->bd_tbl) {
 			dma_free_coherent(&qedf->pdev->dev, bd_tbl_sz,
 			    bdt_info->bd_tbl, bdt_info->bd_tbl_dma);
 			bdt_info->bd_tbl = NULL;
@@ -254,8 +254,7 @@ struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf)
 	}
 
 	/* Allocate pool of io_bdts - one for each qedf_ioreq */
-	cmgr->io_bdt_pool = kmalloc_array(num_ios, sizeof(struct io_bdt *),
-	    GFP_KERNEL);
+	cmgr->io_bdt_pool = kzalloc(num_ios * sizeof(struct io_bdt *), GFP_KERNEL);
 
 	if (!cmgr->io_bdt_pool) {
 		QEDF_WARN(&(qedf->dbg_ctx), "Failed to alloc io_bdt_pool.\n");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2025-02-07 15:46 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-31 19:54 [PATCH] scsi: qedf: Use kzalloc() and add check for bdt_info Jiasheng Jiang
2025-01-31 20:32 ` Bart Van Assche
2025-01-31 21:35   ` [PATCH v2] scsi: qedf: Use kcalloc() " Jiasheng Jiang
2025-02-02 15:22     ` Markus Elfring
2025-02-02 16:54     ` Markus Elfring
2025-02-02 21:21       ` [PATCH] Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-02 21:29       ` [PATCH] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-02 21:32       ` [PATCH] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-03  7:20         ` [PATCH v3?] " Markus Elfring
2025-02-04  2:51           ` [PATCH v3] " Jiasheng Jiang
2025-02-04  2:52           ` [PATCH v3?] " Jiasheng Jiang
2025-02-04  8:05             ` [v3?] " Markus Elfring
2025-02-05  1:07               ` [PATCH v3 1/2] " Jiasheng Jiang
2025-02-05  1:07                 ` [PATCH v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-05  1:08               ` [v3?] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-05  8:11                 ` Markus Elfring
2025-02-06  5:12                   ` Jiasheng Jiang
2025-02-06 12:16                     ` Markus Elfring
2025-02-06  5:25                   ` [PATCH 0/2] scsi: qedf: Replace alloction API and add null check Jiasheng Jiang
2025-02-06  5:25                     ` [PATCH 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-06  5:36                       ` Greg KH
2025-02-06  5:38                         ` Greg KH
2025-02-06 19:19                           ` [PATCH v2 " Jiasheng Jiang
2025-02-06 19:20                             ` [PATCH v2 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-07 15:09                             ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Greg KH
2025-02-07 15:45                               ` [PATCH v3 " Jiasheng Jiang
2025-02-07 15:45                                 ` [PATCH v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-07 15:46                               ` [PATCH v2 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-06  5:25                     ` [PATCH 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-06 11:56                     ` [PATCH v5? 0/2] scsi: qedf: Replace alloction API and add null check Markus Elfring
2025-02-05  2:01               ` [PATCH RESEND v3 1/2] scsi: qedf: Replace kmalloc_array() with kcalloc() Jiasheng Jiang
2025-02-05  2:01                 ` [PATCH RESEND v3 2/2] scsi: qedf: Add check for bdt_info Jiasheng Jiang
2025-02-02 21:33       ` [PATCH v2] scsi: qedf: Use kcalloc() and add " Jiasheng Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox