From 69056d4053e3d5580fad5cfba06c690468b980ad Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Feb 2019 15:38:36 -0600 Subject: [PATCH] net/: The value ERROR should never be returned from internal OS functions. That is reserved for returning values to appliations with the errno value set. Within the OS, errors are returned with a negated errno value ALWAYS. --- arch/arm/src/c5471/c5471_ethernet.c | 4 ++-- net/pkt/pkt_input.c | 13 +++++++------ net/tcp/tcp_listen.c | 2 +- net/udp/udp_input.c | 14 +++++++------- net/udp/udp_wrbuffer.c | 3 ++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/arch/arm/src/c5471/c5471_ethernet.c b/arch/arm/src/c5471/c5471_ethernet.c index 0d518633a7..ffbc5ae7f8 100644 --- a/arch/arm/src/c5471/c5471_ethernet.c +++ b/arch/arm/src/c5471/c5471_ethernet.c @@ -51,8 +51,8 @@ #include #include #include -#include #include +#include #include #include @@ -774,7 +774,7 @@ static int c5471_phyinit (void) if (phyid != LU3X31_T64_PHYID) { nerr("ERROR: Unrecognized PHY ID: %08x\n", phyid); - return ERROR; + return -ENODEV; } /* Next, Set desired network rate, 10BaseT, 100BaseT, or auto. */ diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c index 38e485d2a4..f5ee07c9c3 100644 --- a/net/pkt/pkt_input.c +++ b/net/pkt/pkt_input.c @@ -45,6 +45,7 @@ #include #if defined(CONFIG_NET) && defined(CONFIG_NET_PKT) +#include #include #include @@ -73,10 +74,10 @@ * dev - The device driver structure containing the received packet * * Returned Value: - * OK The packet has been processed and can be deleted - * ERROR There is a matching connection, but could not dispatch the packet - * yet. Useful when a packet arrives before a recv call is in - * place. + * OK The packet has been processed and can be deleted + * -EAGAIN There is a matching connection, but could not dispatch the packet + * yet. Useful when a packet arrives before a recv call is in + * place. * * Assumptions: * The network is locked. @@ -109,14 +110,14 @@ int pkt_input(struct net_driver_s *dev) if ((flags & PKT_NEWDATA) != 0) { - /* No.. the packet was not processed now. Return ERROR so + /* No.. the packet was not processed now. Return -EAGAIN so * that the driver may retry again later. We still need to * set d_len to zero so that the driver is aware that there * is nothing to be sent. */ nwarn("WARNING: Packet not processed\n"); - ret = ERROR; + ret = -EAGAIN; } } else diff --git a/net/tcp/tcp_listen.c b/net/tcp/tcp_listen.c index 0f9f1af920..5c1d0d671e 100644 --- a/net/tcp/tcp_listen.c +++ b/net/tcp/tcp_listen.c @@ -268,7 +268,7 @@ int tcp_accept_connection(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, uint16_t portno) { FAR struct tcp_conn_s *listener; - int ret = ERROR; + int ret = -EINVAL; /* The event processing logic has already allocated and initialized a TCP * connection -- now check there if is an application in place to accept diff --git a/net/udp/udp_input.c b/net/udp/udp_input.c index f60e95f790..dffa4bd556 100644 --- a/net/udp/udp_input.c +++ b/net/udp/udp_input.c @@ -72,11 +72,11 @@ * iplen - Length of the IP and UDP headers * * Returned Value: - * OK - The packet has been processed and can be deleted - * ERROR - Hold the packet and try again later. There is a listening - * socket but no receive in place to catch the packet yet. The - * device's d_len will be set to zero in this case as there is - * no outgoing data. + * OK - The packet has been processed and can be deleted + * -EAGAIN - Hold the packet and try again later. There is a listening + * socket but no receive in place to catch the packet yet. The + * device's d_len will be set to zero in this case as there is + * no outgoing data. * * Assumptions: * The network is locked. @@ -200,7 +200,7 @@ static int udp_input(FAR struct net_driver_s *dev, unsigned int iplen) if ((flags & UDP_NEWDATA) != 0) { - /* No.. the packet was not processed now. Return ERROR so + /* No.. the packet was not processed now. Return -EAGAIN so * that the driver may retry again later. We still need to * set d_len to zero so that the driver is aware that there * is nothing to be sent. @@ -208,7 +208,7 @@ static int udp_input(FAR struct net_driver_s *dev, unsigned int iplen) nwarn("WARNING: Packet not processed\n"); dev->d_len = 0; - ret = ERROR; + ret = -EAGAIN; } /* If the application has data to send, setup the UDP/IP header */ diff --git a/net/udp/udp_wrbuffer.c b/net/udp/udp_wrbuffer.c index 434a0f4221..987db2044a 100644 --- a/net/udp/udp_wrbuffer.c +++ b/net/udp/udp_wrbuffer.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -212,7 +213,7 @@ int udp_wrbuffer_test(void) { int val = 0; nxsem_getvalue(&g_wrbuffer.sem, &val); - return val > 0 ? OK : ERROR; + return val > 0 ? OK : -ENOSPC; } #endif /* CONFIG_NET && CONFIG_NET_UDP && CONFIG_NET_UDP_WRITE_BUFFERS */