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 329A542809; Wed, 22 Mar 2023 12:34:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F51240E09; Wed, 22 Mar 2023 12:34:58 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2089.outbound.protection.outlook.com [40.107.244.89]) by mails.dpdk.org (Postfix) with ESMTP id 0A62040A84; Wed, 22 Mar 2023 12:34:56 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mWlZteQhJZ6BzH9dNuGid2U2ooSKZhEkgGPJVBQeNEUELR9jKwNpp5uQ5No0PkNyt0sJUjnKjD7ABfj00S4DwUqdyRHMUGaQIpoIM2ykeEc+jJmw6oQtEHlzWeXm51Pb99NG/dGqrvj0ho54FUEO8k8RXFgDBEFaA85spgWXGmBnNp0diRlXrCEuvaJ//cVw2MfFkXDp6RIHiHPr1LZ+ULLMIcp8ZdPltlYNzc3dWLdyFyFt0hhfnmPbyTVCGt8xJsukRrlpMAmHLlKWB7nPsiSf/kRJyAOmQ9S0P9pNEXFt5pgB5Dq9uVzcmSTDLWvwFcMSHhPDSXsOjWmH7O+uBw== 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=rHF4FHvbzyg1lHnXT8kzO1UpH4flk0kUlwnJxHcTmD8=; b=iuJrh8LdZ5POEe0gva7ev1qFviSvUgHaI5ikEKtnbyM//Ny3VGAP4axVx6aIlGVKlzx0Q5vA8ecSIujAxRRFGk9yYhTVwd+jxV3+LSjoavim4GOskLAQPtDZnFLTkT6a1prA+/kf4la8nSXftRMYFAl7vHfxeCr98aGbjugcDkrJZYsP55zJ8Kru0BUxUKB1qo8LGphAv5lPgPufcINPmSAwoVAFwQCiIXo2HSKlCfJ3RXbn46+LirlTJ4ebjqoTBZ5M2AHqvwsoK8sHnpgCKviSUEmMDNH/DDUWT9w5W/+ZujitJdng+0HcCg3aWXsCb2HcrijvCcAzwKT5Vzw41w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=rHF4FHvbzyg1lHnXT8kzO1UpH4flk0kUlwnJxHcTmD8=; b=RMa6CjKyGHrwESs/0NMUDZBAnDYWlwa7ewDxbzwtSTJvIiMdB8JYSIyLpnCWmqf9/1rAndhkgFQDFLf40KOLOihEkVjKUqBIomELj6UifSwnpE6PGi2vlCpBL30dE2xy2rDNgmNMfuGZPg8DuiKaZgvq4vGYNQdeEyqZye7M08GEnXKuGgiOcP2PgsjvQI6jWtFcgRLbFrBhke1meJUWD95/mnBsGT0VRqFz3DfgkiBmXLNSBQvcDiac8G4WqJJLIzMY9Vcin2H883lgoo2gsh9hVaqqorKNGtRzAdU9nb2gIgqAVvJHdmULVhhG3jyTvUawnoqSi6v3Gzt3Dcwmhg== Received: from BN9PR03CA0743.namprd03.prod.outlook.com (2603:10b6:408:110::28) by BN9PR12MB5322.namprd12.prod.outlook.com (2603:10b6:408:103::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 11:34:52 +0000 Received: from BN8NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:408:110:cafe::54) by BN9PR03CA0743.outlook.office365.com (2603:10b6:408:110::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Wed, 22 Mar 2023 11:34:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT023.mail.protection.outlook.com (10.13.177.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.17 via Frontend Transport; Wed, 22 Mar 2023 11:34:52 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 22 Mar 2023 04:34:36 -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; Wed, 22 Mar 2023 04:34:34 -0700 From: Bing Zhao To: , , CC: , , Subject: [PATCH v2] common/mlx5: fix the sysfs port name translation Date: Wed, 22 Mar 2023 13:34:12 +0200 Message-ID: <20230322113412.685653-1-bingz@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221110155726.649190-1-bingz@nvidia.com> References: <20221110155726.649190-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: BN8NAM11FT023:EE_|BN9PR12MB5322:EE_ X-MS-Office365-Filtering-Correlation-Id: 261e159d-8323-4639-0cb6-08db2ac97433 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f+FLmHO66K8FRQ17jGVAPYXOYLRmrn/J16M32Y7nuuhw/Q1nFzbjxY1FninrlKRqHbY1xkBcjkJi00LZThe/sCTFuQzwayAfkqvSM6ftOA1tmOCcysszh4EXvvoSGjxj9hqg9YKpP+4vSMdyzb00Cdt7zJpavk85oXimATTG29TjJs3p67ucHkWBkUXL9Lc4mu1O+n9YkkR5UxaEvyfuRSiLHLt19rVG5/23J85w1CXEQHO1k2+4q4gEmIfYmARvyoa+Iw0QymB601YyW4bBa9U7rRM9A8v5Nc3C/twuDssuqq0zLABhZKcDGmghr++JNmdmM+cc4fUFoZgFcKrJ6Dgga4XRz/LgGM/idH8roTAwUh+R++iY/QSzXeackTqtvEljQaSXmfqbO/pYfIls/UHcanJbwmp+E/nu9Bw1/qBsjHrW2FcKiCg1jBjhDjy2TSXKPia+XcIEB51H9mPu71eKtAeWDsJLtkrPxzXxs14sptgjsnZuXGsrltiX3K5fMkMYwiI80RYy6axQHhGSfpEOUr2j1/y8NIaD2VnePB3fAuhTb0OmBykFoytBU9kiBJ15RypfTG45dod37lN4NypVRzjQqmDD8sGWtpVXNlTSK7Rg++HtaBrckhhJDNWfErewBMWpZ9cdUhkKcdPoly5b290aIKn6EcoMlcY9gab4GsMpsvQvprRIwg36q73rsaC6F4KN3e79QXpQgN5RaA83y4tcYUWdRqNqBGYXZsn1RIASs+rX+KqUsKSCD/4n X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230025)(4636009)(346002)(376002)(396003)(136003)(39860400002)(451199018)(36840700001)(40470700004)(46966006)(86362001)(82310400005)(40460700003)(36756003)(40480700001)(55016003)(7696005)(316002)(83380400001)(4326008)(8676002)(478600001)(70206006)(70586007)(54906003)(6286002)(186003)(110136005)(2616005)(426003)(26005)(47076005)(6666004)(1076003)(336012)(16526019)(356005)(8936002)(82740400003)(5660300002)(41300700001)(36860700001)(2906002)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 11:34:52.7165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 261e159d-8323-4639-0cb6-08db2ac97433 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.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5322 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 | 24 ++++++++++++++++++++++-- 1 file changed, 22 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..2955008592 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; + 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,26 @@ 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; + + port_name = (char *)malloc(IF_NAMESIZE); + if (port_name == NULL) { + fclose(file); + rte_errno = ENOMEM; + return -rte_errno; + } + line_size = getline(&port_name, &port_name_size, file); + if (line_size > 0) { + /* Remove tailing newline character. */ + tail_nl = strchr(port_name, '\n'); + if (tail_nl) + *tail_nl = '\0'; + tail_nl = strchr(port_name, '\r'); + 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