From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0CC67432E5; Thu, 9 Nov 2023 15:08:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DB55A402EE; Thu, 9 Nov 2023 15:08:37 +0100 (CET) Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) by mails.dpdk.org (Postfix) with ESMTP id 1E41B4026B for ; Thu, 9 Nov 2023 15:08:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1699538917; x=1731074917; h=from:to:cc:subject:date:message-id:mime-version; bh=hcVA1CaZUJ0iOkcPOdgm5P7v4xm5DSksRQdzDx0NY7I=; b=KK75L8Uk9TY/Xt348FI7AJ1XlrhdOsYijrsqqc9rj4GmPI3STR6Zn+lP jaUS7lcUUHZChH/33+Z3m+TYaLWHp/VLVa8cKDFGQ/gIyb1NhhB0eyFoF qNtkPvtw4wRBXMPuyXaleyBCiSv3IGUO/6TMzBoFMxfPHV4+8cY5NYVPU A=; X-IronPort-AV: E=Sophos;i="6.03,289,1694736000"; d="scan'208";a="165240396" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-44b6fc51.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 14:08:35 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (pdx2-ws-svc-p26-lb5-vlan2.pdx.amazon.com [10.39.38.66]) by email-inbound-relay-pdx-2a-m6i4x-44b6fc51.us-west-2.amazon.com (Postfix) with ESMTPS id 976AAA0C3D; Thu, 9 Nov 2023 14:08:33 +0000 (UTC) Received: from EX19MTAEUC002.ant.amazon.com [10.0.43.254:63736] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.17.103:2525] with esmtp (Farcaster) id 4f32fbdd-04a2-4229-8372-60a673289811; Thu, 9 Nov 2023 14:08:32 +0000 (UTC) X-Farcaster-Flow-ID: 4f32fbdd-04a2-4229-8372-60a673289811 Received: from EX19D017EUA004.ant.amazon.com (10.252.50.239) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 9 Nov 2023 14:08:32 +0000 Received: from EX19MTAUEC001.ant.amazon.com (10.252.135.222) by EX19D017EUA004.ant.amazon.com (10.252.50.239) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 9 Nov 2023 14:08:32 +0000 Received: from HFA15-CG15235BS.amazon.com (10.85.143.175) by mail-relay.amazon.com (10.252.135.200) with Microsoft SMTP Server id 15.2.1118.39 via Frontend Transport; Thu, 9 Nov 2023 14:08:30 +0000 From: To: CC: , , , , Subject: [PATCH] net/ena: fix coverity issues Date: Thu, 9 Nov 2023 16:08:16 +0200 Message-ID: <20231109140816.2844-1-shaibran@amazon.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Shai Brandes Changed the rte_memcpy call to use the precomputed buf_size. Rearranged the ena adapter structure and removed redundant '&' operators as a precaution. Coverity issue: 405363 Coverity issue: 405357 Coverity issue: 405359 Fixes: 92401abfbcb9 ("net/ena: support connection tracking stats") Signed-off-by: Shai Brandes --- drivers/net/ena/ena_ethdev.c | 21 ++++++++++----------- drivers/net/ena/ena_ethdev.h | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/net/ena/ena_ethdev.c b/drivers/net/ena/ena_ethdev.c index dc846d2e84..53e7251874 100644 --- a/drivers/net/ena/ena_ethdev.c +++ b/drivers/net/ena/ena_ethdev.c @@ -531,8 +531,8 @@ ENA_PROXY_DESC(ena_com_get_eni_stats, ENA_MP_ENI_STATS_GET, ({ ENA_TOUCH(rsp); ENA_TOUCH(ena_dev); - if (stats != (struct ena_admin_eni_stats *)&adapter->metrics_stats) - rte_memcpy(stats, &adapter->metrics_stats, sizeof(*stats)); + if (stats != (struct ena_admin_eni_stats *)adapter->metrics_stats) + rte_memcpy(stats, adapter->metrics_stats, sizeof(*stats)); }), struct ena_com_dev *ena_dev, struct ena_admin_eni_stats *stats); @@ -590,9 +590,8 @@ ENA_PROXY_DESC(ena_com_get_customer_metrics, ENA_MP_CUSTOMER_METRICS_GET, ({ ENA_TOUCH(rsp); ENA_TOUCH(ena_dev); - ENA_TOUCH(buf_size); - if (buf != (char *)&adapter->metrics_stats) - rte_memcpy(buf, &adapter->metrics_stats, adapter->metrics_num * sizeof(uint64_t)); + if (buf != (char *)adapter->metrics_stats) + rte_memcpy(buf, adapter->metrics_stats, buf_size); }), struct ena_com_dev *ena_dev, char *buf, size_t buf_size); @@ -3240,7 +3239,7 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, } static void ena_copy_customer_metrics(struct ena_adapter *adapter, uint64_t *buf, - size_t num_metrics) + size_t num_metrics) { struct ena_com_dev *ena_dev = &adapter->ena_dev; int rc; @@ -3252,10 +3251,10 @@ static void ena_copy_customer_metrics(struct ena_adapter *adapter, uint64_t *buf } rte_spinlock_lock(&adapter->admin_lock); rc = ENA_PROXY(adapter, - ena_com_get_customer_metrics, - &adapter->ena_dev, - (char *)buf, - num_metrics * sizeof(uint64_t)); + ena_com_get_customer_metrics, + &adapter->ena_dev, + (char *)buf, + num_metrics * sizeof(uint64_t)); rte_spinlock_unlock(&adapter->admin_lock); if (rc != 0) { PMD_DRV_LOG(WARNING, "Failed to get customer metrics, rc: %d\n", rc); @@ -4088,7 +4087,7 @@ ena_mp_primary_handle(const struct rte_mp_msg *mp_msg, const void *peer) case ENA_MP_CUSTOMER_METRICS_GET: res = ena_com_get_customer_metrics(ena_dev, (char *)adapter->metrics_stats, - sizeof(uint64_t) * adapter->metrics_num); + adapter->metrics_num * sizeof(uint64_t)); break; case ENA_MP_SRD_STATS_GET: res = ena_com_get_ena_srd_info(ena_dev, diff --git a/drivers/net/ena/ena_ethdev.h b/drivers/net/ena/ena_ethdev.h index 4988fbffb5..17d292101c 100644 --- a/drivers/net/ena/ena_ethdev.h +++ b/drivers/net/ena/ena_ethdev.h @@ -344,8 +344,8 @@ struct ena_adapter { * Helper variables for holding the information about the supported * metrics. */ - uint64_t metrics_stats[ENA_MAX_CUSTOMER_METRICS] __rte_cache_aligned; - uint16_t metrics_num; + uint16_t metrics_num __rte_cache_aligned; + uint64_t metrics_stats[ENA_MAX_CUSTOMER_METRICS]; struct ena_stats_srd srd_stats __rte_cache_aligned; }; -- 2.17.1