* [dpdk-dev] [PATCH] eal: save error in string copy
@ 2021-06-11 22:49 Xueming Li
2021-06-12 8:34 ` Thomas Monjalon
2021-06-12 23:05 ` [dpdk-dev] [v1] " Xueming Li
0 siblings, 2 replies; 6+ messages in thread
From: Xueming Li @ 2021-06-11 22:49 UTC (permalink / raw)
Cc: Thomas Monjalon, dev, xuemingl, Jerin Jacob, Sunil Kumar Kori,
Kiran Kumar K, Nithin Dabilpuram
From: Thomas Monjalon <thomas@monjalon.net>
Sets rte_errrno if the destination buffer is too small.
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
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 <errno.h>
#include <rte_string_fns.h>
+#include <rte_errno.h>
/* 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: save error in string copy
2021-06-11 22:49 [dpdk-dev] [PATCH] eal: save error in string copy Xueming Li
@ 2021-06-12 8:34 ` Thomas Monjalon
2021-06-12 23:06 ` Xueming(Steven) Li
2021-06-12 23:05 ` [dpdk-dev] [v1] " Xueming Li
1 sibling, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2021-06-12 8:34 UTC (permalink / raw)
To: Xueming Li
Cc: dev, Jerin Jacob, Sunil Kumar Kori, Kiran Kumar K,
Nithin Dabilpuram, david.marchand
12/06/2021 00:49, Xueming Li:
> From: Thomas Monjalon <thomas@monjalon.net>
>
> Sets rte_errrno if the destination buffer is too small.
Would be good to mention the function name,
and the reason for the change.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
You did half of the patch, so you should add your Signed-off.
> ---
> 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(-)
Did you check all occurences of rte_strcpy?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: save error in string copy
2021-06-12 8:34 ` Thomas Monjalon
@ 2021-06-12 23:06 ` Xueming(Steven) Li
0 siblings, 0 replies; 6+ messages in thread
From: Xueming(Steven) Li @ 2021-06-12 23:06 UTC (permalink / raw)
To: NBU-Contact-Thomas Monjalon
Cc: dev, Jerin Jacob, Sunil Kumar Kori, Kiran Kumar K,
Nithin Dabilpuram, david.marchand
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Saturday, June 12, 2021 4:35 PM
> To: Xueming(Steven) Li <xuemingl@nvidia.com>
> Cc: dev@dpdk.org; Jerin Jacob <jerinj@marvell.com>; Sunil Kumar Kori <skori@marvell.com>; Kiran Kumar K
> <kirankumark@marvell.com>; Nithin Dabilpuram <ndabilpuram@marvell.com>; david.marchand@redhat.com
> Subject: Re: [PATCH] eal: save error in string copy
>
> 12/06/2021 00:49, Xueming Li:
> > From: Thomas Monjalon <thomas@monjalon.net>
> >
> > Sets rte_errrno if the destination buffer is too small.
>
> Would be good to mention the function name, and the reason for the change.
>
> >
> > Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>
> You did half of the patch, so you should add your Signed-off.
>
> > ---
> > 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(-)
>
> Did you check all occurences of rte_strcpy?
Yes, looks not too much to modify.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [v1] eal: save error in string copy
2021-06-11 22:49 [dpdk-dev] [PATCH] eal: save error in string copy Xueming Li
2021-06-12 8:34 ` Thomas Monjalon
@ 2021-06-12 23:05 ` Xueming Li
2021-06-13 8:24 ` [dpdk-dev] [PATCH v2] " Xueming Li
1 sibling, 1 reply; 6+ messages in thread
From: Xueming Li @ 2021-06-12 23:05 UTC (permalink / raw)
Cc: Thomas Monjalon, dev, xuemingl, Jerin Jacob, Sunil Kumar Kori,
Kiran Kumar K, Nithin Dabilpuram
From: Thomas Monjalon <thomas@monjalon.net>
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 <thomas@monjalon.net>
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
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 <errno.h>
#include <rte_string_fns.h>
+#include <rte_errno.h>
/* 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH v2] eal: save error in string copy
2021-06-12 23:05 ` [dpdk-dev] [v1] " Xueming Li
@ 2021-06-13 8:24 ` Xueming Li
2021-07-05 10:05 ` David Marchand
0 siblings, 1 reply; 6+ messages in thread
From: Xueming Li @ 2021-06-13 8:24 UTC (permalink / raw)
Cc: Thomas Monjalon, dev, xuemingl, Jerin Jacob, Sunil Kumar Kori,
Kiran Kumar K, Nithin Dabilpuram
From: Thomas Monjalon <thomas@monjalon.net>
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 <thomas@monjalon.net>
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
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 <errno.h>
#include <rte_string_fns.h>
+#include <rte_errno.h>
/* 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] eal: save error in string copy
2021-06-13 8:24 ` [dpdk-dev] [PATCH v2] " Xueming Li
@ 2021-07-05 10:05 ` David Marchand
0 siblings, 0 replies; 6+ messages in thread
From: David Marchand @ 2021-07-05 10:05 UTC (permalink / raw)
To: Xueming Li
Cc: Thomas Monjalon, dev, Jerin Jacob, Sunil Kumar Kori,
Kiran Kumar K, Nithin Dabilpuram
On Sun, Jun 13, 2021 at 10:25 AM Xueming Li <xuemingl@nvidia.com> wrote:
>
> From: Thomas Monjalon <thomas@monjalon.net>
>
> 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 <thomas@monjalon.net>
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Added RN update.
Applied, thanks.
--
David Marchand
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-05 10:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11 22:49 [dpdk-dev] [PATCH] eal: save error in string copy Xueming Li
2021-06-12 8:34 ` Thomas Monjalon
2021-06-12 23:06 ` Xueming(Steven) Li
2021-06-12 23:05 ` [dpdk-dev] [v1] " Xueming Li
2021-06-13 8:24 ` [dpdk-dev] [PATCH v2] " Xueming Li
2021-07-05 10:05 ` David Marchand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).