[PATCH] scsi: fnic: Test for memory allocation failure and return error code
From: Karan Tilak Kumar
Date: Fri Jan 10 2025 - 04:24:36 EST
Fix kernel test robot warning.
Test for memory allocation failure, and free memory for
queues allocated in a multiqueue and non-multiqueue scenario.
Return appropriate error code.
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/r/202412312347.FE4ZgEoM-lkp@xxxxxxxxx/
Reported-by: Julia Lawall <julia.lawall@xxxxxxxx>
Closes: https://lore.kernel.org/r/202412312347.FE4ZgEoM-lkp@xxxxxxxxx/
Reviewed-by: Sesidhar Baddela <sebaddel@xxxxxxxxx>
Reviewed-by: Arulprabhu Ponnusamy <arulponn@xxxxxxxxx>
Reviewed-by: Gian Carlo Boffa <gcboffa@xxxxxxxxx>
Reviewed-by: Arun Easi <aeasi@xxxxxxxxx>
Signed-off-by: Karan Tilak Kumar <kartilak@xxxxxxxxx>
---
drivers/scsi/fnic/fnic_main.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
index 6eb551112170..6880b40507aa 100644
--- a/drivers/scsi/fnic/fnic_main.c
+++ b/drivers/scsi/fnic/fnic_main.c
@@ -582,6 +582,14 @@ static void fnic_scsi_init(struct fnic *fnic)
host->transportt = fnic_fc_transport;
}
+static void fnic_free_ioreq_tables_mq(struct fnic *fnic)
+{
+ int hwq;
+
+ for (hwq = 0; hwq < fnic->wq_copy_count; hwq++)
+ kfree(fnic->sw_copy_wq[hwq].io_req_table);
+}
+
static int fnic_scsi_drv_init(struct fnic *fnic)
{
struct Scsi_Host *host = fnic->host;
@@ -614,6 +622,11 @@ static int fnic_scsi_drv_init(struct fnic *fnic)
fnic->sw_copy_wq[hwq].io_req_table =
kzalloc((fnic->sw_copy_wq[hwq].ioreq_table_size + 1) *
sizeof(struct fnic_io_req *), GFP_KERNEL);
+
+ if (!fnic->sw_copy_wq[hwq].io_req_table) {
+ fnic_free_ioreq_tables_mq(fnic);
+ return -ENOMEM;
+ }
}
dev_info(&fnic->pdev->dev, "fnic copy wqs: %d, Q0 ioreq table size: %d\n",
@@ -1060,6 +1073,7 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
err_out_free_stats_debugfs:
fnic_stats_debugfs_remove(fnic);
+ fnic_free_ioreq_tables_mq(fnic);
scsi_remove_host(fnic->host);
err_out_scsi_drv_init:
fnic_free_intr(fnic);
--
2.47.1