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

dmaengine: tegra-apb: proper default init of channel slave_id

Initialize default channel slave_id(req_sel) to invalid id
(i.e max supported slave id + 1) to avoid overwriting of slave_id
during tegra_dma_slave_config() with client data if slave_id
is not initialized through DT

Signed-off-by: Shardar Shariff Md <smohammed@nvidia.com>
Reviewed-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>

authored by

Shardar Shariff Md and committed by
Vinod Koul
00ef4490 f55532a0

+14 -2
+14 -2
drivers/dma/tegra20-apb-dma.c
··· 54 54 #define TEGRA_APBDMA_CSR_ONCE BIT(27) 55 55 #define TEGRA_APBDMA_CSR_FLOW BIT(21) 56 56 #define TEGRA_APBDMA_CSR_REQ_SEL_SHIFT 16 57 + #define TEGRA_APBDMA_CSR_REQ_SEL_MASK 0x1F 57 58 #define TEGRA_APBDMA_CSR_WCOUNT_MASK 0xFFFC 58 59 59 60 /* STATUS register */ ··· 114 113 115 114 /* Channel base address offset from APBDMA base address */ 116 115 #define TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET 0x1000 116 + 117 + #define TEGRA_APBDMA_SLAVE_ID_INVALID (TEGRA_APBDMA_CSR_REQ_SEL_MASK + 1) 117 118 118 119 struct tegra_dma; 119 120 ··· 356 353 } 357 354 358 355 memcpy(&tdc->dma_sconfig, sconfig, sizeof(*sconfig)); 359 - if (!tdc->slave_id) 356 + if (tdc->slave_id == TEGRA_APBDMA_SLAVE_ID_INVALID) { 357 + if (sconfig->slave_id > TEGRA_APBDMA_CSR_REQ_SEL_MASK) 358 + return -EINVAL; 360 359 tdc->slave_id = sconfig->slave_id; 360 + } 361 361 tdc->config_init = true; 362 362 return 0; 363 363 } ··· 1242 1236 } 1243 1237 pm_runtime_put(tdma->dev); 1244 1238 1245 - tdc->slave_id = 0; 1239 + tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID; 1246 1240 } 1247 1241 1248 1242 static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec, ··· 1251 1245 struct tegra_dma *tdma = ofdma->of_dma_data; 1252 1246 struct dma_chan *chan; 1253 1247 struct tegra_dma_channel *tdc; 1248 + 1249 + if (dma_spec->args[0] > TEGRA_APBDMA_CSR_REQ_SEL_MASK) { 1250 + dev_err(tdma->dev, "Invalid slave id: %d\n", dma_spec->args[0]); 1251 + return NULL; 1252 + } 1254 1253 1255 1254 chan = dma_get_any_slave_channel(&tdma->dma_dev); 1256 1255 if (!chan) ··· 1400 1389 &tdma->dma_dev.channels); 1401 1390 tdc->tdma = tdma; 1402 1391 tdc->id = i; 1392 + tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID; 1403 1393 1404 1394 tasklet_init(&tdc->tasklet, tegra_dma_tasklet, 1405 1395 (unsigned long)tdc);