Skip to contentSkip to conversation

net: marvell: prestera: fix NULL dereference on devlink_alloc() failure

PATCH Applied Alok Tiwari 3 participants 3 messages Dec 30, 2025 – Jan 4 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 34dd1710f5a3 ("net: marvell: prestera: Add basic devlink support")
---
 drivers/net/ethernet/marvell/prestera/prestera_devlink.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/prestera/prestera_devlink.c +2 -0
index 2a4c9df4eb79..e63d95c1842f 100644
@@ -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

#2 lore raw
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]; Taras

Chornyi ><[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 dereference

on devlink_alloc() >failure

Quoted 3 lines

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

>b/

Quoted 29 lines

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")

---

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..e63d95c1842f 100644

--- 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 -0
           dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch

),

Quoted 11 lines
>b/ renamed from drivers/net/ethernet/marvell/prestera/prestera_devlink.c +2 -0
                                           dev->dev);
 
+          if (!dl)
 
+                        return NULL;
 
 
           return devlink_priv(dl);

}

Quoted 7 lines
Quoted 3 lines

--

2.50.1

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

#3 lore raw
In reply to Alok Tiwari
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, 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.

[...]

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