From patchwork Tue Feb 1 17:39:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Claudi X-Patchwork-Id: 12732089 X-Patchwork-Delegate: stephen@networkplumber.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56B83C433FE for ; Tue, 1 Feb 2022 17:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241464AbiBARkT (ORCPT ); Tue, 1 Feb 2022 12:40:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51109 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241585AbiBARkS (ORCPT ); Tue, 1 Feb 2022 12:40:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643737218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y04lGEKjC/hmo1MyxrvxM+WIGyydNovofQoZFDBLn54=; b=TljBxXn1l62+GT7PEG2LbxIRwB/1bOl9TNkoDr9NyLUFiG1z3bZ4yjXv0tt0ViF+M2Il0j BkNE3NAuUehd60SzcPPQDRABm8Wc/GklwIRd03B/9v8QOhZGoXXLeE8XRlLYIiZY9KjJ1Z w9SjDPXGWRmnuWjTDoZ0G9Qu+gWoeaE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-jnGFxkrBM_mvHvbhVT8IOQ-1; Tue, 01 Feb 2022 12:40:16 -0500 X-MC-Unique: jnGFxkrBM_mvHvbhVT8IOQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B404810144E3; Tue, 1 Feb 2022 17:39:53 +0000 (UTC) Received: from tc2.redhat.com (unknown [10.39.195.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E65DD1903; Tue, 1 Feb 2022 17:39:52 +0000 (UTC) From: Andrea Claudi To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, markzhang@nvidia.com, leonro@nvidia.com Subject: [PATCH iproute2 1/3] lib/fs: fix memory leak in get_task_name() Date: Tue, 1 Feb 2022 18:39:24 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com asprintf() allocates memory which is not freed on the error path of get_task_name(), thus potentially leading to memory leaks. This commit fixes this using free() on error paths. Fixes: 81bfd01a4c9e ("lib: move get_task_name() from rdma") Signed-off-by: Andrea Claudi --- lib/fs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/fs.c b/lib/fs.c index f6f5f8a0..5692e2d3 100644 --- a/lib/fs.c +++ b/lib/fs.c @@ -354,11 +354,15 @@ char *get_task_name(pid_t pid) return NULL; f = fopen(comm, "r"); - if (!f) + if (!f) { + free(comm); return NULL; + } - if (fscanf(f, "%ms\n", &comm) != 1) - comm = NULL; + if (fscanf(f, "%ms\n", &comm) != 1) { + free(comm); + return NULL; + } fclose(f); From patchwork Tue Feb 1 17:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Claudi X-Patchwork-Id: 12732088 X-Patchwork-Delegate: stephen@networkplumber.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 320EAC433F5 for ; Tue, 1 Feb 2022 17:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241587AbiBARkS (ORCPT ); Tue, 1 Feb 2022 12:40:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35314 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241582AbiBARkR (ORCPT ); Tue, 1 Feb 2022 12:40:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643737216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UYRLncCVsowRyoLBV+GIXTKfbnP0wqJacTT3x+w1BrI=; b=FkmpTQLlYWgzBOpbrOAsTm35enDSlpTThS28oxubdX2rQMP0j5LnXWFhr6URMgzq/AwaKb F0dArK1oHjsCi/diBliLaXcBjpsgjgdnSrvtIQUkkvwjNDc6UG0PxfNJT4nMLWpBA+Jqxp /WaKMBjLAAbnMd3Fzacb2QfxFQpfEGE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-62t8Cv4wNaGieB9wbEv9AQ-1; Tue, 01 Feb 2022 12:40:13 -0500 X-MC-Unique: 62t8Cv4wNaGieB9wbEv9AQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5016C1927836; Tue, 1 Feb 2022 17:39:55 +0000 (UTC) Received: from tc2.redhat.com (unknown [10.39.195.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BF8BD1903; Tue, 1 Feb 2022 17:39:53 +0000 (UTC) From: Andrea Claudi To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, markzhang@nvidia.com, leonro@nvidia.com Subject: [PATCH iproute2 2/3] rdma: stat: fix memory leak in res_counter_line() Date: Tue, 1 Feb 2022 18:39:25 +0100 Message-Id: <09e775d1152bc4c92722e91098de01b752a4e7cd.1643736038.git.aclaudi@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com get_task_name() uses asprintf() to reserve storage for the task name string. As asprintf() manpage states, a free() should be used to release the allocated storage when it is no longer needed. res_counter_line() uses get_task_name() but does not free the allocated storage on the error paths and after the usage. This uses a single return point to free the allocated storage, adopting the same approach of other rdma code using get_task_name(). Fixes: 5937552b42e4 ("rdma: Add "stat qp show" support") Signed-off-by: Andrea Claudi --- rdma/stat.c | 74 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/rdma/stat.c b/rdma/stat.c index adfcd34a..66121b12 100644 --- a/rdma/stat.c +++ b/rdma/stat.c @@ -222,9 +222,9 @@ static int res_counter_line(struct rd *rd, const char *name, int index, uint32_t cntn, port = 0, pid = 0, qpn, qp_type = 0; struct nlattr *hwc_table, *qp_table; struct nlattr *nla_entry; - const char *comm = NULL; + char *comm = NULL; bool isfirst; - int err; + int err, ret; if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) port = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]); @@ -232,52 +232,70 @@ static int res_counter_line(struct rd *rd, const char *name, int index, hwc_table = nla_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]; qp_table = nla_line[RDMA_NLDEV_ATTR_RES_QP]; if (!hwc_table || !qp_table || - !nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]) - return MNL_CB_ERROR; + !nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]) { + ret = MNL_CB_ERROR; + goto out; + } cntn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID]); if (rd_is_filtered_attr(rd, "cntn", cntn, - nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID])) - return MNL_CB_OK; + nla_line[RDMA_NLDEV_ATTR_STAT_COUNTER_ID])) { + ret = MNL_CB_OK; + goto out; + } if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE]) qp_type = mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_TYPE]); if (rd_is_string_filtered_attr(rd, "qp-type", qp_types_to_str(qp_type), - nla_line[RDMA_NLDEV_ATTR_RES_TYPE])) - return MNL_CB_OK; + nla_line[RDMA_NLDEV_ATTR_RES_TYPE])) { + ret = MNL_CB_OK; + goto out; + } if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); } if (rd_is_filtered_attr(rd, "pid", pid, - nla_line[RDMA_NLDEV_ATTR_RES_PID])) - return MNL_CB_OK; + nla_line[RDMA_NLDEV_ATTR_RES_PID])) { + ret = MNL_CB_OK; + goto out; + } - if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) + 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]); + } mnl_attr_for_each_nested(nla_entry, qp_table) { struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {}; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line); - if (err != MNL_CB_OK) - return -EINVAL; + if (err != MNL_CB_OK) { + ret = -EINVAL; + goto out; + } - if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN]) - return -EINVAL; + if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN]) { + ret = -EINVAL; + goto out; + } qpn = mnl_attr_get_u32(qp_line[RDMA_NLDEV_ATTR_RES_LQPN]); if (rd_is_filtered_attr(rd, "lqpn", qpn, - qp_line[RDMA_NLDEV_ATTR_RES_LQPN])) - return MNL_CB_OK; + qp_line[RDMA_NLDEV_ATTR_RES_LQPN])) { + ret = MNL_CB_OK; + goto out; + } } err = res_get_hwcounters(rd, hwc_table, false); - if (err != MNL_CB_OK) - return err; + if (err != MNL_CB_OK) { + ret = err; + goto out; + } open_json_object(NULL); print_link(rd, index, name, port, nla_line); print_color_uint(PRINT_ANY, COLOR_NONE, "cntn", "cntn %u ", cntn); @@ -292,11 +310,15 @@ static int res_counter_line(struct rd *rd, const char *name, int index, mnl_attr_for_each_nested(nla_entry, qp_table) { struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {}; err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line); - if (err != MNL_CB_OK) - return -EINVAL; + if (err != MNL_CB_OK) { + ret = -EINVAL; + goto out; + } - if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN]) - return -EINVAL; + if (!qp_line[RDMA_NLDEV_ATTR_RES_LQPN]) { + ret = -EINVAL; + goto out; + } qpn = mnl_attr_get_u32(qp_line[RDMA_NLDEV_ATTR_RES_LQPN]); if (!isfirst) @@ -307,7 +329,11 @@ static int res_counter_line(struct rd *rd, const char *name, int index, } close_json_array(PRINT_ANY, ">"); newline(rd); - return MNL_CB_OK; + ret = MNL_CB_OK; +out: + if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) + free(comm); + return ret; } static int stat_qp_show_parse_cb(const struct nlmsghdr *nlh, void *data) From patchwork Tue Feb 1 17:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Claudi X-Patchwork-Id: 12732087 X-Patchwork-Delegate: stephen@networkplumber.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD4B6C433EF for ; Tue, 1 Feb 2022 17:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241586AbiBARkS (ORCPT ); Tue, 1 Feb 2022 12:40:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23378 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233255AbiBARkR (ORCPT ); Tue, 1 Feb 2022 12:40:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643737216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qnU4vUxo8x+y3ebRuIiqy3FjsThYYN89Ijsumv5mldg=; b=i41bZJZBKbPGq5OA8X8DyO/ewaGUehd7SYpK3BPis9otDhiNXmBKmPN1y6lxcsINErHq5E yJ2OtT5EiI4UTBneIAWuyzhEiC51AG9CtkMd+tAxJXjIpi/wrOGpLDp58ATTdNiMkboERi QAp3o6zaRBUrg7KXku06WlFLWQOLSKk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-NYnMn5wuPpGJJHedICm3xw-1; Tue, 01 Feb 2022 12:40:13 -0500 X-MC-Unique: NYnMn5wuPpGJJHedICm3xw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A876793934; Tue, 1 Feb 2022 17:39:56 +0000 (UTC) Received: from tc2.redhat.com (unknown [10.39.195.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80B14D1907; Tue, 1 Feb 2022 17:39:55 +0000 (UTC) From: Andrea Claudi To: netdev@vger.kernel.org Cc: stephen@networkplumber.org, dsahern@gmail.com, markzhang@nvidia.com, leonro@nvidia.com Subject: [PATCH iproute2 3/3] rdma: RES_PID and RES_KERN_NAME are alternatives to each other Date: Tue, 1 Feb 2022 18:39:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com RDMA_NLDEV_ATTR_RES_PID and RDMA_NLDEV_ATTR_RES_KERN_NAME cannot be set together, as evident from the fill_res_name_pid() function in the kernel infiniband driver. This commit makes this clear at first glance, using an else branch for RDMA_NLDEV_ATTR_RES_KERN_NAME. This also helps coverity to better understand this code and avoid producing a bogus warning complaining about mnl_attr_get_str overwriting comm, and thus leaking the storage that comm points to. Signed-off-by: Andrea Claudi --- 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 | 11 +++++------ 8 files changed, 34 insertions(+), 41 deletions(-) diff --git a/rdma/res-cmid.c b/rdma/res-cmid.c index bfaa47b5..21bdabca 100644 --- a/rdma/res-cmid.c +++ b/rdma/res-cmid.c @@ -161,6 +161,10 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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, @@ -173,12 +177,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, diff --git a/rdma/res-cq.c b/rdma/res-cq.c index 9e7c4f51..0ba19447 100644 --- a/rdma/res-cq.c +++ b/rdma/res-cq.c @@ -86,6 +86,10 @@ static int res_cq_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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, @@ -103,11 +107,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]); diff --git a/rdma/res-ctx.c b/rdma/res-ctx.c index 30afe97a..895598d8 100644 --- a/rdma/res-ctx.c +++ b/rdma/res-ctx.c @@ -20,6 +20,10 @@ static int res_ctx_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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, @@ -33,11 +37,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]); diff --git a/rdma/res-mr.c b/rdma/res-mr.c index 1bf73f3a..9ae6c777 100644 --- a/rdma/res-mr.c +++ b/rdma/res-mr.c @@ -49,6 +49,10 @@ static int res_mr_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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, @@ -67,10 +71,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]); diff --git a/rdma/res-pd.c b/rdma/res-pd.c index df538010..aca2b0cc 100644 --- a/rdma/res-pd.c +++ b/rdma/res-pd.c @@ -36,6 +36,10 @@ static int res_pd_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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, @@ -55,11 +59,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]); diff --git a/rdma/res-qp.c b/rdma/res-qp.c index a38be399..76a5334f 100644 --- a/rdma/res-qp.c +++ b/rdma/res-qp.c @@ -148,17 +148,16 @@ static int res_qp_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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]); diff --git a/rdma/res-srq.c b/rdma/res-srq.c index 3038c352..982e3fe9 100644 --- a/rdma/res-srq.c +++ b/rdma/res-srq.c @@ -176,7 +176,12 @@ static int res_srq_line(struct rd *rd, const char *name, int idx, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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; @@ -209,11 +214,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]); diff --git a/rdma/stat.c b/rdma/stat.c index 66121b12..cf2c705b 100644 --- a/rdma/stat.c +++ b/rdma/stat.c @@ -256,19 +256,18 @@ static int res_counter_line(struct rd *rd, const char *name, int index, if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); comm = get_task_name(pid); + } 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])) { ret = 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]); - } - mnl_attr_for_each_nested(nla_entry, qp_table) { struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};