Skip to content

Commit

Permalink
devlink: take device reference for devlink object
Browse files Browse the repository at this point in the history
In preparation to allow to access device pointer without devlink
instance lock held, make sure the device pointer is usable until
devlink_release() is called.

Fixes: c137743 ("devlink: introduce object and nested devlink relationship infra")
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Oct 18, 2023
1 parent c503bc7 commit a380687
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/devlink/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ static void devlink_release(struct work_struct *work)

mutex_destroy(&devlink->lock);
lockdep_unregister_key(&devlink->lock_key);
put_device(devlink->dev);
kfree(devlink);
}

Expand Down Expand Up @@ -425,7 +426,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
if (ret < 0)
goto err_xa_alloc;

devlink->dev = dev;
devlink->dev = get_device(dev);
devlink->ops = ops;
xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC);
xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
Expand Down

0 comments on commit a380687

Please sign in to comment.