]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: marvell: prestera: fix NULL dereference on devlink_alloc() failure
authorAlok Tiwari <alok.a.tiwari@oracle.com>
Tue, 30 Dec 2025 05:21:18 +0000 (21:21 -0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 4 Jan 2026 17:38:55 +0000 (09:38 -0800)
devlink_alloc() may return NULL on allocation failure, but
prestera_devlink_alloc() unconditionally calls devlink_priv() on
the returned pointer.

This leads to a NULL pointer dereference if devlink allocation fails.
Add a check for a NULL devlink pointer and return NULL early to avoid
the crash.

Fixes: 34dd1710f5a3 ("net: marvell: prestera: Add basic devlink support")
Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Acked-by: Elad Nachman <enachman@marvell.com>
Link: https://patch.msgid.link/20251230052124.897012-1-alok.a.tiwari@oracle.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/marvell/prestera/prestera_devlink.c

index 2a4c9df4eb797259056b5a81207ea41f005053f6..e63d95c1842f3d4f9cc9ce7b38d9d58af5dd94b6 100644 (file)
@@ -387,6 +387,8 @@ struct prestera_switch *prestera_devlink_alloc(struct prestera_device *dev)
 
        dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch),
                           dev->dev);
+       if (!dl)
+               return NULL;
 
        return devlink_priv(dl);
 }