Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dmaengine: edma: avoid uninitialized variable use

If edma_read_slot() gets an invalid argument, it does not set a result,
as found by "gcc -Wmaybe-uninitialized"

drivers/dma/edma.c: In function 'dma_ccerr_handler':
drivers/dma/edma.c:1499:21: error: 'p.a_b_cnt' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/dma/edma.c:1499:21: error: 'p.ccnt' may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (p.a_b_cnt == 0 && p.ccnt == 0) {

If we change the function to return an error in this case, we can handle
the failure more gracefully and treat this the same way as a null slot
that we already catch.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>

authored by

Arnd Bergmann and committed by
Vinod Koul
2cc40ee7 3a03ea76

+8 -4
+8 -4
drivers/dma/edma.c
··· 464 464 memcpy_toio(ecc->base + PARM_OFFSET(slot), param, PARM_SIZE); 465 465 } 466 466 467 - static void edma_read_slot(struct edma_cc *ecc, unsigned slot, 467 + static int edma_read_slot(struct edma_cc *ecc, unsigned slot, 468 468 struct edmacc_param *param) 469 469 { 470 470 slot = EDMA_CHAN_SLOT(slot); 471 471 if (slot >= ecc->num_slots) 472 - return; 472 + return -EINVAL; 473 473 memcpy_fromio(param, ecc->base + PARM_OFFSET(slot), PARM_SIZE); 474 + 475 + return 0; 474 476 } 475 477 476 478 /** ··· 1478 1476 struct edma_cc *ecc = echan->ecc; 1479 1477 struct device *dev = echan->vchan.chan.device->dev; 1480 1478 struct edmacc_param p; 1479 + int err; 1481 1480 1482 1481 if (!echan->edesc) 1483 1482 return; 1484 1483 1485 1484 spin_lock(&echan->vchan.lock); 1486 1485 1487 - edma_read_slot(ecc, echan->slot[0], &p); 1486 + err = edma_read_slot(ecc, echan->slot[0], &p); 1487 + 1488 1488 /* 1489 1489 * Issue later based on missed flag which will be sure 1490 1490 * to happen as: ··· 1499 1495 * lead to some nasty recursion when we are in a NULL 1500 1496 * slot. So we avoid doing so and set the missed flag. 1501 1497 */ 1502 - if (p.a_b_cnt == 0 && p.ccnt == 0) { 1498 + if (err || (p.a_b_cnt == 0 && p.ccnt == 0)) { 1503 1499 dev_dbg(dev, "Error on null slot, setting miss\n"); 1504 1500 echan->missed = 1; 1505 1501 } else {