You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/12/31 08:38:46 UTC

[incubator-nuttx] branch master updated (c8db329 -> c647faa)

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from c8db329  BL602: Use sig mask instead of number for AHB swrst
     new 0defe43  OS internal function should indicate the error by return negative value
     new c647faa  Fix nxstyle warning

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/src/cxd56xx/cxd56_charger.c               |   6 +-
 arch/arm/src/cxd56xx/cxd56_ge2d.c                  |   3 +-
 arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c         |  12 +-
 arch/arm/src/cxd56xx/cxd56_scu.c                   |   8 +-
 arch/arm/src/cxd56xx/cxd56_sfc.c                   |  15 +-
 arch/arm/src/cxd56xx/cxd56_sysctl.c                |   4 -
 arch/arm/src/cxd56xx/cxd56_uart0.c                 |  21 +--
 arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c       |  12 +-
 .../arm/src/max326xx/common/max326_rtc_lowerhalf.c |  12 +-
 arch/arm/src/nrf52/nrf52_adc.c                     |   1 -
 arch/arm/src/stm32/stm32_rtc_lowerhalf.c           |  23 +--
 arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c       |  12 +-
 arch/z80/src/ez80/ez80_rtc_lowerhalf.c             |  12 +-
 drivers/leds/ws2812.c                              |   9 +-
 drivers/sensors/adt7320.c                          |  20 ++-
 drivers/sensors/adxl372.c                          |  86 +++++-----
 drivers/sensors/lsm330_spi.c                       | 174 ++++++++++++---------
 fs/fat/fs_fat32attrib.c                            |  14 +-
 fs/vfs/fs_eventfd.c                                |   2 +-
 mm/mm_heap/mm_sem.c                                |  29 +---
 20 files changed, 220 insertions(+), 255 deletions(-)


[incubator-nuttx] 02/02: Fix nxstyle warning

Posted by ag...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c647faa117b3ae3d46b8a08bc551a91fe2bc7122
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Dec 31 03:06:56 2020 +0800

    Fix nxstyle warning
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/arm/src/stm32/stm32_rtc_lowerhalf.c |  11 ++-
 drivers/sensors/adt7320.c                |  19 +++--
 drivers/sensors/adxl372.c                |  73 +++++++++-------
 drivers/sensors/lsm330_spi.c             | 140 +++++++++++++++++++------------
 4 files changed, 146 insertions(+), 97 deletions(-)

diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
index d617651..d16baae 100644
--- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
@@ -113,6 +113,7 @@ struct stm32_lowerhalf_s
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
+
 /* Prototypes for static methods in struct rtc_ops_s */
 
 static int stm32_rdtime(FAR struct rtc_lowerhalf_s *lower,
@@ -125,7 +126,7 @@ static bool stm32_havesettime(FAR struct rtc_lowerhalf_s *lower);
 static int stm32_setalarm(FAR struct rtc_lowerhalf_s *lower,
                           FAR const struct lower_setalarm_s *alarminfo);
 static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower,
-                             FAR const struct lower_setrelative_s *alarminfo);
+                            FAR const struct lower_setrelative_s *alarminfo);
 static int stm32_cancelalarm(FAR struct rtc_lowerhalf_s *lower,
                              int alarmid);
 static int stm32_rdalarm(FAR struct rtc_lowerhalf_s *lower,
@@ -134,13 +135,14 @@ static int stm32_rdalarm(FAR struct rtc_lowerhalf_s *lower,
 
 #ifdef CONFIG_RTC_PERIODIC
 static int stm32_setperiodic(FAR struct rtc_lowerhalf_s *lower,
-                             FAR const struct lower_setperiodic_s *alarminfo);
+                            FAR const struct lower_setperiodic_s *alarminfo);
 static int stm32_cancelperiodic(FAR struct rtc_lowerhalf_s *lower, int id);
 #endif
 
 /****************************************************************************
  * Private Data
  ****************************************************************************/
+
 /* STM32 RTC driver operations */
 
 static const struct rtc_ops_s g_rtc_ops =
@@ -786,8 +788,9 @@ static int stm32_rdalarm(FAR struct rtc_lowerhalf_s *lower,
  * Name: stm32_periodic_callback
  *
  * Description:
- *   This is the function that is called from the RTC driver when the periodic
- *   wakeup goes off.  It just invokes the upper half drivers callback.
+ *   This is the function that is called from the RTC driver when the
+ *   periodic wakeup goes off.  It just invokes the upper half drivers
+ *   callback.
  *
  * Input Parameters:
  *   None
diff --git a/drivers/sensors/adt7320.c b/drivers/sensors/adt7320.c
index b3a84f1..2bcf15f 100644
--- a/drivers/sensors/adt7320.c
+++ b/drivers/sensors/adt7320.c
@@ -367,7 +367,8 @@ static int adt7320_close(FAR struct file *filep)
  * Name: adt7320_read
  ****************************************************************************/
 
-static ssize_t adt7320_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
+static ssize_t adt7320_read(FAR struct file *filep,
+                            FAR char *buffer, size_t buflen)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct adt7320_dev_s *priv = inode->i_private;
@@ -524,7 +525,8 @@ static int adt7320_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
       /* Write to the critical temperature register. Arg: b16_t value */
 
       case SNIOC_WRITETCRIT:
-        adt7320_write_reg16(priv, ADT7320_TCRIT_REG, b16tob8((b16_t)arg) >> 1);
+        adt7320_write_reg16(priv, ADT7320_TCRIT_REG,
+                            b16tob8((b16_t)arg) >> 1);
         break;
 
       /* Read the hysteresis temperature register. Arg: b16_t* */
@@ -560,7 +562,8 @@ static int adt7320_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
       /* Write to the low temperature register. Arg: b16_t value */
 
       case SNIOC_WRITETLOW:
-        adt7320_write_reg16(priv, ADT7320_TLOW_REG, b16tob8((b16_t)arg) >> 1);
+        adt7320_write_reg16(priv, ADT7320_TLOW_REG,
+                            b16tob8((b16_t)arg) >> 1);
         break;
 
       /* Read the high temperature register. Arg: b16_t* pointer */
@@ -578,7 +581,8 @@ static int adt7320_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
       /* Write to the high temperature register. Arg: b16_t value */
 
       case SNIOC_WRITETHIGH:
-        adt7320_write_reg16(priv, ADT7320_THIGH_REG, b16tob8((b16_t)arg) >> 1);
+        adt7320_write_reg16(priv, ADT7320_THIGH_REG,
+                            b16tob8((b16_t)arg) >> 1);
         break;
 
       default:
@@ -602,7 +606,7 @@ static int adt7320_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
  *
  * Input Parameters:
  *   devpath - The full path to the driver to register. E.g., "/dev/temp0"
- *   spi - An instance of the SPI interface to use to communicate with ADT7320
+ *   spi - An instance of the SPI bus to use to communicate with ADT7320
  *   spidev - The SPI device number used to select the correct CS line
  *
  * Returned Value:
@@ -610,7 +614,8 @@ static int adt7320_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
  *
  ****************************************************************************/
 
-int adt7320_register(FAR const char *devpath, FAR struct spi_dev_s *spi, int spidev)
+int adt7320_register(FAR const char *devpath,
+                     FAR struct spi_dev_s *spi, int spidev)
 {
   FAR struct adt7320_dev_s *priv;
   int ret;
@@ -621,7 +626,7 @@ int adt7320_register(FAR const char *devpath, FAR struct spi_dev_s *spi, int spi
 
   /* Initialize the ADT7320 device structure */
 
-  priv = (FAR struct adt7320_dev_s *)kmm_malloc(sizeof(struct adt7320_dev_s));
+  priv = kmm_malloc(sizeof(struct adt7320_dev_s));
   if (priv == NULL)
     {
       snerr("ERROR: Failed to allocate instance\n");
diff --git a/drivers/sensors/adxl372.c b/drivers/sensors/adxl372.c
index 8343347..3381118 100644
--- a/drivers/sensors/adxl372.c
+++ b/drivers/sensors/adxl372.c
@@ -32,7 +32,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- *****************************************************************************/
+ ****************************************************************************/
 
 /****************************************************************************
  * Included Files
@@ -114,17 +114,17 @@ static off_t    adxl372_seek(FAR struct file *filep, off_t offset,
 static int      adxl372_ioctl(FAR struct file *filep, int cmd,
                               unsigned long arg);
 
-static int      adxl372_dvr_open(FAR void *instance_handle, int32_t arg);
-static int      adxl372_dvr_close(FAR void *instance_handle, int32_t arg);
-static ssize_t  adxl372_dvr_read(FAR void *instance_handle,
+static int      adxl372_dvr_open(FAR void *instance, int32_t arg);
+static int      adxl372_dvr_close(FAR void *instance, int32_t arg);
+static ssize_t  adxl372_dvr_read(FAR void *instance,
                                  FAR char *buffer, size_t buflen);
-static ssize_t  adxl372_dvr_write(FAR void *instance_handle,
+static ssize_t  adxl372_dvr_write(FAR void *instance,
                                   FAR const char *buffer, size_t buflen);
-static off_t    adxl372_dvr_seek(FAR void *instance_handle, off_t offset,
+static off_t    adxl372_dvr_seek(FAR void *instance, off_t offset,
                                  int whence);
-static int      adxl372_dvr_ioctl(FAR void *instance_handle, int cmd,
+static int      adxl372_dvr_ioctl(FAR void *instance, int cmd,
                                   unsigned long arg);
-static void     adxl372_dvr_exchange(FAR void *instance_handle,
+static void     adxl372_dvr_exchange(FAR void *instance,
                                      FAR const void *txbuffer,
                                      FAR void *rxbuffer, size_t nwords);
 
@@ -231,7 +231,9 @@ static uint8_t adxl372_read_register(FAR struct adxl372_dev_s *dev,
 {
   uint8_t reg_data;
 
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -261,16 +263,18 @@ static uint8_t adxl372_read_register(FAR struct adxl372_dev_s *dev,
   return reg_data;
 }
 
-/******************************************************************************
+/****************************************************************************
  * Name: adxl372_read_registerblk
- ******************************************************************************/
+ ****************************************************************************/
 
 static void adxl372_read_registerblk(FAR struct adxl372_dev_s *dev,
                                      uint8_t reg_addr,
                                      FAR uint8_t *reg_data,
                                      uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -308,7 +312,9 @@ static void adxl372_read_registerblk(FAR struct adxl372_dev_s *dev,
 static void adxl372_write_register(FAR struct adxl372_dev_s *dev,
                                    uint8_t reg_addr, uint8_t reg_data)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -345,7 +351,9 @@ static void adxl372_write_registerblk(FAR struct adxl372_dev_s *dev,
                                       FAR uint8_t *reg_data,
                                       uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -448,9 +456,9 @@ static uint32_t adxl372_read_id(FAR struct adxl372_dev_s *dev)
  * Name: adxl372_dvr_open
  ****************************************************************************/
 
-static int adxl372_dvr_open(FAR void *instance_handle, int32_t arg)
+static int adxl372_dvr_open(FAR void *instance, int32_t arg)
 {
-  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance_handle;
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
   FAR struct adxl372_reg_pair_s *initp;
   uint32_t pnpid;
   int sz;
@@ -541,14 +549,14 @@ static int adxl372_dvr_open(FAR void *instance_handle, int32_t arg)
  * Name: adxl372_dvr_close
  ****************************************************************************/
 
-static int adxl372_dvr_close(FAR void *instance_handle, int32_t arg)
+static int adxl372_dvr_close(FAR void *instance, int32_t arg)
 {
-  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance_handle;
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
 
   DEBUGASSERT(priv != NULL);
   UNUSED(arg);
 
-  /* Perform a reset to place the sensor in standby mode.*/
+  /* Perform a reset to place the sensor in standby mode. */
 
   adxl372_reset(priv);
 
@@ -562,15 +570,16 @@ static int adxl372_dvr_close(FAR void *instance_handle, int32_t arg)
  * Name: adxl372_dvr_read
  ****************************************************************************/
 
-static ssize_t adxl372_dvr_read(FAR void *instance_handle, FAR char *buffer,
+static ssize_t adxl372_dvr_read(FAR void *instance, FAR char *buffer,
                                 size_t buflen)
 {
-  FAR struct adxl372_dev_s *priv = ((FAR struct adxl372_dev_s *)instance_handle);
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
   union
   {
     int16_t d16;
     char    d8[2];
   } un;
+
   FAR char *p1;
   FAR char *p2;
   int i;
@@ -602,10 +611,10 @@ static ssize_t adxl372_dvr_read(FAR void *instance_handle, FAR char *buffer,
  * Name: adxl372_dvr_write
  ****************************************************************************/
 
-static ssize_t adxl372_dvr_write(FAR void *instance_handle,
+static ssize_t adxl372_dvr_write(FAR void *instance,
                                  FAR const char *buffer, size_t buflen)
 {
-  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance_handle;
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
 
   DEBUGASSERT(priv != NULL);
 
@@ -624,11 +633,11 @@ static ssize_t adxl372_dvr_write(FAR void *instance_handle,
  * Name: adxl372_dvr_seek
  ****************************************************************************/
 
-static off_t adxl372_dvr_seek(FAR void *instance_handle, off_t offset,
+static off_t adxl372_dvr_seek(FAR void *instance, off_t offset,
                               int whence)
 {
   off_t reg;
-  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance_handle;
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
 
   DEBUGASSERT(priv != NULL);
 
@@ -668,7 +677,7 @@ static off_t adxl372_dvr_seek(FAR void *instance_handle, off_t offset,
  * Name: adxl372_dvr_ioctl
  ****************************************************************************/
 
-static int adxl372_dvr_ioctl(FAR void *instance_handle, int cmd,
+static int adxl372_dvr_ioctl(FAR void *instance, int cmd,
                              unsigned long arg)
 {
   int ret = OK;
@@ -693,7 +702,7 @@ static int adxl372_dvr_ioctl(FAR void *instance_handle, int cmd,
  *   Exchange a block of data on SPI using DMA
  *
  * Input Parameters:
- *   instance_handle - Pointer to struct adxl372_dev_s.
+ *   instance - Pointer to struct adxl372_dev_s.
  *   txbuffer - A pointer to the buffer of data to be sent
  *   rxbuffer - A pointer to a buffer in which to receive data
  *   nwords   - the length of data to be exchanged in units of words.
@@ -707,14 +716,16 @@ static int adxl372_dvr_ioctl(FAR void *instance_handle, int cmd,
  *
  ****************************************************************************/
 
-static void adxl372_dvr_exchange(FAR void *instance_handle,
+static void adxl372_dvr_exchange(FAR void *instance,
                                  FAR const void *txbuffer,
                                  FAR void *rxbuffer, size_t nwords)
 {
-  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance_handle;
+  FAR struct adxl372_dev_s *priv = (FAR struct adxl372_dev_s *)instance;
   FAR struct spi_dev_s *spi = priv->spi;
 
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(spi, true);
 
@@ -852,7 +863,7 @@ int adxl372_register(FAR const char *devpath,
 
   /* Initialize the ADXL372 accelerometer device structure. */
 
-  priv = (FAR struct adxl372_dev_s *)kmm_malloc(sizeof(struct adxl372_dev_s));
+  priv = kmm_malloc(sizeof(struct adxl372_dev_s));
   if (priv == NULL)
     {
       snerr("ERROR: Failed to allocate accelerometer instance\n");
diff --git a/drivers/sensors/lsm330_spi.c b/drivers/sensors/lsm330_spi.c
index 6243eb6..91f1dc6 100644
--- a/drivers/sensors/lsm330_spi.c
+++ b/drivers/sensors/lsm330_spi.c
@@ -77,13 +77,13 @@ struct lsm330_dev_s
   FAR struct spi_dev_s *spi;          /* Pointer to the SPI instance */
   FAR struct lsm330_config_s *config; /* Pointer to the configuration of the
                                        * LSM330 sensor */
-  sem_t devicesem;                /* Manages exclusive access to this
-                                   * device */
-  sem_t datasem;                  /* Manages exclusive access to this
-                                   * structure */
-  struct sensor_data_s data;      /* The data as measured by the sensor */
-  uint8_t seek_address;           /* Current device address. */
-  uint8_t readonly;               /* 0 = writing to the device in enabled */
+  sem_t devicesem;                    /* Manages exclusive access to this
+                                       * device */
+  sem_t datasem;                      /* Manages exclusive access to this
+                                       * structure */
+  struct sensor_data_s data;          /* The data as measured by the sensor */
+  uint8_t seek_address;               /* Current device address. */
+  uint8_t readonly;                   /* 0 = writing to the device in enabled */
 };
 
 /****************************************************************************
@@ -241,56 +241,63 @@ static struct lsm330_dev_s *g_lsm330g_list = NULL;
 
 static struct lsm330_reg_pair_s g_default_lsm330_aclcr_values[] =
 {
-  /* CR5 ODR[3:0]        BDU ZEN YEN XEN             */
-  /*     0000=Off         0   0   0   0=all disabled */
+  /* CR5 ODR[3:0]        BDU ZEN YEN XEN
+   *     0000=Off         0   0   0   0=all disabled
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG5,
     .value = 0x00
   },
 
-  /* CR6 BW[2:1]   FSCALE[2:0] - -  SIM       */
-  /*     00=800Hz   10 0=16g   0 0  0=4-wire  */
+  /* CR6 BW[2:1]   FSCALE[2:0] - -  SIM
+   *     00=800Hz   10 0=16g   0 0  0=4-wire
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG6,
     .value = 0x20
   },
 
-  /* CR7 BOOT FIFO_EN WTM_EN ADD_INC P1_MTY P1_WTM P1_OVR WTM_EN*/
-  /*      0      0      0      1       0      0      0       0  */
+  /* CR7 BOOT FIFO_EN WTM_EN ADD_INC P1_MTY P1_WTM P1_OVR WTM_EN
+   *      0      0      0      1       0      0      0       0
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG7,
     .value = 0x10
   },
 
-  /* CR2 HYST1 -  SM1_PIN - - SM1_EN */
-  /*     000   0     0    0 0    0   */
+  /* CR2 HYST1 -  SM1_PIN - - SM1_EN
+   *     000   0     0    0 0    0
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG2,
     .value = 0x00
   },
 
-  /* CR3 HYST2 -  SM2_PIN - - SM2_EN */
-  /*     000   0     0    0 0    0   */
+  /* CR3 HYST2 -  SM2_PIN - - SM2_EN
+   *     000   0     0    0 0    0
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG3,
     .value = 0x00
   },
 
-  /* CR4 DR_EN IEA IEL INT2_EN INT1_EN  VFILT STRT */
-  /*       1    1   0     0       0       0    0   */
+  /* CR4 DR_EN IEA IEL INT2_EN INT1_EN  VFILT STRT
+   *       1    1   0     0       0       0    0
+   */
 
   {
     .addr  = LSM330_ACL_CTRL_REG4,
     .value = 0xc0
   },
 
-  /* CR5 ODR[3:0]        BDU ZEN YEN XEN            */
-  /*     1001=1600Hz      1   1   1   1=all enabled */
+  /* CR5 ODR[3:0]        BDU ZEN YEN XEN
+   *     1001=1600Hz      1   1   1   1=all enabled
+  */
 
   {
     .addr  = LSM330_ACL_CTRL_REG5,
@@ -311,40 +318,45 @@ static struct lsm330_reg_pair_s g_default_lsm330_aclcr_values[] =
 
 static struct lsm330_reg_pair_s g_default_lsm330_gyrocr_values[] =
 {
-  /* CR1  DR[1:0]   BW[1:0]    PD Zen Xen Yen  */
-  /*      1 1=760Hz 1 1=100Hz  1   1   1   1   */
+  /* CR1  DR[1:0]   BW[1:0]    PD Zen Xen Yen
+   *      1 1=760Hz 1 1=100Hz  1   1   1   1
+   */
 
   {
     .addr =  LSM330_GYRO_CTRL_REG1,
     .value = 0xff
   },
 
-  /* CR2 EXTRen LVLen HPM[1:0]  HPCF[3:0]     */
-  /*      0      0    00=Normal xxxx  Default */
+  /* CR2 EXTRen LVLen HPM[1:0]  HPCF[3:0]
+   *      0      0    00=Normal xxxx  Default
+   */
 
   {
     .addr  = LSM330_GYRO_CTRL_REG2,
     .value = 0x00
   },
 
-  /* CR3 I1_Int1 I1_Boot H_Lactive PP_OD I2_DRDY I2_WTM I2_ORun I2_Empty */
-  /*       0        0       0        0      0      0      0        0     */
+  /* CR3 I1_Int1 I1_Boot H_Lactive PP_OD I2_DRDY I2_WTM I2_ORun I2_Empty
+   *       0        0       0        0      0      0      0        0
+   */
 
   {
     .addr  = LSM330_GYRO_CTRL_REG3,
     .value = 0x00
   },
 
-  /* CR4 BDU BLE FS[1:0]   0 0 0 SIM      */
-  /*      1   0  01=500dps 0 0 0 0=4-wire */
+  /* CR4 BDU BLE FS[1:0]   0 0 0 SIM
+   *      1   0  01=500dps 0 0 0 0=4-wire
+   */
 
   {
     .addr  = LSM330_GYRO_CTRL_REG4,
     .value = 0x90
   },
 
-  /* CR5 BOOT FIFO_EN  - HPen INT1_Sel[1:0] Out_Sel[1:0] */
-  /*      0     0      0  0    00=LPF1        00=LPF1    */
+  /* CR5 BOOT FIFO_EN  - HPen INT1_Sel[1:0] Out_Sel[1:0]
+   *      0     0      0  0    00=LPF1        00=LPF1
+   */
 
   {
     .addr  = LSM330_GYRO_CTRL_REG5,
@@ -352,7 +364,7 @@ static struct lsm330_reg_pair_s g_default_lsm330_gyrocr_values[] =
   }
 };
 
-/******************************************************************************
+/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -365,7 +377,9 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
 {
   uint8_t reg_data;
 
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -396,16 +410,18 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
   return reg_data;
 }
 
-/******************************************************************************
+/****************************************************************************
  * Name: lsm330_read_acl_registerblk
- ******************************************************************************/
+ ****************************************************************************/
 
 static void lsm330_read_acl_registerblk(FAR struct lsm330_dev_s *dev,
                                         uint8_t reg_addr,
                                         FAR uint8_t *reg_data,
                                         uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -438,16 +454,18 @@ static void lsm330_read_acl_registerblk(FAR struct lsm330_dev_s *dev,
   SPI_LOCK(dev->spi, false);
 }
 
-/******************************************************************************
+/****************************************************************************
  * Name: lsm330_read_gyro_registerblk
- ******************************************************************************/
+ ****************************************************************************/
 
 static void lsm330_read_gyro_registerblk(FAR struct lsm330_dev_s *dev,
                                          uint8_t reg_addr,
                                          FAR uint8_t *reg_data,
                                          uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -489,7 +507,9 @@ static void lsm330_write_register(FAR struct lsm330_dev_s *dev,
                                   uint8_t reg_addr,
                                   uint8_t reg_data)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -528,7 +548,9 @@ static void lsm330_write_acl_registerblk(FAR struct lsm330_dev_s *dev,
                                          FAR uint8_t *reg_data,
                                          uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -570,7 +592,9 @@ static void lsm330_write_gyro_registerblk(FAR struct lsm330_dev_s *dev,
                                           FAR uint8_t *reg_data,
                                           uint8_t xfercnt)
 {
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(dev->spi, true);
 
@@ -685,8 +709,8 @@ static int lsm330acl_dvr_open(FAR void *instance_handle, int32_t arg)
     {
       /* Made info log level to permit open being used as a device probe. */
 
-      snwarn("INFO: "
-             "Device ID (0x%02X) does not match expected LSM330 Acl ID (0x%02).\n",
+      snwarn("INFO: Device ID (0x%02X) "
+             "does not match expected LSM330 Acl ID (0x%02).\n",
              reg_content, LSM330_ACL_IDREG_VALUE);
 
       priv->readonly = true;
@@ -775,10 +799,12 @@ static int lsm330gyro_dvr_open(FAR void *instance_handle, int32_t arg)
 
   if (reg_content != LSM330_GYRO_IDREG_VALUE)
     {
-      /* Made warning log level to permit open being used as a device probe. */
+      /* Made warning log level to permit open being used as
+       * a device probe.
+       */
 
-      snwarn("INFO: "
-             "Device ID (0x%02X) does not match expected LSM330 Gyro ID (0x%02).\n",
+      snwarn("INFO: Device ID (0x%02X) "
+             "does not match expected LSM330 Gyro ID (0x%02).\n",
              reg_content, LSM330_GYRO_IDREG_VALUE);
 
       priv->readonly = true;
@@ -834,7 +860,7 @@ static int lsm330gyro_dvr_open(FAR void *instance_handle, int32_t arg)
 
 /****************************************************************************
  * Name: lsm330acl_dvr_close
- ******************************************************************************/
+ ****************************************************************************/
 
 static int lsm330acl_dvr_close(FAR void *instance_handle, int32_t arg)
 {
@@ -855,7 +881,7 @@ static int lsm330acl_dvr_close(FAR void *instance_handle, int32_t arg)
 
 /****************************************************************************
  * Name: lsm330gyro_dvr_close
- ******************************************************************************/
+ ****************************************************************************/
 
 static int lsm330gyro_dvr_close(FAR void *instance_handle, int32_t arg)
 {
@@ -896,8 +922,8 @@ static ssize_t lsm330acl_dvr_read(FAR void *instance_handle,
  * Name: lsm330gyro_dvr_read
  ****************************************************************************/
 
-static ssize_t lsm330gyro_dvr_read(FAR void *instance_handle, FAR char *buffer,
-                           size_t buflen)
+static ssize_t lsm330gyro_dvr_read(FAR void *instance_handle,
+                                   FAR char *buffer, size_t buflen)
 {
   FAR struct lsm330_dev_s *priv = (FAR struct lsm330_dev_s *)instance_handle;
 
@@ -954,7 +980,8 @@ static ssize_t lsm330gyro_dvr_write(FAR void *instance_handle,
  * Name: lsm330acl_dvr_seek
  ****************************************************************************/
 
-static off_t lsm330acl_dvr_seek(FAR void *instance_handle, off_t offset, int whence)
+static off_t lsm330acl_dvr_seek(FAR void *instance_handle,
+                                off_t offset, int whence)
 {
   FAR struct lsm330_dev_s *priv = (FAR struct lsm330_dev_s *)instance_handle;
   off_t reg;
@@ -1078,7 +1105,7 @@ static int lsm330_dvr_ioctl(FAR void *instance_handle, int cmd,
  * Returned Value:
  *   None
  *
- ******************************************************************************/
+ ****************************************************************************/
 
 static void lsm330_dvr_exchange(FAR void *instance_handle,
                                 FAR const void *txbuffer,
@@ -1089,7 +1116,9 @@ static void lsm330_dvr_exchange(FAR void *instance_handle,
 
   sninfo("In lsm330_dvr_exchange: Handle=0x%08X\n", instance_handle);
 
-  /* Lock the SPI bus so that only one device can access it at the same time */
+  /* Lock the SPI bus so that only one device can access it
+   * at the same time
+   */
 
   SPI_LOCK(spi, true);
 
@@ -1241,7 +1270,8 @@ static off_t lsm330acl_seek(FAR struct file *filep, off_t offset, int whence)
  * Name: lsm330gyro_seek
  ****************************************************************************/
 
-static off_t lsm330gyro_seek(FAR struct file *filep, off_t offset, int whence)
+static off_t lsm330gyro_seek(FAR struct file *filep,
+                             off_t offset, int whence)
 {
   FAR struct inode *inode = filep->f_inode;
   FAR struct lsm330_dev_s *priv = inode->i_private;


[incubator-nuttx] 01/02: OS internal function should indicate the error by return negative value

Posted by ag...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 0defe43282ace0be68b9119e743a4a7c6b200e54
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat May 2 22:05:41 2020 +0800

    OS internal function should indicate the error by return negative value
    
    instead to change errno value by calling set_errno
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 arch/arm/src/cxd56xx/cxd56_charger.c               |  6 ++--
 arch/arm/src/cxd56xx/cxd56_ge2d.c                  |  3 +-
 arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c         | 12 ++++----
 arch/arm/src/cxd56xx/cxd56_scu.c                   |  8 +----
 arch/arm/src/cxd56xx/cxd56_sfc.c                   | 15 ++++------
 arch/arm/src/cxd56xx/cxd56_sysctl.c                |  4 ---
 arch/arm/src/cxd56xx/cxd56_uart0.c                 | 21 ++-----------
 arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c       | 12 ++++----
 .../arm/src/max326xx/common/max326_rtc_lowerhalf.c | 12 ++++----
 arch/arm/src/nrf52/nrf52_adc.c                     |  1 -
 arch/arm/src/stm32/stm32_rtc_lowerhalf.c           | 12 ++++----
 arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c       | 12 ++++----
 arch/z80/src/ez80/ez80_rtc_lowerhalf.c             | 12 ++++----
 drivers/leds/ws2812.c                              |  9 ++----
 drivers/sensors/adt7320.c                          |  1 -
 drivers/sensors/adxl372.c                          | 13 +++------
 drivers/sensors/lsm330_spi.c                       | 34 +++++++---------------
 fs/fat/fs_fat32attrib.c                            | 14 ++++-----
 fs/vfs/fs_eventfd.c                                |  2 +-
 mm/mm_heap/mm_sem.c                                | 29 ++----------------
 20 files changed, 74 insertions(+), 158 deletions(-)

diff --git a/arch/arm/src/cxd56xx/cxd56_charger.c b/arch/arm/src/cxd56xx/cxd56_charger.c
index 7da837e..5018052 100644
--- a/arch/arm/src/cxd56xx/cxd56_charger.c
+++ b/arch/arm/src/cxd56xx/cxd56_charger.c
@@ -625,8 +625,7 @@ static int charger_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
             }
           else
             {
-              set_errno(EINVAL);
-              ret = -1;
+              ret = -EINVAL;
             }
         }
         break;
@@ -641,8 +640,7 @@ static int charger_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
             }
           else
             {
-              set_errno(EINVAL);
-              ret = -1;
+              ret = -EINVAL;
             }
         }
         break;
diff --git a/arch/arm/src/cxd56xx/cxd56_ge2d.c b/arch/arm/src/cxd56xx/cxd56_ge2d.c
index bdacfe1..b26e645 100644
--- a/arch/arm/src/cxd56xx/cxd56_ge2d.c
+++ b/arch/arm/src/cxd56xx/cxd56_ge2d.c
@@ -154,8 +154,7 @@ static ssize_t ge2d_write(FAR struct file *filep,
 
   if (((uintptr_t)buffer & 0xf) != 0)
     {
-      set_errno(EINVAL);
-      return 0;
+      return -EINVAL;
     }
 
   /* Get exclusive access */
diff --git a/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c b/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
index 9918364..f327aef 100644
--- a/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
+++ b/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
@@ -219,7 +219,7 @@ static int cxd56_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -229,15 +229,15 @@ static int cxd56_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 
 #else
   time_t timer;
diff --git a/arch/arm/src/cxd56xx/cxd56_scu.c b/arch/arm/src/cxd56xx/cxd56_scu.c
index 5c76a99..514b8e5 100644
--- a/arch/arm/src/cxd56xx/cxd56_scu.c
+++ b/arch/arm/src/cxd56xx/cxd56_scu.c
@@ -3159,8 +3159,7 @@ int seq_ioctl(FAR struct seq_s *seq, int fifoid, int cmd, unsigned long arg)
 
   if (fifoid < 0 || fifoid > 2)
     {
-      set_errno(-EINVAL);
-      return -1;
+      return -EINVAL;
     }
 
   scuinfo("cmd = %04x, arg = %08x\n", cmd, arg);
@@ -3406,11 +3405,6 @@ int seq_ioctl(FAR struct seq_s *seq, int fifoid, int cmd, unsigned long arg)
         break;
     }
 
-  if (ret < 0)
-    {
-      set_errno(-ret);
-    }
-
   return ret;
 }
 
diff --git a/arch/arm/src/cxd56xx/cxd56_sfc.c b/arch/arm/src/cxd56xx/cxd56_sfc.c
index 6d10d7b..5cc704e 100644
--- a/arch/arm/src/cxd56xx/cxd56_sfc.c
+++ b/arch/arm/src/cxd56xx/cxd56_sfc.c
@@ -103,8 +103,7 @@ static int cxd56_erase(FAR struct mtd_dev_s *dev, off_t startblock,
       ret = fw_fm_rawerasesector(startblock + i);
       if (ret < 0)
         {
-          set_errno(-ret);
-          return ERROR;
+          return ret;
         }
     }
 
@@ -122,8 +121,7 @@ static ssize_t cxd56_bread(FAR struct mtd_dev_s *dev, off_t startblock,
                       nblocks << PAGE_SHIFT);
   if (ret < 0)
     {
-      set_errno(-ret);
-      return ERROR;
+      return ret;
     }
 
   return nblocks;
@@ -145,8 +143,7 @@ static ssize_t cxd56_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
 #endif
   if (ret < 0)
     {
-      set_errno(-ret);
-      return ERROR;
+      return ret;
     }
 
   return nblocks;
@@ -162,8 +159,7 @@ static ssize_t cxd56_read(FAR struct mtd_dev_s *dev, off_t offset,
   ret = fw_fm_rawread(offset, buffer, nbytes);
   if (ret < 0)
     {
-      set_errno(-ret);
-      return ERROR;
+      return ret;
     }
 
   return nbytes;
@@ -184,8 +180,7 @@ static ssize_t cxd56_write(FAR struct mtd_dev_s *dev, off_t offset,
 #endif
   if (ret < 0)
     {
-      set_errno(-ret);
-      return ERROR;
+      return ret;
     }
 
   return nbytes;
diff --git a/arch/arm/src/cxd56xx/cxd56_sysctl.c b/arch/arm/src/cxd56xx/cxd56_sysctl.c
index 6adff53..4ab778c 100644
--- a/arch/arm/src/cxd56xx/cxd56_sysctl.c
+++ b/arch/arm/src/cxd56xx/cxd56_sysctl.c
@@ -104,10 +104,6 @@ static int sysctl_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
         {
           _err("cmd %x(%lx)\n", cmd, arg);
           ret = cxd56_sysctlcmd(cmd & 0xff, arg);
-          if (ret)
-            {
-              set_errno(ret);
-            }
         }
     }
 
diff --git a/arch/arm/src/cxd56xx/cxd56_uart0.c b/arch/arm/src/cxd56xx/cxd56_uart0.c
index 848d1dc..feb8e5b 100644
--- a/arch/arm/src/cxd56xx/cxd56_uart0.c
+++ b/arch/arm/src/cxd56xx/cxd56_uart0.c
@@ -162,8 +162,7 @@ static int uart0_open(FAR struct file *filep)
   ret = fw_pd_uartinit(0);
   if (ret < 0)
     {
-      set_errno(EFAULT);
-      return ERROR;
+      return -EFAULT;
     }
 
   /* 0 = 5bit, 1 = 6bit, 2 = 7bit, 3 = 8bit */
@@ -191,16 +190,14 @@ static int uart0_open(FAR struct file *filep)
   if (ret < 0)
     {
       fw_pd_uartuninit(0);
-      set_errno(EINVAL);
-      return ERROR;
+      return -EINVAL;
     }
 
   ret = fw_pd_uartenable(0);
   if (ret < 0)
     {
       fw_pd_uartuninit(0);
-      set_errno(EFAULT);
-      return ERROR;
+      return -EFAULT;
     }
 
   return OK;
@@ -247,12 +244,6 @@ static ssize_t uart0_read(FAR struct file *filep,
 
   uart0_semgive(&g_lock);
 
-  if (ret < 0)
-    {
-      set_errno(-ret);
-      ret = 0; /* Receive no data */
-    }
-
   return (ssize_t)ret;
 }
 
@@ -272,12 +263,6 @@ static ssize_t uart0_write(FAR struct file *filep,
 
   uart0_semgive(&g_lock);
 
-  if (ret < 0)
-    {
-      set_errno(-ret);
-      ret = 0;
-    }
-
   return (ssize_t)ret;
 }
 
diff --git a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
index d6fc27b..8a52599 100644
--- a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
+++ b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
@@ -224,7 +224,7 @@ static int kinetis_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -234,15 +234,15 @@ static int kinetis_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 
 #else
   time_t timer;
diff --git a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
index d51102a..fceea81 100644
--- a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
+++ b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
@@ -255,7 +255,7 @@ static int max326_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -265,15 +265,15 @@ static int max326_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 
 #else
   time_t timer;
diff --git a/arch/arm/src/nrf52/nrf52_adc.c b/arch/arm/src/nrf52/nrf52_adc.c
index 1b82fdf..f805e9a 100644
--- a/arch/arm/src/nrf52/nrf52_adc.c
+++ b/arch/arm/src/nrf52/nrf52_adc.c
@@ -926,7 +926,6 @@ struct adc_dev_s *nrf52_adcinitialize(
   if (channels > 1)
     {
       aerr("ERORR: timer trigger works only for 1 channel!\n");
-      set_errno(-EINVAL);
       goto errout;
     }
 #endif
diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
index 868a080..d617651 100644
--- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
@@ -286,7 +286,7 @@ static int stm32_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -296,15 +296,15 @@ static int stm32_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 
 #else
   time_t timer;
diff --git a/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c b/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
index d878fd3..50481aa 100644
--- a/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
+++ b/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
@@ -247,7 +247,7 @@ static int rx65n_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -257,16 +257,16 @@ static int rx65n_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 #endif
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 }
 
 /****************************************************************************
diff --git a/arch/z80/src/ez80/ez80_rtc_lowerhalf.c b/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
index 9729866..a40cc23 100644
--- a/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
+++ b/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
@@ -223,7 +223,7 @@ static int ez80_rdtime(FAR struct rtc_lowerhalf_s *lower,
   ret = up_rtc_gettime(&ts);
   if (ret < 0)
     {
-      goto errout_with_errno;
+      goto errout;
     }
 
   /* Convert the one second epoch time to a struct tm.  This operation
@@ -233,15 +233,15 @@ static int ez80_rdtime(FAR struct rtc_lowerhalf_s *lower,
 
   if (!gmtime_r(&ts.tv_sec, (FAR struct tm *)rtctime))
     {
-      goto errout_with_errno;
+      ret = -get_errno();
+      goto errout;
     }
 
   return OK;
 
-errout_with_errno:
-  ret = get_errno();
-  DEBUGASSERT(ret > 0);
-  return -ret;
+errout:
+  DEBUGASSERT(ret < 0);
+  return ret;
 
 #else
   time_t timer;
diff --git a/drivers/leds/ws2812.c b/drivers/leds/ws2812.c
index 867a183..8c1edd9 100644
--- a/drivers/leds/ws2812.c
+++ b/drivers/leds/ws2812.c
@@ -267,8 +267,7 @@ static ssize_t ws2812_write(FAR struct file *filep, FAR const char *buffer,
   if (buffer == NULL)
     {
       lederr("ERROR: Buffer is null\n");
-      set_errno(EINVAL);
-      return -1;
+      return -EINVAL;
     }
 
   /* We need at least one LED, so 1 byte */
@@ -276,15 +275,13 @@ static ssize_t ws2812_write(FAR struct file *filep, FAR const char *buffer,
   if (buflen < 1)
     {
       lederr("ERROR: You need to control at least 1 LED!\n");
-      set_errno(EINVAL);
-      return -1;
+      return -EINVAL;
     }
 
   if ((buflen % WS2812_RW_PIXEL_SIZE) != 0)
     {
       lederr("ERROR: LED values must be 24bit packed in 32bit\n");
-      set_errno(EINVAL);
-      return -1;
+      return -EINVAL;
     }
 
   nxsem_wait(&priv->exclsem);
diff --git a/drivers/sensors/adt7320.c b/drivers/sensors/adt7320.c
index c50dfc4..b3a84f1 100644
--- a/drivers/sensors/adt7320.c
+++ b/drivers/sensors/adt7320.c
@@ -344,7 +344,6 @@ static int adt7320_open(FAR struct file *filep)
 
   if (adt7320_read_reg8(priv, ADT7320_ID_REG) != ADT7320_ID)
     {
-      set_errno(ENODEV);
       return -ENODEV;
     }
 
diff --git a/drivers/sensors/adxl372.c b/drivers/sensors/adxl372.c
index 003023c..8343347 100644
--- a/drivers/sensors/adxl372.c
+++ b/drivers/sensors/adxl372.c
@@ -487,7 +487,6 @@ static int adxl372_dvr_open(FAR void *instance_handle, int32_t arg)
       snwarn("ERROR: Invalid ADXL372_ID = 0x%08x\n", pnpid);
 
       priv->readonly = true;
-      set_errno(ENODEV);
     }
   else /* ID matches */
     {
@@ -612,8 +611,7 @@ static ssize_t adxl372_dvr_write(FAR void *instance_handle,
 
   if (priv->readonly)
     {
-      set_errno(EROFS);
-      return -1;
+      return -EROFS;
     }
 
   adxl372_write_registerblk(priv, priv->seek_address, (uint8_t *)buffer,
@@ -640,8 +638,7 @@ static off_t adxl372_dvr_seek(FAR void *instance_handle, off_t offset,
         reg = priv->seek_address + offset;
         if (0 > reg || reg > ADXL372_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = reg;
@@ -654,16 +651,14 @@ static off_t adxl372_dvr_seek(FAR void *instance_handle, off_t offset,
       case SEEK_SET:  /* Seek to designated address */
         if (0 > offset || offset > ADXL372_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = offset;
         break;
 
       default:        /* invalid whence */
-        set_errno(-EINVAL);
-        return -1;
+        return -EINVAL;
     }
 
   return priv->seek_address;
diff --git a/drivers/sensors/lsm330_spi.c b/drivers/sensors/lsm330_spi.c
index a942726..6243eb6 100644
--- a/drivers/sensors/lsm330_spi.c
+++ b/drivers/sensors/lsm330_spi.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * drivers/sensors/lsm330.c
+ * drivers/sensors/lsm330_spi.c
  * Character driver for the ST LSM330 Tri-axis accelerometer and gyroscope.
  *
  *   Copyright (C) 2017-2018 RAF Research LLC. All rights reserved.
@@ -671,8 +671,7 @@ static int lsm330acl_dvr_open(FAR void *instance_handle, int32_t arg)
     {
       sninfo("INFO: LSM330 Accelerometer is already open.\n");
 
-      set_errno(-EBUSY);
-      return -1;
+      return -EBUSY;
     }
 
   /* Read the ID Register */
@@ -690,7 +689,6 @@ static int lsm330acl_dvr_open(FAR void *instance_handle, int32_t arg)
              "Device ID (0x%02X) does not match expected LSM330 Acl ID (0x%02).\n",
              reg_content, LSM330_ACL_IDREG_VALUE);
 
-      set_errno(ENODEV);
       priv->readonly = true;
     }
   else  /* ID matches */
@@ -765,8 +763,7 @@ static int lsm330gyro_dvr_open(FAR void *instance_handle, int32_t arg)
   if (ret < 0)
     {
       sninfo("INFO: LSM330 Gyroscope is already open.\n");
-      set_errno(-EBUSY);
-      return -1;
+      return -EBUSY;
     }
 
   /* Read the ID Register */
@@ -784,7 +781,6 @@ static int lsm330gyro_dvr_open(FAR void *instance_handle, int32_t arg)
              "Device ID (0x%02X) does not match expected LSM330 Gyro ID (0x%02).\n",
              reg_content, LSM330_GYRO_IDREG_VALUE);
 
-      set_errno(ENODEV);
       priv->readonly = true;
     }
   else /* ID matches */
@@ -925,8 +921,7 @@ static ssize_t lsm330acl_dvr_write(FAR void *instance_handle,
 
   if (priv->readonly)
     {
-      set_errno(-EROFS);
-      return -1;
+      return -EROFS;
     }
 
   lsm330_write_acl_registerblk(priv, priv->seek_address, (uint8_t *)buffer,
@@ -947,8 +942,7 @@ static ssize_t lsm330gyro_dvr_write(FAR void *instance_handle,
 
   if (priv->readonly)
     {
-      set_errno(-EROFS);
-      return -1;
+      return -EROFS;
     }
 
   lsm330_write_gyro_registerblk(priv, priv->seek_address,
@@ -973,8 +967,7 @@ static off_t lsm330acl_dvr_seek(FAR void *instance_handle, off_t offset, int whe
         reg = priv->seek_address + offset;
         if (0 > reg || reg > LSM330_ACL_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = reg;
@@ -987,16 +980,14 @@ static off_t lsm330acl_dvr_seek(FAR void *instance_handle, off_t offset, int whe
       case SEEK_SET:  /* seek to designated address */
         if (0 > offset || offset > LSM330_ACL_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = offset;
         break;
 
     default:  /* Invalid whence */
-        set_errno(-EINVAL);
-        return -1;
+        return -EINVAL;
     }
 
   return priv->seek_address;
@@ -1020,8 +1011,7 @@ static off_t lsm330gyro_dvr_seek(FAR void *instance_handle, off_t offset,
         reg = priv->seek_address + offset;
         if (0 > reg || reg > LSM330_GYRO_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = reg;
@@ -1034,16 +1024,14 @@ static off_t lsm330gyro_dvr_seek(FAR void *instance_handle, off_t offset,
       case SEEK_SET:  /* seek to designated address */
         if (0 > offset || offset > LSM330_GYRO_LAST)
           {
-            set_errno(-EINVAL);
-            return -1;
+            return -EINVAL;
           }
 
         priv->seek_address = offset;
         break;
 
       default:  /* Invalid whence */
-        set_errno(-EINVAL);
-        return -1;
+        return -EINVAL;
     }
 
   return priv->seek_address;
diff --git a/fs/fat/fs_fat32attrib.c b/fs/fat/fs_fat32attrib.c
index f6a4e35..76ebe16 100644
--- a/fs/fat/fs_fat32attrib.c
+++ b/fs/fat/fs_fat32attrib.c
@@ -52,19 +52,17 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
   uint8_t *direntry;
   uint8_t oldattributes;
   uint8_t newattributes;
-  int status;
   int ret;
 
   /* Find the inode for this file */
 
   SETUP_SEARCH(&desc, path, false);
 
-  status = inode_find(&desc);
-  if (status < 0)
+  ret = inode_find(&desc);
+  if (ret < 0)
     {
       /* There is no mountpoint that includes in this path */
 
-      ret = -status;
       goto errout;
     }
 
@@ -77,7 +75,7 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
 
   if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops || !inode->i_private)
     {
-      ret = ENXIO;
+      ret = -ENXIO;
       goto errout_with_inode;
     }
 
@@ -115,7 +113,7 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
     {
       /* Ooops.. we found the root directory */
 
-      ret = EACCES;
+      ret = -EACCES;
       goto errout_with_semaphore;
     }
 
@@ -141,7 +139,6 @@ static int fat_attrib(const char *path, fat_attrib_t *retattrib,
       ret = fat_updatefsinfo(fs);
       if (ret != OK)
         {
-          ret = -ret;
           goto errout_with_semaphore;
         }
     }
@@ -166,8 +163,7 @@ errout_with_inode:
 
 errout:
   RELEASE_SEARCH(&desc);
-  set_errno(ret);
-  return ERROR;
+  return ret;
 }
 
 /****************************************************************************
diff --git a/fs/vfs/fs_eventfd.c b/fs/vfs/fs_eventfd.c
index 23066a2..8175fce 100644
--- a/fs/vfs/fs_eventfd.c
+++ b/fs/vfs/fs_eventfd.c
@@ -625,7 +625,7 @@ int eventfd(unsigned int count, int flags)
 
   /* Try open new device */
 
-  new_fd = open(devpath, O_RDWR |
+  new_fd = nx_open(devpath, O_RDWR |
     (flags & (EFD_NONBLOCK | EFD_SEMAPHORE | EFD_CLOEXEC)));
 
   if (new_fd < 0)
diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c
index 10f2496..fa14316 100644
--- a/mm/mm_heap/mm_sem.c
+++ b/mm/mm_heap/mm_sem.c
@@ -56,26 +56,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Internal nxsem_* interfaces are not available in the user space in
- * PROTECTED and KERNEL builds.  In that context, the application semaphore
- * interfaces must be used.  The differences between the two sets of
- * interfaces are:  (1) the nxsem_* interfaces do not cause cancellation
- * points and (2) they do not modify the errno variable.
- *
- * See additional definitions in include/nuttx/semaphore.h
- *
- * REVISIT:  The fact that sem_wait() is a cancellation point is an issue
- * and does cause a violation:  It makes all of the memory management
- * interfaces into cancellation points when used from user space in the
- * PROTECTED and KERNEL builds.
- */
-
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
-#  define _SEM_GETERROR(r)
-#else
-#  define _SEM_GETERROR(r)  (r) = -errno
-#endif
-
 /* This is a special value that indicates that there is no holder of the
  * semaphore.  The valid range of PIDs is 0-32767 and any value outside of
  * that range could be used (except -ESRCH which is a special return value
@@ -194,7 +174,7 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap)
       ret = _SEM_TRYWAIT(&heap->mm_semaphore);
       if (ret < 0)
         {
-          _SEM_GETERROR(ret);
+          ret = _SEM_ERRVAL(ret);
           goto errout;
         }
 
@@ -255,13 +235,8 @@ void mm_takesemaphore(FAR struct mm_heap_s *heap)
 
           if (ret < 0)
             {
-#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+              ret = _SEM_ERRVAL(ret);
               DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
-#else
-              int errcode = get_errno();
-              DEBUGASSERT(errcode == EINTR || errcode == ECANCELED);
-              ret = -errcode;
-#endif
             }
         }
       while (ret == -EINTR);