* [PATCH] edma: avoid uninitialized variable use
@ 2016-09-30 16:19 Arnd Bergmann
2016-09-30 17:47 ` Vinod Koul
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-09-30 16:19 UTC (permalink / raw)
To: Vinod Koul
Cc: Arnd Bergmann, Dan Williams, Peter Ujfalusi, Tony Lindgren,
dmaengine, linux-kernel
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>
---
drivers/dma/edma.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index 844e87b3bffc..e18a58068bca 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -465,13 +465,15 @@ static void edma_write_slot(struct edma_cc *ecc, unsigned slot,
memcpy_toio(ecc->base + PARM_OFFSET(slot), param, PARM_SIZE);
}
-static void edma_read_slot(struct edma_cc *ecc, unsigned slot,
+static int edma_read_slot(struct edma_cc *ecc, unsigned slot,
struct edmacc_param *param)
{
slot = EDMA_CHAN_SLOT(slot);
if (slot >= ecc->num_slots)
- return;
+ return -EINVAL;
memcpy_fromio(param, ecc->base + PARM_OFFSET(slot), PARM_SIZE);
+
+ return 0;
}
/**
@@ -1477,13 +1479,15 @@ static void edma_error_handler(struct edma_chan *echan)
struct edma_cc *ecc = echan->ecc;
struct device *dev = echan->vchan.chan.device->dev;
struct edmacc_param p;
+ int err;
if (!echan->edesc)
return;
spin_lock(&echan->vchan.lock);
- edma_read_slot(ecc, echan->slot[0], &p);
+ err = edma_read_slot(ecc, echan->slot[0], &p);
+
/*
* Issue later based on missed flag which will be sure
* to happen as:
@@ -1496,7 +1500,7 @@ static void edma_error_handler(struct edma_chan *echan)
* lead to some nasty recursion when we are in a NULL
* slot. So we avoid doing so and set the missed flag.
*/
- if (p.a_b_cnt == 0 && p.ccnt == 0) {
+ if (err || (p.a_b_cnt == 0 && p.ccnt == 0)) {
dev_dbg(dev, "Error on null slot, setting miss\n");
echan->missed = 1;
} else {
--
2.9.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] edma: avoid uninitialized variable use
2016-09-30 16:19 [PATCH] edma: avoid uninitialized variable use Arnd Bergmann
@ 2016-09-30 17:47 ` Vinod Koul
0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2016-09-30 17:47 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Dan Williams, Peter Ujfalusi, Tony Lindgren, dmaengine,
linux-kernel
On Fri, Sep 30, 2016 at 06:19:01PM +0200, Arnd Bergmann wrote:
> 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.
Applied. Fixes subsystem tag
Thanks
--
~Vinod
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-30 17:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-30 16:19 [PATCH] edma: avoid uninitialized variable use Arnd Bergmann
2016-09-30 17:47 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox