All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhipeng Lu <alexious@zju.edu.cn>
To: alexious@zju.edu.cn
Cc: Kashyap Desai <kashyap.desai@broadcom.com>,
	Sumit Saxena <sumit.saxena@broadcom.com>,
	Shivasharan S <shivasharan.srikanteshwara@broadcom.com>,
	Chandrakanth patil <chandrakanth.patil@broadcom.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: megaraid_sas: Fix a memleak in megasas_init_fw
Date: Wed, 17 Jan 2024 16:13:13 +0800	[thread overview]
Message-ID: <20240117081314.3818871-1-alexious@zju.edu.cn> (raw)

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


             reply	other threads:[~2024-01-17  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-17  8:13 Zhipeng Lu [this message]
2024-01-18  1:25 ` [PATCH] scsi: megaraid_sas: Fix a memleak in megasas_init_fw kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240117081314.3818871-1-alexious@zju.edu.cn \
    --to=alexious@zju.edu.cn \
    --cc=chandrakanth.patil@broadcom.com \
    --cc=jejb@linux.ibm.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=megaraidlinux.pdl@broadcom.com \
    --cc=shivasharan.srikanteshwara@broadcom.com \
    --cc=sumit.saxena@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.