]> 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>
Mon, 19 Jan 2026 12:10:16 +0000 (13:10 +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 68b442eb6d6943a5bd25b703909f7e6dff8da87e..59e865df6cee0c3f52d37cd4a01ac2195c303e72 100644 (file)
@@ -396,6 +396,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);
 }