Commit 67e6272d authored by Or Har-Toov's avatar Or Har-Toov Committed by Leon Romanovsky

RDMA/nldev: Add NULL check to silence false warnings

Using nlmsg_put causes static analysis tools to many
false positives of not checking the return value of nlmsg_put.

In all uses in nldev.c, payload parameter is 0 so NULL will never
be returned. So let's add useless checks to silence the warnings.
Signed-off-by: default avatarOr Har-Toov <ohartoov@nvidia.com>
Reviewed-by: default avatarMichael Guralnik <michaelgur@nvidia.com>
Link: https://lore.kernel.org/r/bd924da89d5b4f5291a4a01d9b5ae47c0a9b6a3f.1669636336.git.leonro@nvidia.comSigned-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent 2d6c66f5
...@@ -1043,6 +1043,10 @@ static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1043,6 +1043,10 @@ static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET), RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET),
0, 0); 0, 0);
if (!nlh) {
err = -EMSGSIZE;
goto err_free;
}
err = fill_dev_info(msg, device); err = fill_dev_info(msg, device);
if (err) if (err)
...@@ -1128,7 +1132,7 @@ static int _nldev_get_dumpit(struct ib_device *device, ...@@ -1128,7 +1132,7 @@ static int _nldev_get_dumpit(struct ib_device *device,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET), RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET),
0, NLM_F_MULTI); 0, NLM_F_MULTI);
if (fill_dev_info(skb, device)) { if (!nlh || fill_dev_info(skb, device)) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);
goto out; goto out;
} }
...@@ -1187,6 +1191,10 @@ static int nldev_port_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1187,6 +1191,10 @@ static int nldev_port_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET), RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET),
0, 0); 0, 0);
if (!nlh) {
err = -EMSGSIZE;
goto err_free;
}
err = fill_port_info(msg, device, port, sock_net(skb->sk)); err = fill_port_info(msg, device, port, sock_net(skb->sk));
if (err) if (err)
...@@ -1248,7 +1256,7 @@ static int nldev_port_get_dumpit(struct sk_buff *skb, ...@@ -1248,7 +1256,7 @@ static int nldev_port_get_dumpit(struct sk_buff *skb,
RDMA_NLDEV_CMD_PORT_GET), RDMA_NLDEV_CMD_PORT_GET),
0, NLM_F_MULTI); 0, NLM_F_MULTI);
if (fill_port_info(skb, device, p, sock_net(skb->sk))) { if (!nlh || fill_port_info(skb, device, p, sock_net(skb->sk))) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);
goto out; goto out;
} }
...@@ -1290,6 +1298,10 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1290,6 +1298,10 @@ static int nldev_res_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_RES_GET), RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_RES_GET),
0, 0); 0, 0);
if (!nlh) {
ret = -EMSGSIZE;
goto err_free;
}
ret = fill_res_info(msg, device); ret = fill_res_info(msg, device);
if (ret) if (ret)
...@@ -1321,7 +1333,7 @@ static int _nldev_res_get_dumpit(struct ib_device *device, ...@@ -1321,7 +1333,7 @@ static int _nldev_res_get_dumpit(struct ib_device *device,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_RES_GET), RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_RES_GET),
0, NLM_F_MULTI); 0, NLM_F_MULTI);
if (fill_res_info(skb, device)) { if (!nlh || fill_res_info(skb, device)) {
nlmsg_cancel(skb, nlh); nlmsg_cancel(skb, nlh);
goto out; goto out;
} }
...@@ -1456,7 +1468,7 @@ static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1456,7 +1468,7 @@ static int res_get_common_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_OP(nlh->nlmsg_type)), RDMA_NL_GET_OP(nlh->nlmsg_type)),
0, 0); 0, 0);
if (fill_nldev_handle(msg, device)) { if (!nlh || fill_nldev_handle(msg, device)) {
ret = -EMSGSIZE; ret = -EMSGSIZE;
goto err_free; goto err_free;
} }
...@@ -1535,7 +1547,7 @@ static int res_get_common_dumpit(struct sk_buff *skb, ...@@ -1535,7 +1547,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,
RDMA_NL_GET_OP(cb->nlh->nlmsg_type)), RDMA_NL_GET_OP(cb->nlh->nlmsg_type)),
0, NLM_F_MULTI); 0, NLM_F_MULTI);
if (fill_nldev_handle(skb, device)) { if (!nlh || fill_nldev_handle(skb, device)) {
ret = -EMSGSIZE; ret = -EMSGSIZE;
goto err; goto err;
} }
...@@ -1797,6 +1809,10 @@ static int nldev_get_chardev(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1797,6 +1809,10 @@ static int nldev_get_chardev(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_GET_CHARDEV), RDMA_NLDEV_CMD_GET_CHARDEV),
0, 0); 0, 0);
if (!nlh) {
err = -EMSGSIZE;
goto out_nlmsg;
}
data.nl_msg = msg; data.nl_msg = msg;
err = ib_get_client_nl_info(ibdev, client_name, &data); err = ib_get_client_nl_info(ibdev, client_name, &data);
...@@ -1854,6 +1870,10 @@ static int nldev_sys_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -1854,6 +1870,10 @@ static int nldev_sys_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_SYS_GET), RDMA_NLDEV_CMD_SYS_GET),
0, 0); 0, 0);
if (!nlh) {
nlmsg_free(msg);
return -EMSGSIZE;
}
err = nla_put_u8(msg, RDMA_NLDEV_SYS_ATTR_NETNS_MODE, err = nla_put_u8(msg, RDMA_NLDEV_SYS_ATTR_NETNS_MODE,
(u8)ib_devices_shared_netns); (u8)ib_devices_shared_netns);
...@@ -2034,7 +2054,7 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2034,7 +2054,7 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_STAT_SET), RDMA_NLDEV_CMD_STAT_SET),
0, 0); 0, 0);
if (fill_nldev_handle(msg, device) || if (!nlh || fill_nldev_handle(msg, device) ||
nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) { nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) {
ret = -EMSGSIZE; ret = -EMSGSIZE;
goto err_free_msg; goto err_free_msg;
...@@ -2103,6 +2123,10 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2103,6 +2123,10 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_STAT_SET), RDMA_NLDEV_CMD_STAT_SET),
0, 0); 0, 0);
if (!nlh) {
ret = -EMSGSIZE;
goto err_fill;
}
cntn = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]); cntn = nla_get_u32(tb[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]);
qpn = nla_get_u32(tb[RDMA_NLDEV_ATTR_RES_LQPN]); qpn = nla_get_u32(tb[RDMA_NLDEV_ATTR_RES_LQPN]);
...@@ -2173,7 +2197,7 @@ static int stat_get_doit_default_counter(struct sk_buff *skb, ...@@ -2173,7 +2197,7 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
RDMA_NLDEV_CMD_STAT_GET), RDMA_NLDEV_CMD_STAT_GET),
0, 0); 0, 0);
if (fill_nldev_handle(msg, device) || if (!nlh || fill_nldev_handle(msg, device) ||
nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) { nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) {
ret = -EMSGSIZE; ret = -EMSGSIZE;
goto err_msg; goto err_msg;
...@@ -2261,6 +2285,10 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2261,6 +2285,10 @@ static int stat_get_doit_qp(struct sk_buff *skb, struct nlmsghdr *nlh,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_STAT_GET), RDMA_NLDEV_CMD_STAT_GET),
0, 0); 0, 0);
if (!nlh) {
ret = -EMSGSIZE;
goto err_msg;
}
ret = rdma_counter_get_mode(device, port, &mode, &mask); ret = rdma_counter_get_mode(device, port, &mode, &mask);
if (ret) if (ret)
...@@ -2393,7 +2421,7 @@ static int nldev_stat_get_counter_status_doit(struct sk_buff *skb, ...@@ -2393,7 +2421,7 @@ static int nldev_stat_get_counter_status_doit(struct sk_buff *skb,
0, 0); 0, 0);
ret = -EMSGSIZE; ret = -EMSGSIZE;
if (fill_nldev_handle(msg, device) || if (!nlh || fill_nldev_handle(msg, device) ||
nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port))
goto err_msg; goto err_msg;
......
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