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 BEA69A0A0C; Sun, 13 Jun 2021 10:24:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C21C4003F; Sun, 13 Jun 2021 10:24:54 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2045.outbound.protection.outlook.com [40.107.94.45]) by mails.dpdk.org (Postfix) with ESMTP id 661D54003E for ; Sun, 13 Jun 2021 10:24:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vs7lte91Ny/GNN5se/kujvXiwZM+XamPXp33/l4M3kGiQkJzgSX/pJ+JesulgMpfJhQovRx4k3l/Xk/cBpGz6OYekN3Y7hTfNhB8a/Diecx5K+wh6cQFplTRUkj5C+U8V5Kccr9AQZYakZBwifIzZs/3UX0IVPQDe1JHSi2tURFcFYApgqeFT9J93itf52znxZ1dx6wLhsxk91FAAagmU0KC585nKojs2+3kIyX4elXPWnYlMKEFXmxoLsXMzfcIqhT6VQXrgOmq+rHttgprvSeniBf6+6F9B1fzn0cS/x7PHIgFKlFyJ0sCHGGb9TBY05GAb6NeHz0bmA1R9BfvfA== 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=hyVlQsetU0yZYZPAF9Kq2v99CCzlsX2Pan/7FBL9/KwVBq6RU5Jq6C9OZVRzFHmGTlPspgbBMBsE7PkAHRpf5M4WfshQFbOu78EL7EDEzk5o60q3KiI0DCI7sKx1mdNxgyq/KuQysxId2SKGYeLN/fq9wOf/DhfJuQNwXX0TlfZrDZ73GZQfNvVNHlEUmRRL/3lH1RCuQJH+JiB6h2SBYbuG+7LjfhHD2UFfsOqhUBl7LnkOfVAINGw9LH85Pe4+n3E0kMxWGGif2e5x+7CRH+lCyFx3j9MmHOCfcqVb5sy17Qj159b5k9prbwMoQe647zSeIUznG2Z7Dw2RDzLf7w== 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=fpONWf5VfJP4+NAdy/qOufXZZ9l+yNpt2h2+67rkpTuMHFxaA3Ctotj05RNNcvE48QOoUf9d5jt90en7z4gHzp+aV98S7JZD6XZef+/dNr6DdkNN5l7UMfOPcnt0ZujIgCtX+RwUbLJUt6HFH3ZZ1P/F/lnUr2rWRym7rOHnkloskxCZbOFmdXI0Pk8e/lKFMb5EzA2wuOu7bKcrlI5XCS/bVq8D5aStYdMOSrxTYaTzqG62LCGqu0I/zeyZmfuO0rSafV5dqG3XOj+CdI53H8Q53P7gqdsXOX90739oAhBD00ZWZhPwi++O5b8GjqmdKxbszAZ7MY1BZ1ZnvqHjMw== Received: from MWHPR15CA0041.namprd15.prod.outlook.com (2603:10b6:300:ad::27) by BY5PR12MB3875.namprd12.prod.outlook.com (2603:10b6:a03:1ae::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.24; Sun, 13 Jun 2021 08:24:50 +0000 Received: from CO1NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ad:cafe::56) by MWHPR15CA0041.outlook.office365.com (2603:10b6:300:ad::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Sun, 13 Jun 2021 08:24:50 +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 CO1NAM11FT020.mail.protection.outlook.com (10.13.174.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4219.21 via Frontend Transport; Sun, 13 Jun 2021 08:24:50 +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; Sun, 13 Jun 2021 08:24:47 +0000 From: Xueming Li To: CC: Thomas Monjalon , , , Jerin Jacob , Sunil Kumar Kori , Kiran Kumar K , "Nithin Dabilpuram" Date: Sun, 13 Jun 2021 16:24:21 +0800 Message-ID: <20210613082421.24453-1-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210612230519.21614-1-xuemingl@nvidia.com> References: <20210612230519.21614-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: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c105f818-c19e-4e13-0206-08d92e44b67f X-MS-TrafficTypeDiagnostic: BY5PR12MB3875: 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: riqKrscasw4OFydeBIuGJXddNJUEh7ciSa3KwDxIdFem76cL60C8TE9j3V9dXpkf9QtE1lzNQT+lI32gcWrDDmsxW92+sUk5okYIiBb8aUsKwf4VaWefRsjA4/Ei6DAWV+T1lnEGvZh2WGYc8wzzIKFi4iS5ZUqdQmalV787R/UkcF+c3+beS70YyiV3imz1twNKC+uKFIaArlH+Na97R9vkvzkvWcJOX3ckjMZnfj0LRQv1mISiLdk+g5pq8J4Jj2IoyLQ6Z380kVOws8yOFkl4HHekRvTUuALHJ5NIqytFJhzi3f7Y4S7AKf3g077zna4fmY6M+h/N0rUQmtO7VaO+vOMBEMFtE1jCH/hH4Hw/yTxq7bE9TbY6AnFIkZyD0VBQ2KK3z1byYcJmCpf7kv8JCojdqA0xPaPAG2gn6Oo+Rwwk+om2ExTwSeklPDLie5/NtKhZgJVdM2WPoy6YbRUkVg/N7uu0wUohoydFMytcax2OImoOJbZ2y572nH8CP118Jw2Q82P77jqCe3n+Z5SjyYzf31twAsJkKghABrGYTTlNEbxMcfQUA/EpHbxWEe1L0sahz0LPexJkTw708BGzKxnAOHRtH0yhLn+KnIrJXZZb3eto2exlrZqg1rVIJR7sTqU7W3Fb2sxCs3S4uqB9CzjHTd8jdXHhw2UaVdA= 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)(346002)(396003)(136003)(39860400002)(46966006)(36840700001)(478600001)(2906002)(7696005)(47076005)(6666004)(4326008)(83380400001)(109986005)(356005)(7636003)(2616005)(82740400003)(336012)(1076003)(55016002)(86362001)(26005)(5660300002)(8936002)(36906005)(426003)(8676002)(6286002)(54906003)(70206006)(36860700001)(186003)(82310400003)(70586007)(36756003)(16526019)(316002)(266003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2021 08:24:50.2497 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c105f818-c19e-4e13-0206-08d92e44b67f 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: CO1NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3875 Subject: [dpdk-dev] [PATCH v2] 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