Skip to contentSkip to conversation

dmaengine: loongson: Fix signedness bug

PATCH New Ethan Tidmore 1 participant 1 message Mar 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: loongson: Fix signedness bug

The function platform_get_irq() returns negative error codes and lchan->irq is an unsigned integer, so the check (lchan->irq < 0) is always impossible.

Make the return value of platform_get_irq() be assigned to ret, check for error, and then assign lchan->irq to ret.

Detected by Smatch:
drivers/dma/loongson/loongson2-apb-cmc-dma.c:677 loongson2_cmc_dma_probe() warn:
unsigned 'lchan->irq' is never less than zero.

Fixes 1c0028e725f15 ("dmaengine: loongson: New driver for the Loongson Multi-Channel DMA controller")
---
 drivers/dma/loongson/loongson2-apb-cmc-dma.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma/loongson/loongson2-apb-cmc-dma.c +5 -3
index 1c9a542edc85..2a702de8063c 100644
@@ -673,9 +673,11 @@ static int loongson2_cmc_dma_probe(struct platform_device *pdev)
 	for (i = 0; i < nr_chans; i++) {
 		lchan = &lddev->chan[i];
 
-		lchan->irq = platform_get_irq(pdev, i);
-		if (lchan->irq < 0)
-			return lchan->irq;
+		ret = platform_get_irq(pdev, i);
+		if (ret < 0)
+			return ret;
+
+		lchan->irq = ret;
 
 		ret = devm_request_irq(dev, lchan->irq, loongson2_cmc_dma_chan_irq, IRQF_SHARED,
 				       dev_name(chan2dev(lchan)), lchan);
Signature · 1 line
2.53.0