Skip to content

Commit eb91224

Browse files
kishonvinodkoul
authored andcommitted
dmaengine: ti: k3-udma: Set r/tchan or rflow to NULL if request fail
udma_get_*() checks if rchan/tchan/rflow is already allocated by checking if it has a NON NULL value. For the error cases, rchan/tchan/rflow will have error value and udma_get_*() considers this as already allocated (PASS) since the error values are NON NULL. This results in NULL pointer dereference error while de-referencing rchan/tchan/rflow. Reset the value of rchan/tchan/rflow to NULL if a channel request fails. CC: [email protected] Acked-by: Peter Ujfalusi <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 5c6c6d6 commit eb91224

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/dma/ti/k3-udma.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,7 @@ static int bcdma_get_bchan(struct udma_chan *uc)
13801380
static int udma_get_tchan(struct udma_chan *uc)
13811381
{
13821382
struct udma_dev *ud = uc->ud;
1383+
int ret;
13831384

13841385
if (uc->tchan) {
13851386
dev_dbg(ud->dev, "chan%d: already have tchan%d allocated\n",
@@ -1394,8 +1395,11 @@ static int udma_get_tchan(struct udma_chan *uc)
13941395
*/
13951396
uc->tchan = __udma_reserve_tchan(ud, uc->config.channel_tpl,
13961397
uc->config.mapped_channel_id);
1397-
if (IS_ERR(uc->tchan))
1398-
return PTR_ERR(uc->tchan);
1398+
if (IS_ERR(uc->tchan)) {
1399+
ret = PTR_ERR(uc->tchan);
1400+
uc->tchan = NULL;
1401+
return ret;
1402+
}
13991403

14001404
if (ud->tflow_cnt) {
14011405
int tflow_id;
@@ -1425,6 +1429,7 @@ static int udma_get_tchan(struct udma_chan *uc)
14251429
static int udma_get_rchan(struct udma_chan *uc)
14261430
{
14271431
struct udma_dev *ud = uc->ud;
1432+
int ret;
14281433

14291434
if (uc->rchan) {
14301435
dev_dbg(ud->dev, "chan%d: already have rchan%d allocated\n",
@@ -1439,8 +1444,13 @@ static int udma_get_rchan(struct udma_chan *uc)
14391444
*/
14401445
uc->rchan = __udma_reserve_rchan(ud, uc->config.channel_tpl,
14411446
uc->config.mapped_channel_id);
1447+
if (IS_ERR(uc->rchan)) {
1448+
ret = PTR_ERR(uc->rchan);
1449+
uc->rchan = NULL;
1450+
return ret;
1451+
}
14421452

1443-
return PTR_ERR_OR_ZERO(uc->rchan);
1453+
return 0;
14441454
}
14451455

14461456
static int udma_get_chan_pair(struct udma_chan *uc)
@@ -1494,6 +1504,7 @@ static int udma_get_chan_pair(struct udma_chan *uc)
14941504
static int udma_get_rflow(struct udma_chan *uc, int flow_id)
14951505
{
14961506
struct udma_dev *ud = uc->ud;
1507+
int ret;
14971508

14981509
if (!uc->rchan) {
14991510
dev_err(ud->dev, "chan%d: does not have rchan??\n", uc->id);
@@ -1507,8 +1518,13 @@ static int udma_get_rflow(struct udma_chan *uc, int flow_id)
15071518
}
15081519

15091520
uc->rflow = __udma_get_rflow(ud, flow_id);
1521+
if (IS_ERR(uc->rflow)) {
1522+
ret = PTR_ERR(uc->rflow);
1523+
uc->rflow = NULL;
1524+
return ret;
1525+
}
15101526

1511-
return PTR_ERR_OR_ZERO(uc->rflow);
1527+
return 0;
15121528
}
15131529

15141530
static void bcdma_put_bchan(struct udma_chan *uc)

0 commit comments

Comments
 (0)