* [PATCH net] ionic: catch failure from devlink_alloc
@ 2023-03-01 1:36 Shannon Nelson
2023-03-01 10:48 ` Simon Horman
0 siblings, 1 reply; 2+ messages in thread
From: Shannon Nelson @ 2023-03-01 1:36 UTC (permalink / raw)
To: netdev, davem, kuba; +Cc: drivers, Shannon Nelson
Add a check for NULL on the alloc return. If devlink_alloc() fails and
we try to use devlink_priv() on the NULL return, the kernel gets very
unhappy and panics. With this fix, the driver load will still fail,
but at least it won't panic the kernel.
Fixes: 919d13a7e455 ("devlink: Set device as early as possible")
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
---
drivers/net/ethernet/pensando/ionic/ionic_devlink.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
index e6ff757895ab..4ec66a6be073 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
@@ -61,6 +61,8 @@ struct ionic *ionic_devlink_alloc(struct device *dev)
struct devlink *dl;
dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic), dev);
+ if (!dl)
+ return NULL;
return devlink_priv(dl);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] ionic: catch failure from devlink_alloc
2023-03-01 1:36 [PATCH net] ionic: catch failure from devlink_alloc Shannon Nelson
@ 2023-03-01 10:48 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2023-03-01 10:48 UTC (permalink / raw)
To: Shannon Nelson; +Cc: netdev, davem, kuba, drivers
On Tue, Feb 28, 2023 at 05:36:23PM -0800, Shannon Nelson wrote:
> Add a check for NULL on the alloc return. If devlink_alloc() fails and
> we try to use devlink_priv() on the NULL return, the kernel gets very
> unhappy and panics. With this fix, the driver load will still fail,
> but at least it won't panic the kernel.
>
> Fixes: 919d13a7e455 ("devlink: Set device as early as possible")
Although the reference commit touched the devlink_alloc() line,
I think the bug was already there, introduced by:
df69ba43217d ("ionic: Add basic framework for IONIC Network device driver")
The code change looks good to me :)
> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
> ---
> drivers/net/ethernet/pensando/ionic/ionic_devlink.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> index e6ff757895ab..4ec66a6be073 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c
> @@ -61,6 +61,8 @@ struct ionic *ionic_devlink_alloc(struct device *dev)
> struct devlink *dl;
>
> dl = devlink_alloc(&ionic_dl_ops, sizeof(struct ionic), dev);
> + if (!dl)
> + return NULL;
>
> return devlink_priv(dl);
> }
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-01 10:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 1:36 [PATCH net] ionic: catch failure from devlink_alloc Shannon Nelson
2023-03-01 10:48 ` Simon Horman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.