Skip to content

Commit a428e0d

Browse files
aloktiwakuba-moo
authored andcommitted
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: 34dd171 ("net: marvell: prestera: Add basic devlink support") Signed-off-by: Alok Tiwari <[email protected]> Acked-by: Elad Nachman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dbf8fe8 commit a428e0d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/net/ethernet/marvell/prestera/prestera_devlink.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ struct prestera_switch *prestera_devlink_alloc(struct prestera_device *dev)
387387

388388
dl = devlink_alloc(&prestera_dl_ops, sizeof(struct prestera_switch),
389389
dev->dev);
390+
if (!dl)
391+
return NULL;
390392

391393
return devlink_priv(dl);
392394
}

0 commit comments

Comments
 (0)