From 30f292710117ff4eacccf5583e02c1ab1ef0f323 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 30 Jan 2018 17:23:10 -0600 Subject: [PATCH] binfmt/, drivers/, graphics/: Fix several inappropriate accesses to get_errno() that were missed in previous changes (some going back to nuttx-.23). --- binfmt/binfmt_schedunload.c | 8 ------- drivers/audio/wm8776.c | 4 ++-- drivers/loop/losetup.c | 14 ++++++------- drivers/syslog/syslog_stream.c | 8 +++---- drivers/usbmonitor/usbmonitor.c | 2 +- drivers/wireless/cc3000/socket.c | 6 +++--- drivers/wireless/cc3000/socket_imp.c | 13 ++++++------ graphics/nxmu/nxmu_requestbkgd.c | 28 ++----------------------- graphics/nxmu/nxmu_server.c | 31 ++++------------------------ graphics/vnc/server/vnc_negotiate.c | 30 +++++++++------------------ graphics/vnc/server/vnc_receiver.c | 18 ++++++---------- 11 files changed, 44 insertions(+), 118 deletions(-) diff --git a/binfmt/binfmt_schedunload.c b/binfmt/binfmt_schedunload.c index f742b49396..e7b981d2fe 100644 --- a/binfmt/binfmt_schedunload.c +++ b/binfmt/binfmt_schedunload.c @@ -52,14 +52,6 @@ #if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_SCHED_HAVE_PARENT) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/drivers/audio/wm8776.c b/drivers/audio/wm8776.c index c9a9ebebcc..81c77fac0a 100644 --- a/drivers/audio/wm8776.c +++ b/drivers/audio/wm8776.c @@ -566,7 +566,7 @@ static void wm8776_senddone(FAR struct i2s_dev_s *i2s, CONFIG_WM8776_MSG_PRIO); if (ret < 0) { - auderr("ERROR: mq_send failed: %d\n", errno); + auderr("ERROR: mq_send failed: %d\n", get_errno()); } } @@ -913,7 +913,7 @@ static int wm8776_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, CONFIG_WM8776_MSG_PRIO); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode > 0); auderr("ERROR: mq_send failed: %d\n", errcode); diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index 0690776e23..0a18eaff92 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -234,7 +234,7 @@ static ssize_t loop_read(FAR struct inode *inode, FAR unsigned char *buffer, FAR struct loop_struct_s *dev; ssize_t nbytesread; off_t offset; - int ret; + off_t ret; DEBUGASSERT(inode && inode->i_private); dev = (FAR struct loop_struct_s *)inode->i_private; @@ -249,10 +249,9 @@ static ssize_t loop_read(FAR struct inode *inode, FAR unsigned char *buffer, offset = start_sector * dev->sectsize + dev->offset; ret = file_seek(&dev->devfile, offset, SEEK_SET); - if (ret == (off_t)-1) + if (ret < 0) { - ferr("ERROR: Seek failed for offset=%d: %d\n", - (int)offset, get_errno()); + ferr("ERROR: Seek failed for offset=%d: %d\n", (int)offset, (int)ret); return -EIO; } @@ -290,7 +289,7 @@ static ssize_t loop_write(FAR struct inode *inode, FAR struct loop_struct_s *dev; ssize_t nbyteswritten; off_t offset; - int ret; + off_t ret; DEBUGASSERT(inode && inode->i_private); dev = (FAR struct loop_struct_s *)inode->i_private; @@ -299,10 +298,9 @@ static ssize_t loop_write(FAR struct inode *inode, offset = start_sector * dev->sectsize + dev->offset; ret = file_seek(&dev->devfile, offset, SEEK_SET); - if (ret == (off_t)-1) + if (ret < 0) { - ferr("ERROR: Seek failed for offset=%d: %d\n", - (int)offset, get_errno()); + ferr("ERROR: Seek failed for offset=%d: %d\n", (int)offset, (int)ret); } /* Then write the requested number of sectors to that position */ diff --git a/drivers/syslog/syslog_stream.c b/drivers/syslog/syslog_stream.c index a14a5d4f12..a71bd933d7 100644 --- a/drivers/syslog/syslog_stream.c +++ b/drivers/syslog/syslog_stream.c @@ -79,7 +79,7 @@ static int syslogstream_flush(FAR struct lib_syslogstream_s *stream) (size_t)iob->io_len); if (nbytes < 0) { - ret = -get_errno(); + ret = (int)nbytes; } else { @@ -172,18 +172,18 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch) */ ret = syslog_putc(ch); - if (ret != EOF) + if (ret >= 0) { this->nput++; return; } - /* The special errno value -EINTR means that syslog_putc() was + /* The special return value -EINTR means that syslog_putc() was * awakened by a signal. This is not a real error and must be * ignored in this context. */ } - while (get_errno() == -EINTR); + while (ret == -EINTR); } } } diff --git a/drivers/usbmonitor/usbmonitor.c b/drivers/usbmonitor/usbmonitor.c index 6d350f23db..3f20dbb119 100644 --- a/drivers/usbmonitor/usbmonitor.c +++ b/drivers/usbmonitor/usbmonitor.c @@ -231,7 +231,7 @@ int usbmonitor_start(void) (FAR char * const *)NULL); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); uerr("ERROR: Failed to start the USB monitor: %d\n", errcode); UNUSED(errcode); diff --git a/drivers/wireless/cc3000/socket.c b/drivers/wireless/cc3000/socket.c index 10699a7089..b1da05d0c9 100644 --- a/drivers/wireless/cc3000/socket.c +++ b/drivers/wireless/cc3000/socket.c @@ -130,7 +130,7 @@ int cc3000_socket(int domain, int type, int protocol) if (type < SOCK_STREAM || type >= ARRAY_SIZE(bsd2ti_types)) { - errno = EPROTOTYPE; + set_errno(EPROTOTYPE); return -1; } @@ -145,7 +145,7 @@ int cc3000_socket(int domain, int type, int protocol) break; default: - errno = EAFNOSUPPORT; + set_errno(EAFNOSUPPORT); return -1; } @@ -163,7 +163,7 @@ int cc3000_socket(int domain, int type, int protocol) break; default: - errno = EPROTONOSUPPORT; + set_errno(EPROTONOSUPPORT); return -1; } diff --git a/drivers/wireless/cc3000/socket_imp.c b/drivers/wireless/cc3000/socket_imp.c index a9a830e6ef..832e696a02 100644 --- a/drivers/wireless/cc3000/socket_imp.c +++ b/drivers/wireless/cc3000/socket_imp.c @@ -512,15 +512,16 @@ int cc3000_gethostbyname_impl(char *hostname, uint16_t usNameLen, unsigned long *out_ip_addr) { tBsdGethostbynameParams ret; - uint8_t *ptr, *args; - - set_errno(EFAIL); + uint8_t *ptr; + uint8_t *args; if (usNameLen > CC3000_HOSTNAME_MAX_LENGTH) { - return get_errno(); + return -EINVAL; } + ret.retVal = OK; + ptr = tSLInformation.pucTxCommandBuffer; args = (ptr + SIMPLE_LINK_HCI_CMND_TRANSPORT_HEADER_SIZE); @@ -539,11 +540,9 @@ int cc3000_gethostbyname_impl(char *hostname, uint16_t usNameLen, SimpleLinkWaitEvent(HCI_EVNT_BSD_GETHOSTBYNAME, &ret); - set_errno(ret.retVal); - (*((FAR long *)out_ip_addr)) = ret.outputAddress; - return ret.retVal; + return (int)ret.retVal; } #endif diff --git a/graphics/nxmu/nxmu_requestbkgd.c b/graphics/nxmu/nxmu_requestbkgd.c index 23f7748fc3..72485b6aaa 100644 --- a/graphics/nxmu/nxmu_requestbkgd.c +++ b/graphics/nxmu/nxmu_requestbkgd.c @@ -39,32 +39,13 @@ #include +#include #include #include #include #include "nxfe.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -92,12 +73,7 @@ void nxmu_requestbkgd(FAR struct nxfe_conn_s *conn, FAR const struct nx_callback_s *cb, FAR void *arg) { -#ifdef CONFIG_DEBUG_FEATURES - if (!conn || !be || !cb) - { - errno = EINVAL; - } -#endif + DEBUGASSERT(conn != NULL || be != NULL || cb != NULL); /* Set the client's callback vtable and and replace the server * connection with the clients connection. diff --git a/graphics/nxmu/nxmu_server.c b/graphics/nxmu/nxmu_server.c index 79cb140a3e..a2a2999abd 100644 --- a/graphics/nxmu/nxmu_server.c +++ b/graphics/nxmu/nxmu_server.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -53,22 +54,6 @@ #include "nxfe.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -190,7 +175,7 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, if (ret < 0) { gerr("ERROR: nxbe_configure failed: %d\n", -ret); - errno = -ret; + set_errno(-ret); return ERROR; } @@ -199,7 +184,7 @@ static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, if (ret < 0) { gerr("ERROR: nxbe_colormap failed: %d\n", -ret); - errno = -ret; + set_errno(-ret); return ERROR; } #endif /* CONFIG_FB_CMAP */ @@ -301,15 +286,7 @@ int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev) /* Initialization *********************************************************/ - /* Sanity checking */ - -#ifdef CONFIG_DEBUG_FEATURES - if (!mqname || !dev) - { - errno = EINVAL; - return ERROR; - } -#endif + DEBUGASSERT(mqname != NULL || dev != NULL); /* Initialize and configure the server */ diff --git a/graphics/vnc/server/vnc_negotiate.c b/graphics/vnc/server/vnc_negotiate.c index 31ee14322f..f685acb438 100644 --- a/graphics/vnc/server/vnc_negotiate.c +++ b/graphics/vnc/server/vnc_negotiate.c @@ -158,10 +158,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) nrecvd = psock_recv(&session->connect, session->inbuf, len, 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive protocol confirmation failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive protocol confirmation failed: %d\n", (int)nrecvd); + return (int)nrecvd; } else if (nrecvd == 0) { @@ -226,10 +224,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_selected_sectype_s), 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive SecurityType failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive SecurityType failed: %d\n", (int)nrecvd); + return (int)nrecvd; } else if (nrecvd == 0) { @@ -309,10 +305,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_clientinit_s), 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive ClientInit failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive ClientInit failed: %d\n", (int)nrecvd); + return (int)nrecvd; } else if (nrecvd == 0) { @@ -383,10 +377,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) sizeof(struct rfb_setpixelformat_s), 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive SetPixelFormat failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive SetPixelFormat failed: %d\n", (int)nrecvd); + return (int)nrecvd; } else if (nrecvd == 0) { @@ -430,10 +422,8 @@ int vnc_negotiate(FAR struct vnc_session_s *session) CONFIG_VNCSERVER_INBUFFER_SIZE, 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive SetEncodings failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive SetEncodings failed: %d\n", (int)nrecvd); + return (int)nrecvd; } else if (nrecvd == 0) { diff --git a/graphics/vnc/server/vnc_receiver.c b/graphics/vnc/server/vnc_receiver.c index 36d04428ab..82a7fbb421 100644 --- a/graphics/vnc/server/vnc_receiver.c +++ b/graphics/vnc/server/vnc_receiver.c @@ -104,10 +104,8 @@ int vnc_read_remainder(FAR struct vnc_session_s *session, size_t msglen, msglen - ntotal, 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive message failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive message failed: %d\n", (int)nrecvd); + return (int)recvd; } } @@ -155,10 +153,8 @@ int vnc_receiver(FAR struct vnc_session_s *session) &tv, sizeof(struct timeval)); if (ret < 0) { - errcode = get_errno(); - gerr("ERROR: Failed to disable receive timeout: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Failed to disable receive timeout: %d\n", ret); + return ret; } #endif @@ -174,10 +170,8 @@ int vnc_receiver(FAR struct vnc_session_s *session) nrecvd = psock_recv(&session->connect, session->inbuf, 1, 0); if (nrecvd < 0) { - errcode = get_errno(); - gerr("ERROR: Receive byte failed: %d\n", errcode); - DEBUGASSERT(errcode > 0); - return -errcode; + gerr("ERROR: Receive byte failed: %d\n", (int)nrecvd); + return (int)nrecvd; } /* A return value of zero means that the connection was gracefully