Skip to content

Commit 7edfe3d

Browse files
alanmikhak-at-sifivevinodkoul
authored andcommitted
dmaengine: dw-edma: Check MSI descriptor before copying
Modify dw_edma_irq_request() to check if a struct msi_desc entry exists before copying the contents of its struct msi_msg pointer. Without this sanity check, __get_cached_msi_msg() crashes when invoked by dw_edma_irq_request() running on a Linux-based PCIe endpoint device. MSI interrupt are not received by PCIe endpoint devices. If irq_get_msi_desc() returns null, then there is no cached struct msi_msg to be copied. Reported-by: kbuild test robot <[email protected]> Signed-off-by: Alan Mikhak <[email protected]> Acked-by: Gustavo Pimentel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent db47493 commit 7edfe3d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/dma/dw-edma/dw-edma-core.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/dmaengine.h>
1414
#include <linux/err.h>
1515
#include <linux/interrupt.h>
16+
#include <linux/irq.h>
1617
#include <linux/dma/edma.h>
1718
#include <linux/dma-mapping.h>
1819

@@ -773,6 +774,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip,
773774
u32 rd_mask = 1;
774775
int i, err = 0;
775776
u32 ch_cnt;
777+
int irq;
776778

777779
ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt;
778780

@@ -781,16 +783,16 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip,
781783

782784
if (dw->nr_irqs == 1) {
783785
/* Common IRQ shared among all channels */
784-
err = request_irq(dw->ops->irq_vector(dev, 0),
785-
dw_edma_interrupt_common,
786+
irq = dw->ops->irq_vector(dev, 0);
787+
err = request_irq(irq, dw_edma_interrupt_common,
786788
IRQF_SHARED, dw->name, &dw->irq[0]);
787789
if (err) {
788790
dw->nr_irqs = 0;
789791
return err;
790792
}
791793

792-
get_cached_msi_msg(dw->ops->irq_vector(dev, 0),
793-
&dw->irq[0].msi);
794+
if (irq_get_msi_desc(irq))
795+
get_cached_msi_msg(irq, &dw->irq[0].msi);
794796
} else {
795797
/* Distribute IRQs equally among all channels */
796798
int tmp = dw->nr_irqs;
@@ -804,7 +806,8 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip,
804806
dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt);
805807

806808
for (i = 0; i < (*wr_alloc + *rd_alloc); i++) {
807-
err = request_irq(dw->ops->irq_vector(dev, i),
809+
irq = dw->ops->irq_vector(dev, i);
810+
err = request_irq(irq,
808811
i < *wr_alloc ?
809812
dw_edma_interrupt_write :
810813
dw_edma_interrupt_read,
@@ -815,8 +818,8 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip,
815818
return err;
816819
}
817820

818-
get_cached_msi_msg(dw->ops->irq_vector(dev, i),
819-
&dw->irq[i].msi);
821+
if (irq_get_msi_desc(irq))
822+
get_cached_msi_msg(irq, &dw->irq[i].msi);
820823
}
821824

822825
dw->nr_irqs = i;

0 commit comments

Comments
 (0)