Commit 1fc2257e authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

devlink: share user_ptr pointer for both devlink and devlink_port

Ptr to devlink structure can be easily obtained from
devlink_port->devlink. So share user_ptr[0] pointer for both and leave
user_ptr[1] free for other users.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 67b5b21f
...@@ -119,7 +119,8 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink, ...@@ -119,7 +119,8 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink,
return devlink_port_get_from_attrs(devlink, info->attrs); return devlink_port_get_from_attrs(devlink, info->attrs);
} }
#define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK BIT(0)
#define DEVLINK_NL_FLAG_NEED_PORT BIT(1)
static int devlink_nl_pre_doit(const struct genl_ops *ops, static int devlink_nl_pre_doit(const struct genl_ops *ops,
struct sk_buff *skb, struct genl_info *info) struct sk_buff *skb, struct genl_info *info)
...@@ -132,8 +133,9 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, ...@@ -132,8 +133,9 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
return PTR_ERR(devlink); return PTR_ERR(devlink);
} }
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_DEVLINK) {
info->user_ptr[0] = devlink; info->user_ptr[0] = devlink;
if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) { } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) {
struct devlink_port *devlink_port; struct devlink_port *devlink_port;
mutex_lock(&devlink_port_mutex); mutex_lock(&devlink_port_mutex);
...@@ -143,7 +145,7 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, ...@@ -143,7 +145,7 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
return PTR_ERR(devlink_port); return PTR_ERR(devlink_port);
} }
info->user_ptr[1] = devlink_port; info->user_ptr[0] = devlink_port;
} }
return 0; return 0;
} }
...@@ -356,8 +358,8 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg, ...@@ -356,8 +358,8 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,
static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink_port *devlink_port = info->user_ptr[0];
struct devlink_port *devlink_port = info->user_ptr[1]; struct devlink *devlink = devlink_port->devlink;
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
...@@ -436,8 +438,8 @@ static int devlink_port_type_set(struct devlink *devlink, ...@@ -436,8 +438,8 @@ static int devlink_port_type_set(struct devlink *devlink,
static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb, static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink *devlink = info->user_ptr[0]; struct devlink_port *devlink_port = info->user_ptr[0];
struct devlink_port *devlink_port = info->user_ptr[1]; struct devlink *devlink = devlink_port->devlink;
int err; int err;
if (info->attrs[DEVLINK_ATTR_PORT_TYPE]) { if (info->attrs[DEVLINK_ATTR_PORT_TYPE]) {
...@@ -511,6 +513,7 @@ static const struct genl_ops devlink_nl_ops[] = { ...@@ -511,6 +513,7 @@ static const struct genl_ops devlink_nl_ops[] = {
.doit = devlink_nl_cmd_get_doit, .doit = devlink_nl_cmd_get_doit,
.dumpit = devlink_nl_cmd_get_dumpit, .dumpit = devlink_nl_cmd_get_dumpit,
.policy = devlink_nl_policy, .policy = devlink_nl_policy,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
}, },
{ {
...@@ -533,12 +536,14 @@ static const struct genl_ops devlink_nl_ops[] = { ...@@ -533,12 +536,14 @@ static const struct genl_ops devlink_nl_ops[] = {
.doit = devlink_nl_cmd_port_split_doit, .doit = devlink_nl_cmd_port_split_doit,
.policy = devlink_nl_policy, .policy = devlink_nl_policy,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
}, },
{ {
.cmd = DEVLINK_CMD_PORT_UNSPLIT, .cmd = DEVLINK_CMD_PORT_UNSPLIT,
.doit = devlink_nl_cmd_port_unsplit_doit, .doit = devlink_nl_cmd_port_unsplit_doit,
.policy = devlink_nl_policy, .policy = devlink_nl_policy,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment