Commit 7ca973dc authored by Leon Romanovsky's avatar Leon Romanovsky Committed by David S. Miller

devlink: Remove check of always valid devlink pointer

Devlink objects are accessible only after they were registered and
have valid devlink_*->devlink pointers.

Remove that check and simplify respective fill functions as an outcome
of such change.
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cbf6ab67
...@@ -832,12 +832,11 @@ static int devlink_port_fn_hw_addr_fill(const struct devlink_ops *ops, ...@@ -832,12 +832,11 @@ static int devlink_port_fn_hw_addr_fill(const struct devlink_ops *ops,
} }
static int devlink_nl_rate_fill(struct sk_buff *msg, static int devlink_nl_rate_fill(struct sk_buff *msg,
struct devlink *devlink,
struct devlink_rate *devlink_rate, struct devlink_rate *devlink_rate,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid, u32 seq,
u32 seq, int flags, int flags, struct netlink_ext_ack *extack)
struct netlink_ext_ack *extack)
{ {
struct devlink *devlink = devlink_rate->devlink;
void *hdr; void *hdr;
hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
...@@ -959,12 +958,12 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por ...@@ -959,12 +958,12 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
return err; return err;
} }
static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, static int devlink_nl_port_fill(struct sk_buff *msg,
struct devlink_port *devlink_port, struct devlink_port *devlink_port,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid, u32 seq,
u32 seq, int flags, int flags, struct netlink_ext_ack *extack)
struct netlink_ext_ack *extack)
{ {
struct devlink *devlink = devlink_port->devlink;
void *hdr; void *hdr;
hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
...@@ -1025,53 +1024,47 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, ...@@ -1025,53 +1024,47 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
static void devlink_port_notify(struct devlink_port *devlink_port, static void devlink_port_notify(struct devlink_port *devlink_port,
enum devlink_command cmd) enum devlink_command cmd)
{ {
struct devlink *devlink = devlink_port->devlink;
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
if (!devlink_port->devlink)
return;
WARN_ON(cmd != DEVLINK_CMD_PORT_NEW && cmd != DEVLINK_CMD_PORT_DEL); WARN_ON(cmd != DEVLINK_CMD_PORT_NEW && cmd != DEVLINK_CMD_PORT_DEL);
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return; return;
err = devlink_nl_port_fill(msg, devlink, devlink_port, cmd, 0, 0, 0, err = devlink_nl_port_fill(msg, devlink_port, cmd, 0, 0, 0, NULL);
NULL);
if (err) { if (err) {
nlmsg_free(msg); nlmsg_free(msg);
return; return;
} }
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), genlmsg_multicast_netns(&devlink_nl_family,
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); devlink_net(devlink_port->devlink), msg, 0,
DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
} }
static void devlink_rate_notify(struct devlink_rate *devlink_rate, static void devlink_rate_notify(struct devlink_rate *devlink_rate,
enum devlink_command cmd) enum devlink_command cmd)
{ {
struct devlink *devlink = devlink_rate->devlink;
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
WARN_ON(cmd != DEVLINK_CMD_RATE_NEW && WARN_ON(cmd != DEVLINK_CMD_RATE_NEW && cmd != DEVLINK_CMD_RATE_DEL);
cmd != DEVLINK_CMD_RATE_DEL);
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return; return;
err = devlink_nl_rate_fill(msg, devlink, devlink_rate, err = devlink_nl_rate_fill(msg, devlink_rate, cmd, 0, 0, 0, NULL);
cmd, 0, 0, 0, NULL);
if (err) { if (err) {
nlmsg_free(msg); nlmsg_free(msg);
return; return;
} }
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), genlmsg_multicast_netns(&devlink_nl_family,
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); devlink_net(devlink_rate->devlink), msg, 0,
DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
} }
static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg, static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,
...@@ -1096,9 +1089,7 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg, ...@@ -1096,9 +1089,7 @@ static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg,
idx++; idx++;
continue; continue;
} }
err = devlink_nl_rate_fill(msg, devlink, err = devlink_nl_rate_fill(msg, devlink_rate, cmd, id,
devlink_rate,
cmd, id,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
NLM_F_MULTI, NULL); NLM_F_MULTI, NULL);
if (err) { if (err) {
...@@ -1122,7 +1113,6 @@ static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, ...@@ -1122,7 +1113,6 @@ static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink_rate *devlink_rate = info->user_ptr[1]; struct devlink_rate *devlink_rate = info->user_ptr[1];
struct devlink *devlink = devlink_rate->devlink;
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
...@@ -1130,8 +1120,7 @@ static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, ...@@ -1130,8 +1120,7 @@ static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb,
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
err = devlink_nl_rate_fill(msg, devlink, devlink_rate, err = devlink_nl_rate_fill(msg, devlink_rate, DEVLINK_CMD_RATE_NEW,
DEVLINK_CMD_RATE_NEW,
info->snd_portid, info->snd_seq, 0, info->snd_portid, info->snd_seq, 0,
info->extack); info->extack);
if (err) { if (err) {
...@@ -1208,7 +1197,6 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, ...@@ -1208,7 +1197,6 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink_port *devlink_port = info->user_ptr[1]; 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;
...@@ -1216,8 +1204,7 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, ...@@ -1216,8 +1204,7 @@ static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb,
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
err = devlink_nl_port_fill(msg, devlink, devlink_port, err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_PORT_NEW,
DEVLINK_CMD_PORT_NEW,
info->snd_portid, info->snd_seq, 0, info->snd_portid, info->snd_seq, 0,
info->extack); info->extack);
if (err) { if (err) {
...@@ -1247,12 +1234,11 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg, ...@@ -1247,12 +1234,11 @@ static int devlink_nl_cmd_port_get_dumpit(struct sk_buff *msg,
idx++; idx++;
continue; continue;
} }
err = devlink_nl_port_fill(msg, devlink, devlink_port, err = devlink_nl_port_fill(msg, devlink_port,
DEVLINK_CMD_NEW, DEVLINK_CMD_NEW,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
NLM_F_MULTI, NLM_F_MULTI, cb->extack);
cb->extack);
if (err) { if (err) {
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
goto out; goto out;
...@@ -1488,9 +1474,8 @@ static int devlink_port_new_notifiy(struct devlink *devlink, ...@@ -1488,9 +1474,8 @@ static int devlink_port_new_notifiy(struct devlink *devlink,
goto out; goto out;
} }
err = devlink_nl_port_fill(msg, devlink, devlink_port, err = devlink_nl_port_fill(msg, devlink_port, DEVLINK_CMD_NEW,
DEVLINK_CMD_NEW, info->snd_portid, info->snd_portid, info->snd_seq, 0, NULL);
info->snd_seq, 0, NULL);
if (err) if (err)
goto out; goto out;
...@@ -5071,7 +5056,6 @@ static void devlink_nl_region_notify(struct devlink_region *region, ...@@ -5071,7 +5056,6 @@ static void devlink_nl_region_notify(struct devlink_region *region,
struct devlink_snapshot *snapshot, struct devlink_snapshot *snapshot,
enum devlink_command cmd) enum devlink_command cmd)
{ {
struct devlink *devlink = region->devlink;
struct sk_buff *msg; struct sk_buff *msg;
WARN_ON(cmd != DEVLINK_CMD_REGION_NEW && cmd != DEVLINK_CMD_REGION_DEL); WARN_ON(cmd != DEVLINK_CMD_REGION_NEW && cmd != DEVLINK_CMD_REGION_DEL);
...@@ -5080,8 +5064,9 @@ static void devlink_nl_region_notify(struct devlink_region *region, ...@@ -5080,8 +5064,9 @@ static void devlink_nl_region_notify(struct devlink_region *region,
if (IS_ERR(msg)) if (IS_ERR(msg))
return; return;
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), genlmsg_multicast_netns(&devlink_nl_family,
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); devlink_net(region->devlink), msg, 0,
DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
} }
/** /**
...@@ -6765,11 +6750,11 @@ EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy); ...@@ -6765,11 +6750,11 @@ EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy);
static int static int
devlink_nl_health_reporter_fill(struct sk_buff *msg, devlink_nl_health_reporter_fill(struct sk_buff *msg,
struct devlink *devlink,
struct devlink_health_reporter *reporter, struct devlink_health_reporter *reporter,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid,
u32 seq, int flags) u32 seq, int flags)
{ {
struct devlink *devlink = reporter->devlink;
struct nlattr *reporter_attr; struct nlattr *reporter_attr;
void *hdr; void *hdr;
...@@ -6846,8 +6831,7 @@ static void devlink_recover_notify(struct devlink_health_reporter *reporter, ...@@ -6846,8 +6831,7 @@ static void devlink_recover_notify(struct devlink_health_reporter *reporter,
if (!msg) if (!msg)
return; return;
err = devlink_nl_health_reporter_fill(msg, reporter->devlink, err = devlink_nl_health_reporter_fill(msg, reporter, cmd, 0, 0, 0);
reporter, cmd, 0, 0, 0);
if (err) { if (err) {
nlmsg_free(msg); nlmsg_free(msg);
return; return;
...@@ -7080,7 +7064,7 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, ...@@ -7080,7 +7064,7 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
goto out; goto out;
} }
err = devlink_nl_health_reporter_fill(msg, devlink, reporter, err = devlink_nl_health_reporter_fill(msg, reporter,
DEVLINK_CMD_HEALTH_REPORTER_GET, DEVLINK_CMD_HEALTH_REPORTER_GET,
info->snd_portid, info->snd_seq, info->snd_portid, info->snd_seq,
0); 0);
...@@ -7117,11 +7101,9 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -7117,11 +7101,9 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
idx++; idx++;
continue; continue;
} }
err = devlink_nl_health_reporter_fill(msg, devlink, err = devlink_nl_health_reporter_fill(
reporter, msg, reporter, DEVLINK_CMD_HEALTH_REPORTER_GET,
DEVLINK_CMD_HEALTH_REPORTER_GET, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
NLM_F_MULTI); NLM_F_MULTI);
if (err) { if (err) {
mutex_unlock(&devlink->reporters_lock); mutex_unlock(&devlink->reporters_lock);
...@@ -7143,11 +7125,11 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, ...@@ -7143,11 +7125,11 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
idx++; idx++;
continue; continue;
} }
err = devlink_nl_health_reporter_fill(msg, devlink, reporter, err = devlink_nl_health_reporter_fill(
msg, reporter,
DEVLINK_CMD_HEALTH_REPORTER_GET, DEVLINK_CMD_HEALTH_REPORTER_GET,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq, NLM_F_MULTI);
NLM_F_MULTI);
if (err) { if (err) {
mutex_unlock(&port->reporters_lock); mutex_unlock(&port->reporters_lock);
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
......
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