Skip to content

Commit

Permalink
net: sparx5: switchdev: fix possible NULL pointer dereference
Browse files Browse the repository at this point in the history
As the possible failure of the allocation, devm_kzalloc() may return NULL
pointer.
Therefore, it should be better to check the 'db' in order to prevent
the dereference of NULL pointer.

Fixes: 1061590 ("net: sparx5: switchdev: adding frame DMA functionality")
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Zheng Yongjun authored and David S. Miller committed Mar 26, 2022
1 parent 7781607 commit 0906f3a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ static int sparx5_fdma_tx_alloc(struct sparx5 *sparx5)
db_hw->dataptr = phys;
db_hw->status = 0;
db = devm_kzalloc(sparx5->dev, sizeof(*db), GFP_KERNEL);
if (!db)
return -ENOMEM;
db->cpu_addr = cpu_addr;
list_add_tail(&db->list, &tx->db_list);
}
Expand Down

0 comments on commit 0906f3a

Please sign in to comment.