Skip to content

Commit fdd41ec

Browse files
paravmellanoxdavem330
authored andcommitted
devlink: Return right error code in case of errors for region read
devlink_nl_cmd_region_read_dumpit() misses to return right error code on most error conditions. Return the right error code on such errors. Fixes: 4e54795 ("devlink: Add support for region snapshot read command") Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 415d394 commit fdd41ec

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

net/core/devlink.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,26 +3646,34 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
36463646
goto out_free;
36473647

36483648
devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
3649-
if (IS_ERR(devlink))
3649+
if (IS_ERR(devlink)) {
3650+
err = PTR_ERR(devlink);
36503651
goto out_free;
3652+
}
36513653

36523654
mutex_lock(&devlink_mutex);
36533655
mutex_lock(&devlink->lock);
36543656

36553657
if (!attrs[DEVLINK_ATTR_REGION_NAME] ||
3656-
!attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
3658+
!attrs[DEVLINK_ATTR_REGION_SNAPSHOT_ID]) {
3659+
err = -EINVAL;
36573660
goto out_unlock;
3661+
}
36583662

36593663
region_name = nla_data(attrs[DEVLINK_ATTR_REGION_NAME]);
36603664
region = devlink_region_get_by_name(devlink, region_name);
3661-
if (!region)
3665+
if (!region) {
3666+
err = -EINVAL;
36623667
goto out_unlock;
3668+
}
36633669

36643670
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
36653671
&devlink_nl_family, NLM_F_ACK | NLM_F_MULTI,
36663672
DEVLINK_CMD_REGION_READ);
3667-
if (!hdr)
3673+
if (!hdr) {
3674+
err = -EMSGSIZE;
36683675
goto out_unlock;
3676+
}
36693677

36703678
err = devlink_nl_put_handle(skb, devlink);
36713679
if (err)
@@ -3676,8 +3684,10 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
36763684
goto nla_put_failure;
36773685

36783686
chunks_attr = nla_nest_start(skb, DEVLINK_ATTR_REGION_CHUNKS);
3679-
if (!chunks_attr)
3687+
if (!chunks_attr) {
3688+
err = -EMSGSIZE;
36803689
goto nla_put_failure;
3690+
}
36813691

36823692
if (attrs[DEVLINK_ATTR_REGION_CHUNK_ADDR] &&
36833693
attrs[DEVLINK_ATTR_REGION_CHUNK_LEN]) {
@@ -3700,8 +3710,10 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
37003710
goto nla_put_failure;
37013711

37023712
/* Check if there was any progress done to prevent infinite loop */
3703-
if (ret_offset == start_offset)
3713+
if (ret_offset == start_offset) {
3714+
err = -EINVAL;
37043715
goto nla_put_failure;
3716+
}
37053717

37063718
*((u64 *)&cb->args[0]) = ret_offset;
37073719

@@ -3720,7 +3732,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
37203732
mutex_unlock(&devlink_mutex);
37213733
out_free:
37223734
kfree(attrs);
3723-
return 0;
3735+
return err;
37243736
}
37253737

37263738
struct devlink_info_req {

0 commit comments

Comments
 (0)