diff mbox series

scsi: fnic: Test for memory allocation failure and return error code

Message ID 20250110091924.17729-1-kartilak@cisco.com
State New
Headers show
Series scsi: fnic: Test for memory allocation failure and return error code | expand

Commit Message

Karan Tilak Kumar (kartilak) Jan. 10, 2025, 9:19 a.m. UTC
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@intel.com>
Closes: https://lore.kernel.org/r/202412312347.FE4ZgEoM-lkp@intel.com/
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202412312347.FE4ZgEoM-lkp@intel.com/
Reviewed-by: Sesidhar Baddela <sebaddel@cisco.com>
Reviewed-by: Arulprabhu Ponnusamy <arulponn@cisco.com>
Reviewed-by: Gian Carlo Boffa <gcboffa@cisco.com>
Reviewed-by: Arun Easi <aeasi@cisco.com>
Signed-off-by: Karan Tilak Kumar <kartilak@cisco.com>
---
 drivers/scsi/fnic/fnic_main.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

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);