diff options
author | Vladyslav Tarasiuk <vladyslavt@mellanox.com> | 2020-07-10 15:25:07 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2020-07-10 14:32:02 -0700 |
commit | c57544b3dec4480c1b455a43f18be5ec91ab3136 (patch) | |
tree | a6f744da5e77dafd8d969283302527be4779f6a6 /net/core | |
parent | d6c7fc0c8cccf6adcc0d3995c4eba740d05832da (diff) | |
download | linux-c57544b3dec4480c1b455a43f18be5ec91ab3136.tar.gz linux-c57544b3dec4480c1b455a43f18be5ec91ab3136.tar.bz2 linux-c57544b3dec4480c1b455a43f18be5ec91ab3136.zip |
devlink: Refactor devlink health reporter constructor
Prepare a common routine in devlink_health_reporter_create() for usage
in similar functions for devlink port health reporters.
Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/devlink.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c index 346d385ba09f..a203d35fb56f 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5321,6 +5321,31 @@ devlink_health_reporter_find_by_name(struct devlink *devlink, return NULL; } +static struct devlink_health_reporter * +__devlink_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) +{ + struct devlink_health_reporter *reporter; + + if (WARN_ON(graceful_period && !ops->recover)) + return ERR_PTR(-EINVAL); + + reporter = kzalloc(sizeof(*reporter), GFP_KERNEL); + if (!reporter) + return ERR_PTR(-ENOMEM); + + reporter->priv = priv; + reporter->ops = ops; + reporter->devlink = devlink; + reporter->graceful_period = graceful_period; + reporter->auto_recover = !!ops->recover; + reporter->auto_dump = !!ops->dump; + mutex_init(&reporter->dump_lock); + refcount_set(&reporter->refcount, 1); + return reporter; +} + /** * devlink_health_reporter_create - create devlink health reporter * @@ -5342,25 +5367,11 @@ devlink_health_reporter_create(struct devlink *devlink, goto unlock; } - if (WARN_ON(graceful_period && !ops->recover)) { - reporter = ERR_PTR(-EINVAL); + reporter = __devlink_health_reporter_create(devlink, ops, + graceful_period, priv); + if (IS_ERR(reporter)) goto unlock; - } - - reporter = kzalloc(sizeof(*reporter), GFP_KERNEL); - if (!reporter) { - reporter = ERR_PTR(-ENOMEM); - goto unlock; - } - reporter->priv = priv; - reporter->ops = ops; - reporter->devlink = devlink; - reporter->graceful_period = graceful_period; - reporter->auto_recover = !!ops->recover; - reporter->auto_dump = !!ops->dump; - mutex_init(&reporter->dump_lock); - refcount_set(&reporter->refcount, 1); list_add_tail(&reporter->list, &devlink->reporter_list); unlock: mutex_unlock(&devlink->reporters_lock); |