Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Hao" <flyingpenghao@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH 4/4] scsi: pm8001: free MSI-X vectors before INT-X fallback
Date: Fri, 11 Sep 2026 09:31:32 +0000	[thread overview]
Message-ID: <20260911093133.25DC51F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911091011.94676-5-flyingpeng@tencent.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Early registration of interrupt handler causes a race condition leading to a NULL pointer dereference.
- [High] The INT-X fallback path is unreachable dead code, and the driver fails to initialize if MSI-X allocation fails.
--

commit 41233b053e82eb6b313eebe72e0ecc8e816d565f
Author: Peng Hao <flyingpenghao@gmail.com>

scsi: pm8001: free MSI-X vectors before INT-X fallback

pm8001_setup_msix() may allocate MSI-X vectors before
pm8001_request_irq() decides to use INT-X. The fallback currently leaves
those vectors allocated. It also leaves max_q_num set to the MSI-X
vector count even though only one legacy interrupt is used.

Free allocated vectors before requesting INT-X, clear number_of_intr and
restore the single-queue configuration. Clear number_of_intr as well
when MSI-X IRQ registration fails after the vectors have been freed.

> diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
> index a747de9a3ca0a..4bf6c747be8b8 100644
> --- a/drivers/scsi/pm8001/pm8001_init.c
> +++ b/drivers/scsi/pm8001/pm8001_init.c

[ ... ]

> @@ -1087,6 +1088,12 @@ static u32 pm8001_request_irq(struct pm8001_hba_info *pm8001_ha)
>  	}
>  
>  use_intx:

[Severity: High]
This is a pre-existing issue, but is this INT-X fallback path actually
reachable?

Looking at pm8001_request_irq(), if pm8001_setup_msix() fails it immediately
returns the error rather than falling back to use_intx:

    rc = pm8001_setup_msix(pm8001_ha);
    if (rc) {
        ...
        return rc;
    }

    if (!pdev->msix_cap || !pci_msi_enabled())
        goto use_intx;

Since pm8001_setup_msix() only succeeds if MSI-X is supported and enabled,
the subsequent checks for !pdev->msix_cap and !pci_msi_enabled() will never
be true.

Does this leave the fallback as dead code, causing driver initialization to
fail completely instead of using legacy interrupts when MSI-X fails?

[Severity: Critical]
This is a pre-existing issue, but does setting up the INT-X interrupt here
introduce a race condition?

The interrupt handler is registered here during pm8001_alloc() via
pm8001_request_irq(), but hardware queues and pointers are not initialized
until later in pm8001_pci_probe() when calling chip_init().

If a shared INT-X line or pending hardware state causes an interrupt to fire
immediately, the handler will schedule a tasklet executing process_oq().
This function reads from the uninitialized queue pointers:

process_oq()
    circularQ->producer_index = cpu_to_le32(pm8001_read_32(circularQ->pi_virt));

Since pi_virt is still NULL before chip_init() is called, could this result
in a NULL pointer dereference?

> +	if (pm8001_ha->number_of_intr) {
> +		pci_free_irq_vectors(pdev);
> +		pm8001_ha->number_of_intr = 0;
> +	}
> +	pm8001_ha->max_q_num = 1;
> +
>  	/* Initialize the INT-X interrupt */
>  	pm8001_dbg(pm8001_ha, INIT, "MSIX not supported!!!\n");
>  	pm8001_ha->use_msix = false;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911091011.94676-1-flyingpeng@tencent.com?part=4

      reply	other threads:[~2026-09-11  9:31 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 ` [PATCH 2/4] scsi: pm8001: clean up resources on probe failure Peng Hao
2026-09-11  9:25   ` 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 [this message]

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=20260911093133.25DC51F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=flyingpenghao@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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