mirror of
https://github.com/apache/nuttx.git
synced 2026-03-27 02:29:15 +08:00
Squashed commit of the following:
configs/z80sim and xtrs: Serial driver lower halfs ioctl methods should return a negated errno value, not set the errno variable.
drivers/wireless: CC1101 driver not permitted to set errno.
drivers/sensors: LIS331DL driver not permitted to set errno.
drivers/lcd: ILI9341 initialize method not permitted to set errno,
drivers/serial: 16550 UART driver IOCTL method must not set errno; it must return a negated errno value.
This commit is contained in:
@@ -502,7 +502,7 @@ int board_lcd_initialize(void)
|
||||
}
|
||||
}
|
||||
|
||||
return -errno;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
@@ -266,8 +266,7 @@ static void up_detach(FAR struct uart_dev_s *dev)
|
||||
|
||||
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
*get_errno_ptr() = ENOTTY;
|
||||
return ERROR;
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -215,8 +215,7 @@ static void up_detach(FAR struct uart_dev_s *dev)
|
||||
|
||||
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
*get_errno_ptr() = ENOTTY;
|
||||
return ERROR;
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -1143,8 +1143,8 @@ static int ili9341_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcd_dev_s *ili9341_initialize(
|
||||
FAR struct ili9341_lcd_s *lcd, int devno)
|
||||
FAR struct lcd_dev_s *
|
||||
ili9341_initialize(FAR struct ili9341_lcd_s *lcd, int devno)
|
||||
{
|
||||
if (lcd && devno >= 0 && devno < CONFIG_LCD_ILI9341_NINTERFACES)
|
||||
{
|
||||
@@ -1175,15 +1175,12 @@ FAR struct lcd_dev_s *ili9341_initialize(
|
||||
{
|
||||
return &priv->dev;
|
||||
}
|
||||
|
||||
errno = EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ili9341_clear
|
||||
*
|
||||
|
||||
@@ -177,8 +177,7 @@ static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr,
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EFAULT;
|
||||
return ERROR;
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (length > 1)
|
||||
@@ -240,7 +239,7 @@ static int lis331dl_readregs(FAR struct lis331dl_dev_s *dev)
|
||||
FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c,
|
||||
uint16_t address)
|
||||
{
|
||||
FAR struct lis331dl_dev_s * dev;
|
||||
FAR struct lis331dl_dev_s *dev;
|
||||
uint8_t retval;
|
||||
|
||||
ASSERT(i2c);
|
||||
@@ -249,7 +248,6 @@ FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c,
|
||||
dev = kmm_malloc(sizeof(struct lis331dl_dev_s));
|
||||
if (dev == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -273,28 +271,14 @@ FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c,
|
||||
{
|
||||
/* Normal exit point */
|
||||
|
||||
errno = 0;
|
||||
return dev;
|
||||
}
|
||||
|
||||
retval = errno;
|
||||
}
|
||||
|
||||
/* Otherwise, we mark an invalid device found at given address */
|
||||
|
||||
retval = ENODEV;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No response at given address is marked as */
|
||||
|
||||
retval = EFAULT;
|
||||
}
|
||||
|
||||
/* Error exit */
|
||||
|
||||
kmm_free(dev);
|
||||
errno = retval;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -412,7 +396,6 @@ lis331dl_getreadings(FAR struct lis331dl_dev_s * dev)
|
||||
|
||||
if (!(retval[0] & ST_LIS331DL_SR_ZYXDA))
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -444,9 +444,9 @@ static uart_dev_t g_uart3port =
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Inline Functions
|
||||
************************************************************************************/
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: u16550_serialin
|
||||
@@ -487,7 +487,8 @@ static inline void u16550_disableuartint(FAR struct u16550_s *priv,
|
||||
* Name: u16550_restoreuartint
|
||||
****************************************************************************/
|
||||
|
||||
static inline void u16550_restoreuartint(FAR struct u16550_s *priv, uint32_t ier)
|
||||
static inline void u16550_restoreuartint(FAR struct u16550_s *priv,
|
||||
uint32_t ier)
|
||||
{
|
||||
priv->ier |= ier & UART_IER_ALLIE;
|
||||
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
|
||||
@@ -497,7 +498,8 @@ static inline void u16550_restoreuartint(FAR struct u16550_s *priv, uint32_t ier
|
||||
* Name: u16550_enablebreaks
|
||||
****************************************************************************/
|
||||
|
||||
static inline void u16550_enablebreaks(FAR struct u16550_s *priv, bool enable)
|
||||
static inline void u16550_enablebreaks(FAR struct u16550_s *priv,
|
||||
bool enable)
|
||||
{
|
||||
uint32_t lcr = u16550_serialin(priv, UART_LCR_OFFSET);
|
||||
|
||||
@@ -513,7 +515,7 @@ static inline void u16550_enablebreaks(FAR struct u16550_s *priv, bool enable)
|
||||
u16550_serialout(priv, UART_LCR_OFFSET, lcr);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: u16550_divisor
|
||||
*
|
||||
* Descrption:
|
||||
@@ -524,7 +526,7 @@ static inline void u16550_enablebreaks(FAR struct u16550_s *priv, bool enable)
|
||||
*
|
||||
* Ignoring the fractional divider for now.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_16550_SUPRESS_CONFIG
|
||||
static inline uint32_t u16550_divisor(FAR struct u16550_s *priv)
|
||||
@@ -533,10 +535,6 @@ static inline uint32_t u16550_divisor(FAR struct u16550_s *priv)
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: u16550_setup
|
||||
*
|
||||
@@ -547,7 +545,7 @@ static inline uint32_t u16550_divisor(FAR struct u16550_s *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int u16550_setup(struct uart_dev_s *dev)
|
||||
static int u16550_setup(FAR struct uart_dev_s *dev)
|
||||
{
|
||||
#ifndef CONFIG_16550_SUPRESS_CONFIG
|
||||
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||
@@ -676,6 +674,7 @@ static int u16550_attach(struct uart_dev_s *dev)
|
||||
up_enable_irq(priv->irq);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -711,10 +710,10 @@ static void u16550_detach(FAR struct uart_dev_s *dev)
|
||||
|
||||
static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
{
|
||||
struct uart_dev_s *dev = (struct uart_dev_s *)arg;
|
||||
struct u16550_s *priv;
|
||||
uint32_t status;
|
||||
int passes;
|
||||
FAR struct uart_dev_s *dev = (struct uart_dev_s *)arg;
|
||||
FAR struct u16550_s *priv;
|
||||
uint32_t status;
|
||||
int passes;
|
||||
|
||||
DEBUGASSERT(dev != NULL && dev->priv != NULL);
|
||||
priv = (FAR struct u16550_s *)dev->priv;
|
||||
@@ -791,7 +790,7 @@ static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
|
||||
default:
|
||||
{
|
||||
_err("ERROR: Unexpected IIR: %02x\n", status);
|
||||
serr("ERROR: Unexpected IIR: %02x\n", status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -810,9 +809,9 @@ static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
|
||||
static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = filep->f_inode;
|
||||
struct uart_dev_s *dev = inode->i_private;
|
||||
struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct uart_dev_s *dev = inode->i_private;
|
||||
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_SERIAL_UART_ARCH_IOCTL
|
||||
@@ -822,6 +821,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
ret = OK;
|
||||
#endif
|
||||
@@ -834,8 +834,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
FAR struct u16550_s *user = (FAR struct u16550_s *)arg;
|
||||
if (!user)
|
||||
{
|
||||
set_errno(EINVAL);
|
||||
ret = ERROR;
|
||||
ret = -EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -863,8 +862,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
break;
|
||||
|
||||
default:
|
||||
set_errno(ENOTTY);
|
||||
ret = ERROR;
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -902,6 +900,7 @@ static int u16550_receive(struct uart_dev_s *dev, uint32_t *status)
|
||||
static void u16550_rxint(struct uart_dev_s *dev, bool enable)
|
||||
{
|
||||
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
priv->ier |= UART_IER_ERBFI;
|
||||
|
||||
@@ -335,7 +335,7 @@ void cc1101_access_end(FAR struct cc1101_dev_s *dev)
|
||||
* however
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success or errno is set.
|
||||
* OK on success or a negated errno value on any failure.
|
||||
*/
|
||||
|
||||
int cc1101_access(FAR struct cc1101_dev_s *dev, uint8_t addr,
|
||||
@@ -350,7 +350,7 @@ int cc1101_access(FAR struct cc1101_dev_s *dev, uint8_t addr,
|
||||
|
||||
if ((addr & CC1101_READ_SINGLE) && length != 1)
|
||||
{
|
||||
return ERROR;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Prepare SPI */
|
||||
@@ -396,7 +396,6 @@ int cc1101_access(FAR struct cc1101_dev_s *dev, uint8_t addr,
|
||||
}
|
||||
|
||||
cc1101_access_end(dev);
|
||||
|
||||
return stabyte;
|
||||
}
|
||||
|
||||
@@ -435,7 +434,7 @@ int cc1101_checkpart(struct cc1101_dev_s *dev)
|
||||
if (cc1101_access(dev, CC1101_PARTNUM, &partnum, 1) < 0 ||
|
||||
cc1101_access(dev, CC1101_VERSION, &version, 1) < 0)
|
||||
{
|
||||
return ERROR;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (partnum == CC1101_PARTNUM_VALUE && version == CC1101_VERSION_VALUE)
|
||||
@@ -443,7 +442,7 @@ int cc1101_checkpart(struct cc1101_dev_s *dev)
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ERROR;
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
void cc1101_dumpregs(struct cc1101_dev_s *dev, uint8_t addr, uint8_t length)
|
||||
@@ -524,16 +523,17 @@ int cc1101_eventcb(int irq, FAR void *context)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
struct cc1101_dev_s *cc1101_init(struct spi_dev_s *spi, uint8_t isrpin,
|
||||
uint32_t pinset, const struct c1101_rfsettings_s *rfsettings)
|
||||
FAR struct cc1101_dev_s *
|
||||
cc1101_init(FAR struct spi_dev_s *spi, uint8_t isrpin,
|
||||
uint32_t pinset,
|
||||
FAR const struct c1101_rfsettings_s *rfsettings)
|
||||
{
|
||||
struct cc1101_dev_s *dev;
|
||||
FAR struct cc1101_dev_s *dev;
|
||||
|
||||
ASSERT(spi);
|
||||
|
||||
if ((dev = kmm_malloc(sizeof(struct cc1101_dev_s))) == NULL)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -550,7 +550,6 @@ struct cc1101_dev_s *cc1101_init(struct spi_dev_s *spi, uint8_t isrpin,
|
||||
if (cc1101_reset(dev) < 0)
|
||||
{
|
||||
kmm_free(dev);
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -559,7 +558,6 @@ struct cc1101_dev_s *cc1101_init(struct spi_dev_s *spi, uint8_t isrpin,
|
||||
if (cc1101_checkpart(dev) < 0)
|
||||
{
|
||||
kmm_free(dev);
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -667,24 +665,24 @@ int cc1101_setrf(struct cc1101_dev_s *dev, const struct c1101_rfsettings_s *sett
|
||||
|
||||
if (cc1101_access(dev, CC1101_FSCTRL1, (FAR uint8_t *)&settings->FSCTRL1, -11) < 0)
|
||||
{
|
||||
return ERROR;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (cc1101_access(dev, CC1101_FOCCFG, (FAR uint8_t *)&settings->FOCCFG, -5) < 0)
|
||||
{
|
||||
return ERROR;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (cc1101_access(dev, CC1101_FREND1, (FAR uint8_t *)&settings->FREND1, -6) < 0)
|
||||
{
|
||||
return ERROR;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Load Power Table */
|
||||
|
||||
if (cc1101_access(dev, CC1101_PATABLE, (FAR uint8_t *)settings->PA, -8) < 0)
|
||||
{
|
||||
return ERROR;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* If channel is out of valid range, mark that. Limit power.
|
||||
|
||||
Reference in New Issue
Block a user