Subject: [PATCH 5.10.y] ionic: catch failure from devlink_alloc

From: Vasiliy Kovalev <[email-masked]>
Date: Wed, 22 Oct 2025 22:54:52 +0300

From: Shannon Nelson <[email-masked]>

commit 4a54903ff68ddb33b6463c94b4eb37fc584ef760 upstream.

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")
Signed-off-by: Shannon Nelson <[email-masked]>
Reviewed-by: Simon Horman <[email-masked]>
Reviewed-by: Jiri Pirko <[email-masked]>
Signed-off-by: David S. Miller <[email-masked]>
[ kovalev: bp to fix CVE-2023-53470 ]
Signed-off-by: Vasiliy Kovalev <[email-masked]>
---
 drivers/net/ethernet/pensando/ionic/ionic_devlink.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
index 3d94064c685d..52ebecf2521e 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
@@ -65,6 +65,8 @@ struct ionic *ionic_devlink_alloc(struct device *dev)
 	struct devlink *dl;
 
 	dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic));
+	if (!dl)
+		return NULL;
 
 	return devlink_priv(dl);
 }
-- 
2.50.1