Skip to content

Commit

Permalink
devlink: Fix some error codes
Browse files Browse the repository at this point in the history
These paths don't set the error codes.  It's especially important in
devlink_nl_region_notify_build() where it leads to a NULL dereference in
the caller.

Fixes: 544e7c3 ("net: devlink: Add support for port regions")
Signed-off-by: Dan Carpenter <[email protected]>
Link: https://lore.kernel.org/r/20201026080059.GA1628785@mwanda
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Dan Carpenter authored and kuba-moo committed Oct 28, 2020
1 parent 6daa1da commit 6c21180
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -4213,10 +4213,12 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
if (err)
goto nla_put_failure;

if (region->port)
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
region->port->index))
if (region->port) {
err = nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
region->port->index);
if (err)
goto nla_put_failure;
}

err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME, region->ops->name);
if (err)
Expand Down Expand Up @@ -4265,10 +4267,12 @@ devlink_nl_region_notify_build(struct devlink_region *region,
if (err)
goto out_cancel_msg;

if (region->port)
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
region->port->index))
if (region->port) {
err = nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX,
region->port->index);
if (err)
goto out_cancel_msg;
}

err = nla_put_string(msg, DEVLINK_ATTR_REGION_NAME,
region->ops->name);
Expand Down Expand Up @@ -4962,10 +4966,12 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
if (err)
goto nla_put_failure;

if (region->port)
if (nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX,
region->port->index))
if (region->port) {
err = nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX,
region->port->index);
if (err)
goto nla_put_failure;
}

err = nla_put_string(skb, DEVLINK_ATTR_REGION_NAME, region_name);
if (err)
Expand Down

0 comments on commit 6c21180

Please sign in to comment.