Re: [PATCH] PCI: dwc: Reject a negative nr_irqs value in dw_pcie_edma_irq_verify()

Niklas Cassel
2024-12-31T18:13:37Z

On Tue, Dec 31, 2024 at 09:21:58PM +0530, Manivannan Sadhasivam wrote:
> On Fri, Dec 20, 2024 at 08:23:29AM +0100, Niklas Cassel wrote:
> > Platforms that do not have (one or more) dedicated IRQs for the eDMA
> > need to set nr_irqs to a non-zero value in their DWC glue driver.
> >
> > Platforms that do have (one or more) dedicated IRQs do not need to
> > initialize nr_irqs. DWC common code will automatically set nr_irqs.
> >
> > Since a glue driver can initialize nr_irqs, dw_pcie_edma_irq_verify()
> > should verify that nr_irqs, if non-zero, is a valid value. Thus, add a
> > check in dw_pcie_edma_irq_verify() to reject a negative nr_irqs value.
> >
>
> Why can't we make dw_edma_chip::nr_irqs unsigned?

dw_edma is defined in drivers/dma/dw-edma/dw-edma-core.h
in struct dw_edma.

struct dw_pcie (defined in drivers/pci/controller/dwc/pcie-designware.h)
simply has a struct dw_edma as a struct member.

If you bounce on nr_irqs in:
drivers/dma/dw-edma/dw-edma-core.c
and in
drivers/dma/dw-edma/dw-edma-pcie.c
you can see that this driver uses signed int for this everywhere.

I didn't feel like refactoring a whole DMA driver.

dw_pcie_edma_irq_verify() is supposed to verify that nr_irqs is either
initialized to a valid value by a DWC PCIe glue driver, or that common
code initializes it.

If nr_irqs is initialized by a glue driver && "pci->edma.nr_irqs != ch_cnt",
dw_pcie_edma_irq_verify() returns error and avoids calling dw_edma_probe(),
thus it made sense for dw_pcie_edma_irq_verify() to also return error on
negative nr_irqs.

Kind regards,
Niklas