Skip to content

Commit 85b6ff0

Browse files
dbalutakartben
authored andcommitted
drivers: dma: sdma: Make access to DMA channel stats atomic
DMA channel stats like pending_length or free is not protected and can be modified in parallel by a consumer and a producer. This can result in non-atomic updates which in turn will result in using stale data. Fix this by making regions of code accessing dma stats atomic. Fixes: e94c86f ("drivers: dma: Add initial support for NXP SDMA") Signed-off-by: Daniel Baluta <[email protected]>
1 parent 312ff1c commit 85b6ff0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/dma/dma_nxp_sdma.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,14 @@ static int dma_nxp_sdma_get_status(const struct device *dev, uint32_t channel,
376376
{
377377
struct sdma_dev_data *dev_data = dev->data;
378378
struct sdma_channel_data *chan_data;
379+
unsigned int key;
379380

380381
chan_data = &dev_data->chan[channel];
381382

383+
key = irq_lock();
382384
stat->free = chan_data->stat.free;
383385
stat->pending_length = chan_data->stat.pending_length;
386+
irq_unlock(key);
384387

385388
return 0;
386389
}
@@ -390,18 +393,21 @@ static int dma_nxp_sdma_reload(const struct device *dev, uint32_t channel, uint3
390393
{
391394
struct sdma_dev_data *dev_data = dev->data;
392395
struct sdma_channel_data *chan_data;
396+
unsigned int key;
393397

394398
chan_data = &dev_data->chan[channel];
395399

396400
if (!size) {
397401
return 0;
398402
}
399403

404+
key = irq_lock();
400405
if (chan_data->direction == MEMORY_TO_PERIPHERAL) {
401406
dma_nxp_sdma_produce(chan_data, size);
402407
} else {
403408
dma_nxp_sdma_consume(chan_data, size);
404409
}
410+
irq_unlock(key);
405411

406412
return 0;
407413
}

0 commit comments

Comments
 (0)