[PATCH] net: sparx5: switchdev: fix possible NULL pointer dereference

Zheng Yongjun posted 1 patch 4 years, 2 months ago
drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] net: sparx5: switchdev: fix possible NULL pointer dereference
Posted by Zheng Yongjun 4 years, 2 months ago
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(+)

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);
 		}
-- 
2.17.1
Re: [PATCH] net: sparx5: switchdev: fix possible NULL pointer dereference
Posted by patchwork-bot+netdevbpf@kernel.org 4 years, 2 months ago
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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html