net: marvell: prestera: fix NULL dereference on devlink_alloc() failure
Subsystems (3)
PATCH 1/1 net: marvell: prestera: fix NULL dereference on devlink_alloc() failure
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.
--- drivers/net/ethernet/marvell/prestera/prestera_devlink.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_devlink.c +2 -0
@@ -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); }
Signature · 1 line
2.50.1
A message that is not in the archive (sent off-list or not yet received): BN9PR18MB4251DB54F86CFD7CA792EECBDBBCA@BN9PR18MB4251.namprd18.prod.outlook.com
Quoted 78 lines · Elad Nachman
Quoted 7 lines
From: Alok Tiwari <[email protected]>
Sent: Tuesday, December 30, 2025 7:21 AM
To: Vadym Kochan <[email protected]>; [email protected]; TarasChornyi ><[email protected]>; [email protected]; [email protected]; [email protected]; >[email protected]; [email protected]; [email protected]
Quoted 2 lines
Cc: [email protected]; [email protected]
Subject: [EXTERNAL] [PATCH net] net: marvell: prestera: fix NULL dereferenceon
devlink_alloc()>failureQuoted 3 lines
devlink_alloc()may return NULL on allocation failure, but
prestera_devlink_alloc()unconditionally >callsdevlink_priv()on the returned pointer. This leads to a NULL pointer dereference if devlink >allocation fails. Add a check for a NULL devlink>b/
Quoted 29 lines
devlink_alloc()may return NULL on allocation failure, but
prestera_devlink_alloc()unconditionally callsdevlink_priv()onthe 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 <[email protected]>---
drivers/net/ethernet/marvell/prestera/prestera_devlink.c| 2 ++1 file changed, 2 insertions(+)>b/ renamed from drivers/net/ethernet/marvell/prestera/prestera_devlink.c +0
-0
drivers/net/ethernet/marvell/prestera/prestera_devlink.c>b/ struct prestera_switch *prestera_devlink_alloc(struct
Quoted 7 lines
index
2a4c9df4eb79..e63d95c1842f100644---
a/drivers/net/ethernet/marvell/prestera/prestera_devlink.c+++
b/drivers/net/ethernet/marvell/prestera/prestera_devlink.c>b/ renamed from drivers/net/ethernet/marvell/prestera/prestera_devlink.c +0
-0@@ -387,6 +387,8 @@ struct prestera_switch *prestera_devlink_alloc(struct
prestera_device>*dev)>b/ struct prestera_switch *prestera_devlink_alloc(struct · line 387
Quoted 3 lines
>b/ renamed from drivers/net/ethernet/marvell/prestera/prestera_devlink.c +0
-0dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch),
Quoted 11 lines
>b/ renamed from drivers/net/ethernet/marvell/prestera/prestera_devlink.c +2
-0dev->dev); + if (!dl) + return NULL;return devlink_priv(dl);}
Quoted 7 lines
Quoted 3 lines
--
2.50.1
Acked-by Elad Nachman <[email protected]>
Hi Elad
Thanks for reviewing the patch, but please could you play with your mail client quoting settings because it is making a mess of the email.
Thanks
Andrew
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 29 Dec 2025 21:21:18 -0800 you wrote:
devlink_alloc()may return NULL on allocation failure, butprestera_devlink_alloc()unconditionally callsdevlink_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.
[...]
Here is the summary with links:
- [net] net: marvell: prestera: fix NULL dereference on devlink_alloc() failure
https://git.kernel.org/netdev/net/c/a428e0da1248
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html