mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: megaraid_sas: Fix a memleak in megasas_init_fw
@ 2024-01-17  8:13 Zhipeng Lu
  2024-01-18  1:25 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Zhipeng Lu @ 2024-01-17  8:13 UTC (permalink / raw)
  To: alexious
  Cc: Kashyap Desai, Sumit Saxena, Shivasharan S, Chandrakanth patil,
	James E.J. Bottomley, Martin K. Petersen, megaraidlinux.pdl,
	linux-scsi, linux-kernel

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@zju.edu.cn>
---
 drivers/scsi/megaraid/megaraid_sas_base.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 3d4f13da1ae8..046d7c880be6 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -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


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

end of thread, other threads:[~2024-01-18  1:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17  8:13 [PATCH] scsi: megaraid_sas: Fix a memleak in megasas_init_fw Zhipeng Lu
2024-01-18  1:25 ` kernel test robot

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

all inboxes | Powered by JetHome®