@@ -164,6 +164,10 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
@@ -176,12 +180,6 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
- }
-
open_json_object(NULL);
print_link(rd, idx, name, port, nla_line);
res_print_uint(rd, "cm-idn", cm_idn,
@@ -89,6 +89,10 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
@@ -106,11 +110,6 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
open_json_object(NULL);
print_dev(rd, idx, name);
res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
@@ -23,6 +23,10 @@ static int res_ctx_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
@@ -36,11 +40,6 @@ static int res_ctx_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
open_json_object(NULL);
print_dev(rd, idx, name);
res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
@@ -52,6 +52,10 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
@@ -70,10 +74,6 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
open_json_object(NULL);
print_dev(rd, idx, name);
res_print_uint(rd, "mrn", mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN]);
@@ -39,6 +39,10 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
@@ -58,11 +62,6 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
nla_line[RDMA_NLDEV_ATTR_RES_PDN]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
open_json_object(NULL);
print_dev(rd, idx, name);
res_print_uint(rd, "pdn", pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN]);
@@ -151,17 +151,16 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
if (rd_is_filtered_attr(rd, "pid", pid,
nla_line[RDMA_NLDEV_ATTR_RES_PID]))
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
open_json_object(NULL);
print_link(rd, idx, name, port, nla_line);
res_print_uint(rd, "lqpn", lqpn, nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
@@ -179,7 +179,12 @@ static int res_srq_line(struct rd *rd, const char *name, int idx,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
+
if (rd_is_filtered_attr(rd, "pid", pid,
nla_line[RDMA_NLDEV_ATTR_RES_PID]))
goto out;
@@ -212,11 +217,6 @@ static int res_srq_line(struct rd *rd, const char *name, int idx,
MNL_CB_OK)
goto out;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- /* discard const from mnl_attr_get_str */
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
open_json_object(NULL);
print_dev(rd, idx, name);
res_print_uint(rd, "srqn", srqn, nla_line[RDMA_NLDEV_ATTR_RES_SRQN]);
@@ -253,15 +253,16 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
if (!get_task_name(pid, b))
comm = b;
+ } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
+ /* discard const from mnl_attr_get_str */
+ comm = (char *)mnl_attr_get_str(
+ nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
}
+
if (rd_is_filtered_attr(rd, "pid", pid,
nla_line[RDMA_NLDEV_ATTR_RES_PID]))
return MNL_CB_OK;
- if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
- comm = (char *)mnl_attr_get_str(
- nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
-
mnl_attr_for_each_nested(nla_entry, qp_table) {
struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};
RDMA_NLDEV_ATTR_RES_PID and RDMA_NLDEV_ATTR_RES_KERN_NAME cannot be set together, as evident for the fill_res_name_pid() function in the kernel infiniband driver. This commit makes this clear at first glance, using an else branch for the RDMA_NLDEV_ATTR_RES_KERN_NAME case. This also helps coverity to better understand this code and avoid producing a bogus warning complaining about mnl_attr_get_str overwriting comme, and thus leaking the storage that comm points to. Signed-off-by: Andrea Claudi <aclaudi@redhat.com> --- rdma/res-cmid.c | 10 ++++------ rdma/res-cq.c | 9 ++++----- rdma/res-ctx.c | 9 ++++----- rdma/res-mr.c | 8 ++++---- rdma/res-pd.c | 9 ++++----- rdma/res-qp.c | 9 ++++----- rdma/res-srq.c | 10 +++++----- rdma/stat.c | 9 +++++---- 8 files changed, 34 insertions(+), 39 deletions(-)