Skip to contentSkip to conversation

ionic: catch failure from devlink_alloc

PATCH Applied Shannon Nelson 4 participants 4 messages May 2, 2023 – May 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ionic: catch failure from devlink_alloc

Add a check for NULL on the alloc return. If devlink_alloc() fails and we try to use devlink_priv() on the NULL return, the kernel gets very unhappy and panics. With this fix, the driver load will still fail, but at least it won't panic the kernel.

Fixes df69ba43217d ("ionic: Add basic framework for IONIC Network device driver")

---
v2 - fixed up the Fixes tag - thanks, Simon

	https://lore.kernel.org/netdev/Y%[email protected]/
 drivers/net/ethernet/pensando/ionic/ionic_devlink.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_devlink.c +2 -0
index e6ff757895ab..4ec66a6be073 100644
@@ -61,6 +61,8 @@ struct ionic *ionic_devlink_alloc(struct device *dev)
 	struct devlink *dl;
 
 	dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic), dev);
+	if (!dl)
+		return NULL;
 
 	return devlink_priv(dl);
 }
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Shannon Nelson

Add a check for NULL on the alloc return. If devlink_alloc() fails and we try to use devlink_priv() on the NULL return, the kernel gets very unhappy and panics. With this fix, the driver load will still fail, but at least it won't panic the kernel.

Fixes df69ba43217d ("ionic: Add basic framework for IONIC Network device driver")

---
v2 - fixed up the Fixes tag - thanks, Simon

	https://lore.kernel.org/netdev/Y%[email protected]/

Likewise, thanks.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Shannon Nelson
Quoted 7 lines · Tue, May 02, 2023 at 08:35:36PM CEST, [email protected] wrote:

Add a check for NULL on the alloc return. If devlink_alloc() fails and we try to use devlink_priv() on the NULL return, the kernel gets very unhappy and panics. With this fix, the driver load will still fail, but at least it won't panic the kernel.

Fixes df69ba43217d ("ionic: Add basic framework for IONIC Network device driver")
#3 lore raw
In reply to Shannon Nelson
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 9 lines · On Tue, 2 May 2023 11:35:36 -0700 you wrote:

Add a check for NULL on the alloc return. If devlink_alloc() fails and we try to use devlink_priv() on the NULL return, the kernel gets very unhappy and panics. With this fix, the driver load will still fail, but at least it won't panic the kernel.

Fixes df69ba43217d ("ionic: Add basic framework for IONIC Network device driver")

[...]

Here is the summary with links:
- [v2,net] ionic: catch failure from devlink_alloc

    https://git.kernel.org/netdev/net/c/4a54903ff68d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html