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 6EB6FA0C47; Sun, 13 Jun 2021 01:05:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DF8184003F; Sun, 13 Jun 2021 01:05:46 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2049.outbound.protection.outlook.com [40.107.93.49]) by mails.dpdk.org (Postfix) with ESMTP id 772B64003E for ; Sun, 13 Jun 2021 01:05:45 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gUNdpywHk/F1FxXnDDB0Xm7KQS97kRCdzHI0L12NJxnjZvvmUd32mEMTCHJci1aPT2Ey6F92SYYvTMbUwDvf5PeESUbh8YJkT5Pi6bJu+dt4bVyCltO5Vht/z/R8hDpM0LWRutoQZqw7LgeMFgmD4TlXGiH821jjn053ZVY0btC8eEREjNbgg75F18cub8CYDDbljLBA5qKC0uRtE8O3gHBueHDJj0Oot93yXBf50Ty2ycwbjXTkPP3s0MHfUQTL8ZIlz6rgsoqfxtLMdc5P/Ze/dHKDEEWj62ERnvUV+d3ZmHDimU5vG+gfQBYn6Yplc6vdtFltNVsxu7UVWntObg== 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-SenderADCheck; bh=ropmM5AaQUFRCb27EZnyVJPpxHYFVDFJ7Mt1V2CnOLg=; b=glysWyX+F+il0cEjqIeHmIEYNbCFbaYAtux4yyhj7RPh1WEdJhqeN1t/M9twbNSpEsMvwdF5D5PxSQWuJYurMyIui/1fb3mkLNgBP48cYHwCTGappWoYYNQZbrqNqMV5WfhxLuKftZ6zeh3qknUn40fiX19VODGWhAOce/0dAGeFlexuoHn0o0W9bNB85Z575iVEar7VyMvInJayTv8/Q4oWjEHhdPu+GZzuZnof7VRujMdr4klU3JJa4s7tuLh/PCU05joMH5n8WykoS1qUbJhSAgZypkTENNx5v/KYx/QNn64xs4irNjKn0+pMkVK+FTk3eveQ+qFHZz38pPmBZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=marvell.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none 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=ropmM5AaQUFRCb27EZnyVJPpxHYFVDFJ7Mt1V2CnOLg=; b=fGICYRJsRmoanRZP9OU2TMonzknADrrUwlnghymsjtwzRU1yC06j53hh0skCg6hAEk1KSRFPgC8jXba4JKrv5/6blJY4Zo3hq/30Mc/Y3uv1wDAqmS0LUoNsYZYKxybFtRY97wzZFdV2gXEugmDYeqGN4fJKwa6ecOduZUVVv9NY0wm20kJV8sdqW+2myFzwmQN40jsarbV6JR5AowizvtaQWxVupenqj8sMbDhtRFG4ZSNt1UPlm4HRA1sPg3bNu+gl71x9oy6I3eXwFKGKh05ndA4Unju38qS0QItrcliLBllKvcXGPhMX/mLMumlV4VahHNLQeTRCqeSh32sPUw== Received: from MWHPR17CA0053.namprd17.prod.outlook.com (2603:10b6:300:93::15) by BY5PR12MB5559.namprd12.prod.outlook.com (2603:10b6:a03:1d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20; Sat, 12 Jun 2021 23:05:43 +0000 Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:300:93:cafe::cd) by MWHPR17CA0053.outlook.office365.com (2603:10b6:300:93::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Sat, 12 Jun 2021 23:05:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; marvell.com; dkim=none (message not signed) header.d=none;marvell.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Sat, 12 Jun 2021 23:05:43 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 12 Jun 2021 23:05:41 +0000 From: Xueming Li To: CC: Thomas Monjalon , , , Jerin Jacob , Sunil Kumar Kori , Kiran Kumar K , "Nithin Dabilpuram" Date: Sun, 13 Jun 2021 07:05:19 +0800 Message-ID: <20210612230519.21614-1-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210611224907.1904-1-xuemingl@nvidia.com> References: <20210611224907.1904-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 43141b3f-70ca-4c8d-4b09-08d92df69b12 X-MS-TrafficTypeDiagnostic: BY5PR12MB5559: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5t4B0pYBqMd6ZyZPaQCrLkRzNswAsSolNgQN1qD4dq//B8QQ9SWYhR74gHzP6tS61/UnimU7X6G4QI6lM1bFmIogu8YlFcdLzDTeCv0c9iv+MoezWBgdlpO2+GccLY+iLtGCIXxYoD6vzvdsXH7b181SyvoJWIdhtTd/9RohrOXYXx54U/L7LmTohMRsocCQduteo1F3+3FQrsQa//7o37kmvJU05w2CCTqqDJ53jsIkrCoUcoA79UoqmIoHcx+znlrTMOQjHMyEGwRVqNMPzZnNBYsUPKoEgFfZXT6808NCkBrsgoEXbxKTOhlQMOjOCz5ulsnLo9wR7nDnVydo9yKq18voudGHAfY8q8bFJlDulUkEJDcBI2s6VpQIx4W2nadanvWXX79KgxMv9Z7WyXeNFb2JKfOkLxx12q6++Z4kRGEKFpKp+YkrxZ20gzZmizgvubcut6Ig7PzTkQL8YA5ua4PFcPCjCbYgtfA8QdpLu0YSjMOgw8Z6pa58GjevyZok1cgtlBsAxcO9ovOsvmiouet/7ZyDjSVJW38ZlnGlO3dlor0WNcKFTU6fjRdjNOACdMLhafxSwqOQ5Z2IFIGoKwC1GKdKZ/7fpxcuOL4nng58wF/d9FPhRPWUgJJyeOKD4um8BuoSXAarIy1HWygTb5dBrUp/VxqIPWLyigE= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(396003)(136003)(346002)(39860400002)(36840700001)(46966006)(82310400003)(47076005)(2906002)(70206006)(70586007)(36860700001)(16526019)(5660300002)(26005)(186003)(7696005)(1076003)(426003)(6286002)(2616005)(478600001)(8676002)(109986005)(4326008)(8936002)(6666004)(54906003)(82740400003)(86362001)(36756003)(356005)(7636003)(336012)(55016002)(83380400001)(36906005)(316002)(266003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2021 23:05:43.5438 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43141b3f-70ca-4c8d-4b09-08d92df69b12 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5559 Subject: [dpdk-dev] [v1] eal: save error in string copy 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 Sender: "dev" From: Thomas Monjalon The string copy api rte_strscpy() doesn't set rte_errno during failures, instead it just return negative error number. Sets rte_errrno if the destination buffer is too small. Signed-off-by: Thomas Monjalon Signed-off-by: Xueming Li --- lib/eal/common/eal_common_string_fns.c | 4 +++- lib/eal/common/eal_common_trace.c | 1 - lib/eal/include/rte_string_fns.h | 5 ++--- lib/graph/node.c | 12 +++--------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/eal/common/eal_common_string_fns.c b/lib/eal/common/eal_common_string_fns.c index 60c5dd66f9..ddd1891656 100644 --- a/lib/eal/common/eal_common_string_fns.c +++ b/lib/eal/common/eal_common_string_fns.c @@ -8,6 +8,7 @@ #include #include +#include /* split string into tokens */ int @@ -62,5 +63,6 @@ rte_strscpy(char *dst, const char *src, size_t dsize) /* Not enough room in dst, set NUL and return error. */ if (res != 0) dst[res - 1] = '\0'; - return -E2BIG; + rte_errno = E2BIG; + return -rte_errno; } diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c index 24e27387b1..7bff1cd2ce 100644 --- a/lib/eal/common/eal_common_trace.c +++ b/lib/eal/common/eal_common_trace.c @@ -500,7 +500,6 @@ __rte_trace_point_register(rte_trace_point_t *handle, const char *name, /* Initialize the trace point */ if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) { trace_err("name is too long"); - rte_errno = E2BIG; goto free; } diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h index 8bac8243c9..bb43b2cba3 100644 --- a/lib/eal/include/rte_string_fns.h +++ b/lib/eal/include/rte_string_fns.h @@ -97,8 +97,6 @@ rte_strlcat(char *dst, const char *src, size_t size) * Copy string src to buffer dst of size dsize. * At most dsize-1 chars will be copied. * Always NUL-terminates, unless (dsize == 0). - * Returns number of bytes copied (terminating NUL-byte excluded) on success ; - * negative errno on error. * * @param dst * The destination string. @@ -110,8 +108,9 @@ rte_strlcat(char *dst, const char *src, size_t size) * Length in bytes of the destination buffer. * * @return - * The number of bytes copied on success + * The number of bytes copied (terminating NUL-byte excluded) on success. * -E2BIG if the destination buffer is too small. + * rte_errno is set. */ ssize_t rte_strscpy(char *dst, const char *src, size_t dsize); diff --git a/lib/graph/node.c b/lib/graph/node.c index 873c9ab16d..86ec4316f9 100644 --- a/lib/graph/node.c +++ b/lib/graph/node.c @@ -86,10 +86,8 @@ __rte_node_register(const struct rte_node_register *reg) } /* Initialize the node */ - if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + if (rte_strscpy(node->name, reg->name, RTE_NODE_NAMESIZE) < 0) goto free; - } node->flags = reg->flags; node->process = reg->process; node->init = reg->init; @@ -98,10 +96,8 @@ __rte_node_register(const struct rte_node_register *reg) node->parent_id = reg->parent_id; for (i = 0; i < reg->nb_edges; i++) { if (rte_strscpy(node->next_nodes[i], reg->next_nodes[i], - RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + RTE_NODE_NAMESIZE) < 0) goto free; - } } node->id = node_id++; @@ -278,10 +274,8 @@ edge_update(struct node *node, struct node *prev, rte_edge_t from, /* Update the new nodes name */ for (i = from; i < max_edges; i++, count++) { if (rte_strscpy(node->next_nodes[i], next_nodes[count], - RTE_NODE_NAMESIZE) < 0) { - rte_errno = E2BIG; + RTE_NODE_NAMESIZE) < 0) goto restore; - } } restore: /* Update the linked list to point new node address in prev node */ -- 2.25.1