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]
…
+++ 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/Docu...
Regards, Markus
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/Docu...
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
May curly brackets be omitted here? https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Docu...
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_ini...
Regards, Markus
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/Docu...
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_ini...
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
[ Sasha's backport helper bot ]
Hi,
✅ All tests passed successfully. No issues detected. No action required from the submitter.
The upstream commit SHA1 provided is correct: 51e6ed83bb4ade7c360551fa4ae55c4eacea354b
WARNING: Author mismatch between patch and upstream commit: Backport author: Shivani Agarwal shivani.agarwal@broadcom.com Commit author: Ajish Koshy Ajish.Koshy@microchip.com
Status in newer kernel trees: 6.15.y | Present (exact SHA1) 6.12.y | Present (exact SHA1) 6.6.y | Present (exact SHA1) 6.1.y | Present (exact SHA1) 5.15.y | Present (different SHA1: 269a4311b15f)
Note: The patch differs from the upstream commit: --- 1: 51e6ed83bb4a ! 1: 1652f92390bb scsi: pm80xx: Fix memory leak during rmmod @@ Metadata ## Commit message ## scsi: pm80xx: Fix memory leak during rmmod
+ [ Upstream commit 51e6ed83bb4ade7c360551fa4ae55c4eacea354b ] + Driver failed to release all memory allocated. This would lead to memory leak during driver removal.
@@ Commit message 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 ## @@ drivers/scsi/pm8001/pm8001_init.c: pm8001_init_ccb_tag(struct pm8001_hba_info *pm8001_ha, struct Scsi_Host *shost, @@ drivers/scsi/pm8001/pm8001_init.c: pm8001_init_ccb_tag(struct pm8001_hba_info *p
/* Memory region for ccb_info*/ + pm8001_ha->ccb_count = ccb_count; - pm8001_ha->ccb_info = + pm8001_ha->ccb_info = (struct pm8001_ccb_info *) kcalloc(ccb_count, sizeof(struct pm8001_ccb_info), GFP_KERNEL); if (!pm8001_ha->ccb_info) { @@ drivers/scsi/pm8001/pm8001_init.c: static void pm8001_pci_remove(struct pci_dev *pdev)
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | origin/linux-5.10.y | Success | Success |
linux-stable-mirror@lists.linaro.org