Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Peng Hao <flyingpenghao@gmail.com>
To: jinpu.wang@cloud.ionos.com, James.Bottomley@HansenPartnership.com
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH 2/4] scsi: pm8001: clean up resources on probe failure
Date: Fri, 11 Sep 2026 17:10:09 +0800	[thread overview]
Message-ID: <20260911091011.94676-3-flyingpeng@tencent.com> (raw)
In-Reply-To: <20260911091011.94676-1-flyingpeng@tencent.com>

When pm8001_init_ccb_tag() fails, pm8001_pci_probe() jumps directly to
the final return label. This bypasses teardown of the IRQs, tasklets,
HBA, SCSI host, SAS host data, PCI regions and PCI device.

Route the failure through the normal cleanup chain and reset the chip
before tearing down an initialized controller, including when
scsi_add_host() fails. Also release the separately allocated sas_phy and
sas_port arrays on failures after SAS host preparation.

Keep the earlier preparation-failure path separate because
pm8001_prep_sas_ha_init() already frees those arrays on failure.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 drivers/scsi/pm8001/pm8001_init.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index 8ede1f1da415..412079b5652c 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -1154,7 +1154,7 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
 	pm8001_ha = pm8001_pci_alloc(pdev, ent, shost);
 	if (!pm8001_ha) {
 		rc = -ENOMEM;
-		goto err_out_free;
+		goto err_out_free_sas_ha;
 	}
 
 	PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
@@ -1167,7 +1167,7 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
 
 	rc = pm8001_init_ccb_tag(pm8001_ha);
 	if (rc)
-		goto err_out_enable;
+		goto err_out_chip;
 
 
 	PM8001_CHIP_DISP->chip_post_init(pm8001_ha);
@@ -1184,7 +1184,7 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
 
 	rc = scsi_add_host(shost, &pdev->dev);
 	if (rc)
-		goto err_out_ha_free;
+		goto err_out_chip;
 
 	PM8001_CHIP_DISP->interrupt_enable(pm8001_ha, 0);
 	if (pm8001_ha->chip_id != chip_8001) {
@@ -1216,8 +1216,16 @@ static int pm8001_pci_probe(struct pci_dev *pdev,
 
 err_out_shost:
 	scsi_remove_host(pm8001_ha->shost);
+err_out_chip:
+	PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF);
+	PM8001_CHIP_DISP->chip_soft_rst(pm8001_ha);
 err_out_ha_free:
+	pm8001_free_irq(pm8001_ha);
+	pm8001_kill_tasklet(pm8001_ha);
 	pm8001_free(pm8001_ha);
+err_out_free_sas_ha:
+	kfree(sha->sas_phy);
+	kfree(sha->sas_port);
 err_out_free:
 	kfree(sha);
 err_out_free_host:
-- 
2.43.7


  parent reply	other threads:[~2026-09-11  9:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  9:10 [PATCH 0/4] scsi: pm8001: fix probe error-path resource leaks Peng Hao
2026-09-11  9:10 ` [PATCH 1/4] scsi: pm8001: free IRQs when HBA allocation fails Peng Hao
2026-09-11  9:26   ` sashiko-bot
2026-09-11  9:10 ` Peng Hao [this message]
2026-09-11  9:25   ` [PATCH 2/4] scsi: pm8001: clean up resources on probe failure sashiko-bot
2026-09-11  9:10 ` [PATCH 3/4] scsi: pm8001: free CCB resources on allocation failure Peng Hao
2026-09-11  9:26   ` sashiko-bot
2026-09-11  9:10 ` [PATCH 4/4] scsi: pm8001: free MSI-X vectors before INT-X fallback Peng Hao
2026-09-11  9:31   ` sashiko-bot

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=20260911091011.94676-3-flyingpeng@tencent.com \
    --to=flyingpenghao@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=linux-scsi@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox