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 B765442822; Thu, 23 Mar 2023 11:54:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3607C4111C; Thu, 23 Mar 2023 11:54:46 +0100 (CET) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2045.outbound.protection.outlook.com [40.107.95.45]) by mails.dpdk.org (Postfix) with ESMTP id DF9B44021D; Thu, 23 Mar 2023 11:54:43 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AHnB6VI83EkQBzirVlTFa+uUFVrw5+o5PDXAUCj4D4TWp3/pJYm5Kt7Cw/qHA6fpGR2QNy1dJui+Fh0u0ynri2/nmBfF42Mli9faXvg4E1fl+LzlgoxEWmaAsjHHh5T8HKP9/HOqFklOhzaodan+E/Wm0SpAO+5GOURa2PoSnv95CNmdnFZPGXn6IyyzmwfNS0000WxpCyapkhe29SXK9+5AqSFw8GZZZh22BoE/JYbNhqS1nLcNWIVhx9/6Jyo3XXbn/AMSpoGnVvOpEqOl7ku97dlyZnmRvbIbnUUgvx4fhg7520kdh+W+gwb4saXVkDaQCf/i/icMVxklITTtvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IQjEJ/aOKGROFVTOyb6O4aScnt/CVLvfqJ5BMD/w7xo=; b=hUAPGdge1X9z99jnZr2slpd6dnwg8bjWZjfTlxkeKgQvRtYReuH8rlKucByl2fQs6+6lVkbZSXBegtVzdYNZW/OmhOWGrxugftzYTNH5D9mmSuOI8FyT0LQY38Xm9g0J/Fcaisvcizos1KeogBcPsHpVgSdODvprJguD5GdVWePIbHKj91YpTYVSk1GCWmB2jrraxLNcrrH3pW1kbIk1z9Q7ei0UEPn40oJww5T42nwpgo3Asgg0joKQacdu+gAuRytqf7yKVm10Wjh8l/GZvSKCnRiimphHR+y8CMUDCEscA9Rqdekmd2LbcyqMSyBtYehmtmfgem7wpGhZTIRP8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IQjEJ/aOKGROFVTOyb6O4aScnt/CVLvfqJ5BMD/w7xo=; b=CR2kCEz92zrlSE55Wr8evBquCpF0HDD55bPsSnW8j1rO+yBGcSSpdknTON2cWT5QDyuYXy8C9ZqXl5PBqBxIvCb+yD5++vj/FTpZaHQf0HjUjEb9WgwK8RGnu9GBKLNvn6gi5fti/ocqCwP3RzkhGYgmfgnj3Vy9AoHuQZhVEVNK8Z6AUIF5JvTQwEV18YJlj14nsL3D5oSqeiKcyBzLcEB9Z5OLCgrGnBvnSiQVKa440gGx4ld9izf1HVW5Xg78ISTjPYUNInwOkZ52z6MoO9IdCQaKtDmX8jlnoWL8253V1+8aTo7MOAfJvSeBbBeDhJP3zICqB62wEswZ3rN7YQ== Received: from MW4PR03CA0215.namprd03.prod.outlook.com (2603:10b6:303:b9::10) by IA1PR12MB8405.namprd12.prod.outlook.com (2603:10b6:208:3d8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38; Thu, 23 Mar 2023 10:54:42 +0000 Received: from CO1NAM11FT025.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::17) by MW4PR03CA0215.outlook.office365.com (2603:10b6:303:b9::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.38 via Frontend Transport; Thu, 23 Mar 2023 10:54:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT025.mail.protection.outlook.com (10.13.175.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.17 via Frontend Transport; Thu, 23 Mar 2023 10:54:41 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 23 Mar 2023 03:54:30 -0700 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 23 Mar 2023 03:54:28 -0700 From: Bing Zhao To: , , CC: , , Subject: [PATCH v3] net/mlx5: fix the sysfs port name translation Date: Thu, 23 Mar 2023 12:54:14 +0200 Message-ID: <20230323105414.724908-1-bingz@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230322113412.685653-1-bingz@nvidia.com> References: <20230322113412.685653-1-bingz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT025:EE_|IA1PR12MB8405:EE_ X-MS-Office365-Filtering-Correlation-Id: bf0e61dd-c6b3-4e5c-8df1-08db2b8d0143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W4zvCVpqwsh8xtwzyz2cnaIKRXymT18eYnbCVKxoGXxRfTDSplBFoeFsIpiay30ZGe76ni6mwS+SkD5n29OZpNjEI/k2WlivQ4mF2QU7vaJ3RUkNFvYA1SIEzwsMZ4rcOAvp1LPySI1jhZzuMvh3vyzFLqTspzLZL+UI4esAxgqlj6CxMxQzlDJFV0IJuQLk3mIGpHH6e2KZob/oCWDYYVHaRNcottAI1fItldJ0eiS9aj9X86qjBW6tvPAqTLZlvKiB7JaNNCBwsn4ZbDLt+BzQWDqRHYdLin72YMnJBbgc38Jr1/c+m80Ws1m2/YAPLOGBmmanRzX6FCUMgZh9nwgxNgdZn57BBRLfTsBakb9If36AepKU9sg7UH2O8lYrit9j/I74AE0kF1hFuBno1WRYI5+LIu/Y06h9260kw6rbq6cSKf1bumjGcjA1bzQqFTD7kJMGAnQg1xKxFi2acOWlKXX9wQwoengMQRh/ND3PFjiyJUp1W6gQmI468NwrIggxEUCMlADyTkumUrufDvmasnbRLI1wixuWYyE77pGtGMcv63azEqvHC0PMRkr/kE4iNSMFei/IKbGFY9gjf6Nhz91h1iJJxNGDerWKTAwv+yuTdzu5KFvc5WWdgA1Kminp0vzbEIZBtI2Xlhyojdz/TrgtILp0wWcWrLd0mxKJ59o2RS7xX0SVuiUSyVH2tyv2mirIfJfGgQen+OjwgoNrD83+SseneF3ieggYYLsAqnOywG3ZcXN9H7yz7W+i X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230025)(4636009)(346002)(39860400002)(136003)(376002)(396003)(451199018)(46966006)(40470700004)(36840700001)(86362001)(36756003)(7636003)(36860700001)(356005)(82740400003)(2906002)(40460700003)(8676002)(41300700001)(4326008)(5660300002)(8936002)(40480700001)(82310400005)(55016003)(2616005)(336012)(186003)(16526019)(6286002)(83380400001)(47076005)(426003)(54906003)(110136005)(478600001)(70586007)(70206006)(316002)(6666004)(7696005)(1076003)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2023 10:54:41.3082 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf0e61dd-c6b3-4e5c-8df1-08db2b8d0143 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT025.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8405 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 With some OFED or upstream kernel of mlx5, the port name fetched from "/sys/class/net/[DEV]/phys_port_name" may have a tailing "\n" as the EOL. The sscanf() will return the scanned items number with this EOL. In such case, the "equal to" condition is considered as false and the function mlx5_translate_port_name() will recognize the port type wrongly with UNKNOWN result. The tailing carriage return character should be removed before calling the mlx5_translate_port_name(), this was already done in the NL message handling. In the meanwhile, the possible incorrect line feed character is also taken into consideration. Fixes: 654810b56828 ("common/mlx5: share Netlink commands") Fixes: 420bbdae89f2 ("net/mlx5: fix host physical function representor naming") Cc: stable@dpdk.org Signed-off-by: Bing Zhao --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index f1ff6f49f9..55801534d1 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -1035,7 +1035,8 @@ int mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) { char ifname[IF_NAMESIZE]; - char port_name[IF_NAMESIZE]; + char *port_name = NULL; + size_t port_name_size = 0; FILE *file; struct mlx5_switch_info data = { .master = 0, @@ -1048,6 +1049,7 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) bool port_switch_id_set = false; bool device_dir = false; char c; + ssize_t line_size; if (!if_indextoname(ifindex, ifname)) { rte_errno = errno; @@ -1063,8 +1065,21 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) file = fopen(phys_port_name, "rb"); if (file != NULL) { - if (fgets(port_name, IF_NAMESIZE, file) != NULL) + char *tail_nl; + + line_size = getline(&port_name, &port_name_size, file); + if (line_size < 0) { + fclose(file); + rte_errno = errno; + return -rte_errno; + } else if (line_size > 0) { + /* Remove tailing newline character. */ + tail_nl = strchr(port_name, '\n'); + if (tail_nl) + *tail_nl = '\0'; mlx5_translate_port_name(port_name, &data); + } + free(port_name); fclose(file); } file = fopen(phys_switch_id, "rb"); -- 2.31.1