mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 21:36:28 +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;
|
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)
|
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
*get_errno_ptr() = ENOTTY;
|
return -ENOTTY;
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -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)
|
static int up_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
*get_errno_ptr() = ENOTTY;
|
return -ENOTTY;
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -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 lcd_dev_s *
|
||||||
FAR struct ili9341_lcd_s *lcd, int devno)
|
ili9341_initialize(FAR struct ili9341_lcd_s *lcd, int devno)
|
||||||
{
|
{
|
||||||
if (lcd && devno >= 0 && devno < CONFIG_LCD_ILI9341_NINTERFACES)
|
if (lcd && devno >= 0 && devno < CONFIG_LCD_ILI9341_NINTERFACES)
|
||||||
{
|
{
|
||||||
@@ -1175,15 +1175,12 @@ FAR struct lcd_dev_s *ili9341_initialize(
|
|||||||
{
|
{
|
||||||
return &priv->dev;
|
return &priv->dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = EINVAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ili9341_clear
|
* Name: ili9341_clear
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -177,8 +177,7 @@ static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errno = EFAULT;
|
return -EFAULT;
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length > 1)
|
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,
|
FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c,
|
||||||
uint16_t address)
|
uint16_t address)
|
||||||
{
|
{
|
||||||
FAR struct lis331dl_dev_s * dev;
|
FAR struct lis331dl_dev_s *dev;
|
||||||
uint8_t retval;
|
uint8_t retval;
|
||||||
|
|
||||||
ASSERT(i2c);
|
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));
|
dev = kmm_malloc(sizeof(struct lis331dl_dev_s));
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
{
|
{
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,28 +271,14 @@ FAR struct lis331dl_dev_s *lis331dl_init(FAR struct i2c_master_s *i2c,
|
|||||||
{
|
{
|
||||||
/* Normal exit point */
|
/* Normal exit point */
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
return dev;
|
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 */
|
/* Error exit */
|
||||||
|
|
||||||
kmm_free(dev);
|
kmm_free(dev);
|
||||||
errno = retval;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +396,6 @@ lis331dl_getreadings(FAR struct lis331dl_dev_s * dev)
|
|||||||
|
|
||||||
if (!(retval[0] & ST_LIS331DL_SR_ZYXDA))
|
if (!(retval[0] & ST_LIS331DL_SR_ZYXDA))
|
||||||
{
|
{
|
||||||
errno = EAGAIN;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-24
@@ -444,9 +444,9 @@ static uart_dev_t g_uart3port =
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Inline Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: u16550_serialin
|
* Name: u16550_serialin
|
||||||
@@ -487,7 +487,8 @@ static inline void u16550_disableuartint(FAR struct u16550_s *priv,
|
|||||||
* Name: u16550_restoreuartint
|
* 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;
|
priv->ier |= ier & UART_IER_ALLIE;
|
||||||
u16550_serialout(priv, UART_IER_OFFSET, priv->ier);
|
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
|
* 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);
|
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);
|
u16550_serialout(priv, UART_LCR_OFFSET, lcr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: u16550_divisor
|
* Name: u16550_divisor
|
||||||
*
|
*
|
||||||
* Descrption:
|
* Descrption:
|
||||||
@@ -524,7 +526,7 @@ static inline void u16550_enablebreaks(FAR struct u16550_s *priv, bool enable)
|
|||||||
*
|
*
|
||||||
* Ignoring the fractional divider for now.
|
* Ignoring the fractional divider for now.
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_16550_SUPRESS_CONFIG
|
#ifndef CONFIG_16550_SUPRESS_CONFIG
|
||||||
static inline uint32_t u16550_divisor(FAR struct u16550_s *priv)
|
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
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: u16550_setup
|
* 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
|
#ifndef CONFIG_16550_SUPRESS_CONFIG
|
||||||
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
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);
|
up_enable_irq(priv->irq);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ret;
|
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)
|
static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||||
{
|
{
|
||||||
struct uart_dev_s *dev = (struct uart_dev_s *)arg;
|
FAR struct uart_dev_s *dev = (struct uart_dev_s *)arg;
|
||||||
struct u16550_s *priv;
|
FAR struct u16550_s *priv;
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
int passes;
|
int passes;
|
||||||
|
|
||||||
DEBUGASSERT(dev != NULL && dev->priv != NULL);
|
DEBUGASSERT(dev != NULL && dev->priv != NULL);
|
||||||
priv = (FAR struct u16550_s *)dev->priv;
|
priv = (FAR struct u16550_s *)dev->priv;
|
||||||
@@ -791,7 +790,7 @@ static int u16550_interrupt(int irq, FAR void *context, FAR void *arg)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
_err("ERROR: Unexpected IIR: %02x\n", status);
|
serr("ERROR: Unexpected IIR: %02x\n", status);
|
||||||
break;
|
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)
|
static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
struct inode *inode = filep->f_inode;
|
FAR struct inode *inode = filep->f_inode;
|
||||||
struct uart_dev_s *dev = inode->i_private;
|
FAR struct uart_dev_s *dev = inode->i_private;
|
||||||
struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef CONFIG_SERIAL_UART_ARCH_IOCTL
|
#ifdef CONFIG_SERIAL_UART_ARCH_IOCTL
|
||||||
@@ -822,6 +821,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
|||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
ret = OK;
|
ret = OK;
|
||||||
#endif
|
#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;
|
FAR struct u16550_s *user = (FAR struct u16550_s *)arg;
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
set_errno(EINVAL);
|
ret = -EINVAL;
|
||||||
ret = ERROR;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -863,8 +862,7 @@ static int u16550_ioctl(struct file *filep, int cmd, unsigned long arg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
set_errno(ENOTTY);
|
ret = -ENOTTY;
|
||||||
ret = ERROR;
|
|
||||||
break;
|
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)
|
static void u16550_rxint(struct uart_dev_s *dev, bool enable)
|
||||||
{
|
{
|
||||||
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
|
||||||
|
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
priv->ier |= UART_IER_ERBFI;
|
priv->ier |= UART_IER_ERBFI;
|
||||||
|
|||||||
+13
-15
@@ -335,7 +335,7 @@ void cc1101_access_end(FAR struct cc1101_dev_s *dev)
|
|||||||
* however
|
* however
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* 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,
|
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)
|
if ((addr & CC1101_READ_SINGLE) && length != 1)
|
||||||
{
|
{
|
||||||
return ERROR;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare SPI */
|
/* Prepare SPI */
|
||||||
@@ -396,7 +396,6 @@ int cc1101_access(FAR struct cc1101_dev_s *dev, uint8_t addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc1101_access_end(dev);
|
cc1101_access_end(dev);
|
||||||
|
|
||||||
return stabyte;
|
return stabyte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,7 +434,7 @@ int cc1101_checkpart(struct cc1101_dev_s *dev)
|
|||||||
if (cc1101_access(dev, CC1101_PARTNUM, &partnum, 1) < 0 ||
|
if (cc1101_access(dev, CC1101_PARTNUM, &partnum, 1) < 0 ||
|
||||||
cc1101_access(dev, CC1101_VERSION, &version, 1) < 0)
|
cc1101_access(dev, CC1101_VERSION, &version, 1) < 0)
|
||||||
{
|
{
|
||||||
return ERROR;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partnum == CC1101_PARTNUM_VALUE && version == CC1101_VERSION_VALUE)
|
if (partnum == CC1101_PARTNUM_VALUE && version == CC1101_VERSION_VALUE)
|
||||||
@@ -443,7 +442,7 @@ int cc1101_checkpart(struct cc1101_dev_s *dev)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cc1101_dumpregs(struct cc1101_dev_s *dev, uint8_t addr, uint8_t length)
|
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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct cc1101_dev_s *cc1101_init(struct spi_dev_s *spi, uint8_t isrpin,
|
FAR struct cc1101_dev_s *
|
||||||
uint32_t pinset, const struct c1101_rfsettings_s *rfsettings)
|
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);
|
ASSERT(spi);
|
||||||
|
|
||||||
if ((dev = kmm_malloc(sizeof(struct cc1101_dev_s))) == NULL)
|
if ((dev = kmm_malloc(sizeof(struct cc1101_dev_s))) == NULL)
|
||||||
{
|
{
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
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)
|
if (cc1101_reset(dev) < 0)
|
||||||
{
|
{
|
||||||
kmm_free(dev);
|
kmm_free(dev);
|
||||||
errno = EFAULT;
|
|
||||||
return NULL;
|
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)
|
if (cc1101_checkpart(dev) < 0)
|
||||||
{
|
{
|
||||||
kmm_free(dev);
|
kmm_free(dev);
|
||||||
errno = ENODEV;
|
|
||||||
return NULL;
|
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)
|
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)
|
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)
|
if (cc1101_access(dev, CC1101_FREND1, (FAR uint8_t *)&settings->FREND1, -6) < 0)
|
||||||
{
|
{
|
||||||
return ERROR;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load Power Table */
|
/* Load Power Table */
|
||||||
|
|
||||||
if (cc1101_access(dev, CC1101_PATABLE, (FAR uint8_t *)settings->PA, -8) < 0)
|
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.
|
/* If channel is out of valid range, mark that. Limit power.
|
||||||
|
|||||||
Reference in New Issue
Block a user