public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod
@ 2025-08-11  5:20 Shivani Agarwal
  2025-08-11  8:00 ` Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Shivani Agarwal @ 2025-08-11  5:20 UTC (permalink / raw)
  To: stable, gregkh
  Cc: bcm-kernel-feedback-list, linux-kernel, ajay.kaher,
	alexey.makhalov, tapas.kundu, James.Bottomley, jinpu.wang,
	martin.petersen, linux-scsi, Ajish Koshy, Jack Wang, Viswas G,
	Sasha Levin, Shivani Agarwal

From: Ajish Koshy <Ajish.Koshy@microchip.com>

[ Upstream commit 51e6ed83bb4ade7c360551fa4ae55c4eacea354b ]

Driver failed to release all memory allocated. This would lead to memory
leak during driver removal.

Properly free memory when the module is removed.

Link: https://lore.kernel.org/r/20210906170404.5682-5-Ajish.Koshy@microchip.com
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Ajish Koshy <Ajish.Koshy@microchip.com>
Signed-off-by: Viswas G <Viswas.G@microchip.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
[Shivani: Modified to apply on 5.10.y]
Signed-off-by: Shivani Agarwal <shivani.agarwal@broadcom.com>
---
 drivers/scsi/pm8001/pm8001_init.c | 11 +++++++++++
 drivers/scsi/pm8001/pm8001_sas.h  |  1 +
 2 files changed, 12 insertions(+)

diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index f40db6f40b1d..45bffa49f876 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1166,6 +1166,7 @@ pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost,
 		goto err_out;
 
 	/* Memory region for ccb_info*/
+	pm8001_ha->ccb_count = ccb_count;
 	pm8001_ha->ccb_info = (struct pm8001_ccb_info *)
 		kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL);
 	if (!pm8001_ha->ccb_info) {
@@ -1226,6 +1227,16 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
 			tasklet_kill(&pm8001_ha->tasklet[j]);
 #endif
 	scsi_host_put(pm8001_ha->shost);
+
+	for (i = 0; i < pm8001_ha->ccb_count; i++) {
+		dma_free_coherent(&pm8001_ha->pdev->dev,
+			sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
+			pm8001_ha->ccb_info[i].buf_prd,
+			pm8001_ha->ccb_info[i].ccb_dma_handle);
+	}
+	kfree(pm8001_ha->ccb_info);
+	kfree(pm8001_ha->devices);
+
 	pm8001_free(pm8001_ha);
 	kfree(sha->sas_phy);
 	kfree(sha->sas_port);
diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
index 5cd6fe6a7d2d..74099d82e436 100644
--- a/drivers/scsi/pm8001/pm8001_sas.h
+++ b/drivers/scsi/pm8001/pm8001_sas.h
@@ -515,6 +515,7 @@ struct pm8001_hba_info {
 	u32			iomb_size; /* SPC and SPCV IOMB size */
 	struct pm8001_device	*devices;
 	struct pm8001_ccb_info	*ccb_info;
+	u32			ccb_count;
 #ifdef PM8001_USE_MSIX
 	int			number_of_intr;/*will be used in remove()*/
 	char			intr_drvname[PM8001_MAX_MSIX_VEC]
-- 
2.40.4

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

* Re: [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod
  2025-08-11  5:20 [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod Shivani Agarwal
@ 2025-08-11  8:00 ` Markus Elfring
  2025-08-11 10:36   ` Shivani Agarwal
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-08-11  8:00 UTC (permalink / raw)
  To: Shivani Agarwal, Sasha Levin, Viswas G, Martin K. Petersen,
	Ajish Koshy, Jack Wang, Greg Kroah-Hartman, linux-scsi
  Cc: bcm-kernel-feedback-list, stable, LKML, Ajay Kaher,
	Alexey Makhalov, Jack Wang, James Bottomley, Tapas Kundu

…
> +++ b/drivers/scsi/pm8001/pm8001_init.c
> @@ -1226,6 +1227,16 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
>  			tasklet_kill(&pm8001_ha->tasklet[j]);
>  #endif
>  	scsi_host_put(pm8001_ha->shost);
> +
> +	for (i = 0; i < pm8001_ha->ccb_count; i++) {
> +		dma_free_coherent(&pm8001_ha->pdev->dev,
> +			sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
> +			pm8001_ha->ccb_info[i].buf_prd,
> +			pm8001_ha->ccb_info[i].ccb_dma_handle);
> +	}

May curly brackets be omitted here?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.16#n197

Regards,
Markus

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

* Re: [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod
  2025-08-11  8:00 ` Markus Elfring
@ 2025-08-11 10:36   ` Shivani Agarwal
  2025-08-11 10:50     ` Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Shivani Agarwal @ 2025-08-11 10:36 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Sasha Levin, Viswas G, Martin K. Petersen, Ajish Koshy, Jack Wang,
	Greg Kroah-Hartman, linux-scsi, bcm-kernel-feedback-list, stable,
	LKML, Ajay Kaher, Alexey Makhalov, Jack Wang, James Bottomley,
	Tapas Kundu

[-- Attachment #1: Type: text/plain, Size: 1161 bytes --]

On Mon, Aug 11, 2025 at 1:30 PM Markus Elfring <Markus.Elfring@web.de> wrote:
>
> …
> > +++ b/drivers/scsi/pm8001/pm8001_init.c
> …
> > @@ -1226,6 +1227,16 @@ static void pm8001_pci_remove(struct pci_dev *pdev)
> >                       tasklet_kill(&pm8001_ha->tasklet[j]);
> >  #endif
> >       scsi_host_put(pm8001_ha->shost);
> > +
> > +     for (i = 0; i < pm8001_ha->ccb_count; i++) {
> > +             dma_free_coherent(&pm8001_ha->pdev->dev,
> > +                     sizeof(struct pm8001_prd) * PM8001_MAX_DMA_SG,
> > +                     pm8001_ha->ccb_info[i].buf_prd,
> > +                     pm8001_ha->ccb_info[i].ccb_dma_handle);
> > +     }
>
> May curly brackets be omitted here?
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.16#n197

Thanks, Markus. I agree with you and have no objection. However, for
the stable branches, we usually keep the patches unchanged.
I think it would be good to remove these curly braces in the Linux
master branch as well. Should I go ahead and submit a patch for the
master branch too?

Regards,
Shivani

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5429 bytes --]

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

* Re: [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod
  2025-08-11 10:36   ` Shivani Agarwal
@ 2025-08-11 10:50     ` Markus Elfring
  2025-08-11 11:20       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-08-11 10:50 UTC (permalink / raw)
  To: Shivani Agarwal, bcm-kernel-feedback-list, linux-scsi
  Cc: Sasha Levin, Viswas G, Martin K. Petersen, Ajish Koshy, Jack Wang,
	Greg Kroah-Hartman, stable, LKML, Ajay Kaher, Alexey Makhalov,
	Jack Wang, James Bottomley, Tapas Kundu

>> May curly brackets be omitted here?
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.16#n197
> 
> Thanks, Markus. I agree with you and have no objection. However, for
> the stable branches, we usually keep the patches unchanged.

I am unsure how many source code adjustments would be supported
also according to coding style concerns.


> I think it would be good to remove these curly braces in the Linux
> master branch as well. Should I go ahead and submit a patch for the
> master branch too?

Corresponding refinements would be nice.
https://elixir.bootlin.com/linux/v6.16/source/drivers/scsi/pm8001/pm8001_init.c#L1311-L1316

Regards,
Markus

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

* Re: [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod
  2025-08-11 10:50     ` Markus Elfring
@ 2025-08-11 11:20       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2025-08-11 11:20 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Shivani Agarwal, bcm-kernel-feedback-list, linux-scsi,
	Sasha Levin, Viswas G, Martin K. Petersen, Ajish Koshy, Jack Wang,
	stable, LKML, Ajay Kaher, Alexey Makhalov, Jack Wang,
	James Bottomley, Tapas Kundu

On Mon, Aug 11, 2025 at 12:50:24PM +0200, Markus Elfring wrote:
> >> May curly brackets be omitted here?
> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.16#n197
> > 
> > Thanks, Markus. I agree with you and have no objection. However, for
> > the stable branches, we usually keep the patches unchanged.
> 
> I am unsure how many source code adjustments would be supported
> also according to coding style concerns.
> 
> 
> > I think it would be good to remove these curly braces in the Linux
> > master branch as well. Should I go ahead and submit a patch for the
> > master branch too?
> 
> Corresponding refinements would be nice.
> https://elixir.bootlin.com/linux/v6.16/source/drivers/scsi/pm8001/pm8001_init.c#L1311-L1316


Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list.  I strongly suggest that you not do this anymore.  Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all.  The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback.  Please feel free to also ignore emails
from them.

thanks,

greg k-h's patch email bot

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

end of thread, other threads:[~2025-08-11 11:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  5:20 [PATCH v5.10] scsi: pm80xx: Fix memory leak during rmmod Shivani Agarwal
2025-08-11  8:00 ` Markus Elfring
2025-08-11 10:36   ` Shivani Agarwal
2025-08-11 10:50     ` Markus Elfring
2025-08-11 11:20       ` Greg Kroah-Hartman

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