[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20240122171610.3840351-1-alexious@zju.edu.cn>
Date: Tue, 23 Jan 2024 01:16:10 +0800
From: Zhipeng Lu <alexious@....edu.cn>
To: alexious@....edu.cn
Cc: Kashyap Desai <kashyap.desai@...adcom.com>,
Sumit Saxena <sumit.saxena@...adcom.com>,
Shivasharan S <shivasharan.srikanteshwara@...adcom.com>,
Chandrakanth patil <chandrakanth.patil@...adcom.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
megaraidlinux.pdl@...adcom.com,
linux-scsi@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] [v2] scsi: megaraid_sas: Fix a memleak in megasas_init_fw
In the error-handling paths after allocation of
fusion->stream_detect_by_ld and fusion->stream_detect_by_ld[i],
megasas_init_fw should free them or there would be memleaks.
Fixes: 2e47e4e62e40 ("scsi: megaraid_sas: Fail init if heartbeat timer fails")
Signed-off-by: Zhipeng Lu <alexious@....edu.cn>
---
Changelog:
v2: remove the unused variable j.
---
drivers/scsi/megaraid/megaraid_sas_base.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 3d4f13da1ae8..a7d3c51fc17b 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -6016,7 +6016,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
void *base_addr_phys;
struct megasas_ctrl_info *ctrl_info = NULL;
unsigned long bar_list;
- int i, j, loop;
+ int i, loop;
struct IOV_111 *iovPtr;
struct fusion_context *fusion;
bool intr_coalescing;
@@ -6378,11 +6378,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
if (!fusion->stream_detect_by_ld[i]) {
dev_err(&instance->pdev->dev,
"unable to allocate stream detect by LD\n ");
- for (j = 0; j < i; ++j)
- kfree(fusion->stream_detect_by_ld[j]);
- kfree(fusion->stream_detect_by_ld);
- fusion->stream_detect_by_ld = NULL;
- goto fail_get_ld_pd_list;
+ goto fail_alloc_stream_detect;
}
fusion->stream_detect_by_ld[i]->mru_bit_map
= MR_STREAM_BITMAP;
@@ -6502,7 +6498,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
megasas_start_timer(instance);
} else {
instance->skip_heartbeat_timer_del = 1;
- goto fail_get_ld_pd_list;
+ goto fail_alloc_stream_detect;
}
}
@@ -6520,6 +6516,13 @@ static int megasas_init_fw(struct megasas_instance *instance)
fail_start_watchdog:
if (instance->requestorId && !instance->skip_heartbeat_timer_del)
del_timer_sync(&instance->sriov_heartbeat_timer);
+fail_alloc_stream_detect:
+ if (instance->adapter_type >= VENTURA_SERIES) {
+ for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i)
+ kfree(fusion->stream_detect_by_ld[i]);
+ kfree(fusion->stream_detect_by_ld);
+ fusion->stream_detect_by_ld = NULL;
+ }
fail_get_ld_pd_list:
instance->instancet->disable_intr(instance);
megasas_destroy_irqs(instance);
--
2.34.1
Powered by blists - more mailing lists