]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Jan 2026 15:39:30 +0000 (16:39 +0100)
[ Upstream commit a428e0da1248c353557970848994f35fd3f005e2 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/marvell/prestera/prestera_devlink.c

index 06279cd6da6746e3333fc1928ba0ab67517d5968..8f0ae62d4a8933483d9988879c6b1740ed9138c0 100644 (file)
@@ -392,6 +392,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);
 }