Message ID | 20220326081239.9168-1-zhengyongjun3@huawei.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 0906f3a3df07835e37077d8971aac65347f2ed57 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: sparx5: switchdev: fix possible NULL pointer dereference | expand |
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Sat, 26 Mar 2022 08:12:39 +0000 you wrote: > 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: 10615907e9b51 ("net: sparx5: switchdev: adding frame DMA functionality") > Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com> > > [...] Here is the summary with links: - net: sparx5: switchdev: fix possible NULL pointer dereference https://git.kernel.org/netdev/net/c/0906f3a3df07 You are awesome, thank you!
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c index 7436f62fa152..174ad95e746a 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c @@ -420,6 +420,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); }
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: 10615907e9b51 ("net: sparx5: switchdev: adding frame DMA functionality") Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com> --- drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c | 2 ++ 1 file changed, 2 insertions(+)