From patchwork Fri Mar 6 12:00:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Traynor X-Patchwork-Id: 66339 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DABA5A056A; Fri, 6 Mar 2020 13:01:09 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1AE282BA8; Fri, 6 Mar 2020 13:01:09 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 05062FEB for ; Fri, 6 Mar 2020 13:01:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583496067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z7ftV3nkQz3zPNKZ+QNqviAhfynMmFRCsC6eZUg346w=; b=e+2QyfOfIEFFeiyrvb+qYzuoy1J9WmqxBO5XqdoQ3vzD//2l90WD/ajIBc0WfawyGxLHFN vsYMpTxafdDzjs5WMdPHsyvm7w3JOPu4LVe3LplMSU8BFYMMB1buriOTq0NES7RwwkRqHL F3xFECMqQFfaPH+8QppaZ3VhQ1pNLE8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-432-rfmNKLB5NHGc2WNSgKue1Q-1; Fri, 06 Mar 2020 07:01:03 -0500 X-MC-Unique: rfmNKLB5NHGc2WNSgKue1Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CFDD107ACC7; Fri, 6 Mar 2020 12:01:02 +0000 (UTC) Received: from rh.redhat.com (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFB0D1001B07; Fri, 6 Mar 2020 12:00:58 +0000 (UTC) From: Kevin Traynor To: dev@dpdk.org Cc: Kevin Traynor , stable@dpdk.org, xuanziyang2@huawei.com, cloud.wangxiaoyun@huawei.com, zhouguoyang@huawei.com Date: Fri, 6 Mar 2020 12:00:46 +0000 Message-Id: <20200306120047.29392-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH 1/2] net/hinic: fix snprintf length X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Correct length and remove unecessary brackets. Fixes: d9ce1917941c ("net/hinic/base: add hardware operation") Cc: stable@dpdk.org Signed-off-by: Kevin Traynor --- Cc: xuanziyang2@huawei.com Cc: cloud.wangxiaoyun@huawei.com Cc: zhouguoyang@huawei.com --- drivers/net/hinic/base/hinic_pmd_hwdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c index 8b16897ad..b6c821a2a 100644 --- a/drivers/net/hinic/base/hinic_pmd_hwdev.c +++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c @@ -1391,5 +1391,5 @@ static void print_cable_info(struct hinic_link_info *info) memcpy(tmp_vendor, info->vendor_name, sizeof(info->vendor_name)); - snprintf(tmp_str, (sizeof(tmp_str) - 1), + snprintf(tmp_str, sizeof(tmp_str), "Vendor: %s, %s, %s, length: %um, max_speed: %uGbps", tmp_vendor, info->sfp_type ? "SFP" : "QSFP", port_type, From patchwork Fri Mar 6 12:00:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kevin Traynor X-Patchwork-Id: 66340 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AA3A6A056A; Fri, 6 Mar 2020 13:01:19 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7C6161BFE2; Fri, 6 Mar 2020 13:01:12 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 0ECA31BFDD for ; Fri, 6 Mar 2020 13:01:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583496070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J7Igk8iQFm+n64lZujt9FQZgcMft9+hJcvPym4Y9MqU=; b=cTcouqz8UnvbPh6/1JCn+RUD0BUW7h5cHlfDF6nr+6jGORbgMuaXLLRAy/RvVD9dhHoJ/8 AwgAJqrs77N1c56TSn9SUrXfRHOQgFKsj5SdQk8fbybZxfNQfKAVPjKMPpOsGpcJaA8mWV p4rZbwckaQ4AhGG80zWBDHqTkKAvuSw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-qIM_WUMrPbOD0cLM_WzdjQ-1; Fri, 06 Mar 2020 07:01:07 -0500 X-MC-Unique: qIM_WUMrPbOD0cLM_WzdjQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23D1D18CA240; Fri, 6 Mar 2020 12:01:06 +0000 (UTC) Received: from rh.redhat.com (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F5511001902; Fri, 6 Mar 2020 12:01:02 +0000 (UTC) From: Kevin Traynor To: dev@dpdk.org Cc: Kevin Traynor , stable@dpdk.org, xuanziyang2@huawei.com, cloud.wangxiaoyun@huawei.com, zhouguoyang@huawei.com Date: Fri, 6 Mar 2020 12:00:47 +0000 Message-Id: <20200306120047.29392-2-ktraynor@redhat.com> In-Reply-To: <20200306120047.29392-1-ktraynor@redhat.com> References: <20200306120047.29392-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH 2/2] net/hinic: fix repeating log and length check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" gcc 10.0.1 reports: ../drivers/net/hinic/base/hinic_pmd_hwdev.c: In function ‘print_cable_info’: ../drivers/net/hinic/base/hinic_pmd_hwdev.c:1398:3: warning: ‘snprintf’ argument 4 may overlap destination object ‘tmp_str’ [-Wrestrict] 1398 | snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1399 | "%s, Temperature: %u", tmp_str, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1400 | info->cable_temp); | ~~~~~~~~~~~~~~~~~ The warning is that tmp_str is in both src and dest. Anyway, the current code is incorrect and because of the +strlen the existing string will be repeated twice and max length does not limit to the end of the string. Fix by removing tmp_str from the src of snprintf and adding the correct max length. Fixes: d9ce1917941c ("net/hinic/base: add hardware operation") Cc: stable@dpdk.org Signed-off-by: Kevin Traynor --- Cc: xuanziyang2@huawei.com Cc: cloud.wangxiaoyun@huawei.com Cc: zhouguoyang@huawei.com --- drivers/net/hinic/base/hinic_pmd_hwdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c index b6c821a2a..fd0292f84 100644 --- a/drivers/net/hinic/base/hinic_pmd_hwdev.c +++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c @@ -1396,7 +1396,7 @@ static void print_cable_info(struct hinic_link_info *info) info->cable_length, info->cable_max_speed); if (info->port_type != LINK_PORT_COPPER) - snprintf(tmp_str + strlen(tmp_str), (sizeof(tmp_str) - 1), - "%s, Temperature: %u", tmp_str, - info->cable_temp); + snprintf(tmp_str + strlen(tmp_str), + sizeof(tmp_str) - strlen(tmp_str), + ", Temperature: %u", info->cable_temp); PMD_DRV_LOG(INFO, "Cable information: %s", tmp_str);