aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Pirko <jiri@mellanox.com>2016-04-08 13:12:48 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-08 15:40:08 -0400
commit1fc2257e837f86c2688fdcc5c8810b73c133794d (patch)
tree83ad768f616aac1b0e5e9f0e2c9f09dbdfcdc7d6
parent67b5b21f389502c3fb18b46d4fa9d02c38982fce (diff)
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: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/devlink.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 44f880d3b816..b84cf0df4a0e 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -119,7 +119,8 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink,
119 return devlink_port_get_from_attrs(devlink, info->attrs); 119 return devlink_port_get_from_attrs(devlink, info->attrs);
120} 120}
121 121
122#define DEVLINK_NL_FLAG_NEED_PORT BIT(0) 122#define DEVLINK_NL_FLAG_NEED_DEVLINK BIT(0)
123#define DEVLINK_NL_FLAG_NEED_PORT BIT(1)
123 124
124static int devlink_nl_pre_doit(const struct genl_ops *ops, 125static int devlink_nl_pre_doit(const struct genl_ops *ops,
125 struct sk_buff *skb, struct genl_info *info) 126 struct sk_buff *skb, struct genl_info *info)
@@ -132,8 +133,9 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
132 mutex_unlock(&devlink_mutex); 133 mutex_unlock(&devlink_mutex);
133 return PTR_ERR(devlink); 134 return PTR_ERR(devlink);
134 } 135 }
135 info->user_ptr[0] = devlink; 136 if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_DEVLINK) {
136 if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) { 137 info->user_ptr[0] = devlink;
138 } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) {
137 struct devlink_port *devlink_port; 139 struct devlink_port *devlink_port;
138 140
139 mutex_lock(&devlink_port_mutex); 141 mutex_lock(&devlink_port_mutex);
@@ -143,7 +145,7 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops,
143 mutex_unlock(&devlink_mutex); 145 mutex_unlock(&devlink_mutex);
144 return PTR_ERR(devlink_port); 146 return PTR_ERR(devlink_port);
145 } 147 }
146 info->user_ptr[1] = devlink_port; 148 info->user_ptr[0] = devlink_port;
147 } 149 }
148 return 0; 150 return 0;
149} 151}
@@ -356,8 +358,8 @@ out:
356static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, 358static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,
357 struct genl_info *info) 359 struct genl_info *info)
358{ 360{
359 struct devlink *devlink = info->user_ptr[0]; 361 struct devlink_port *devlink_port = info->user_ptr[0];
360 struct devlink_port *devlink_port = info->user_ptr[1]; 362 struct devlink *devlink = devlink_port->devlink;
361 struct sk_buff *msg; 363 struct sk_buff *msg;
362 int err; 364 int err;
363 365
@@ -436,8 +438,8 @@ static int devlink_port_type_set(struct devlink *devlink,
436static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb, 438static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb,
437 struct genl_info *info) 439 struct genl_info *info)
438{ 440{
439 struct devlink *devlink = info->user_ptr[0]; 441 struct devlink_port *devlink_port = info->user_ptr[0];
440 struct devlink_port *devlink_port = info->user_ptr[1]; 442 struct devlink *devlink = devlink_port->devlink;
441 int err; 443 int err;
442 444
443 if (info->attrs[DEVLINK_ATTR_PORT_TYPE]) { 445 if (info->attrs[DEVLINK_ATTR_PORT_TYPE]) {
@@ -511,6 +513,7 @@ static const struct genl_ops devlink_nl_ops[] = {
511 .doit = devlink_nl_cmd_get_doit, 513 .doit = devlink_nl_cmd_get_doit,
512 .dumpit = devlink_nl_cmd_get_dumpit, 514 .dumpit = devlink_nl_cmd_get_dumpit,
513 .policy = devlink_nl_policy, 515 .policy = devlink_nl_policy,
516 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
514 /* can be retrieved by unprivileged users */ 517 /* can be retrieved by unprivileged users */
515 }, 518 },
516 { 519 {
@@ -533,12 +536,14 @@ static const struct genl_ops devlink_nl_ops[] = {
533 .doit = devlink_nl_cmd_port_split_doit, 536 .doit = devlink_nl_cmd_port_split_doit,
534 .policy = devlink_nl_policy, 537 .policy = devlink_nl_policy,
535 .flags = GENL_ADMIN_PERM, 538 .flags = GENL_ADMIN_PERM,
539 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
536 }, 540 },
537 { 541 {
538 .cmd = DEVLINK_CMD_PORT_UNSPLIT, 542 .cmd = DEVLINK_CMD_PORT_UNSPLIT,
539 .doit = devlink_nl_cmd_port_unsplit_doit, 543 .doit = devlink_nl_cmd_port_unsplit_doit,
540 .policy = devlink_nl_policy, 544 .policy = devlink_nl_policy,
541 .flags = GENL_ADMIN_PERM, 545 .flags = GENL_ADMIN_PERM,
546 .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
542 }, 547 },
543}; 548};
544 549