sched/wdog: wd_start() is an internal OS function and should not set the errno value. Reviewed and updated every call to wd_start() to verify if return value is used and if so if the errno value is accessed.

This commit is contained in:
Gregory Nutt 2018-01-31 10:09:14 -06:00
parent a959d7fefa
commit da50646bcf
43 changed files with 94 additions and 72 deletions

View File

@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i>
</font></big></h1>
<p>Last Updated: October 12, 2017</p>
<p>Last Updated: January 31, 2018</p>
</td>
</tr>
</table>
@ -2605,7 +2605,7 @@ pointer to a watchdog structure.
<p>
<b>Returned Value:</b>
<ul>
<li>OK or ERROR
<li>Zero (<code>OK</code>) is returned on success; a negated <code>errno</code> value is return to indicate the nature of any failure.
</ul>
<p>
@ -2662,7 +2662,7 @@ wd_start() on a given watchdog ID has any effect.
<p>
<b>Returned Value:</b>
<ul>
<li>OK or ERROR
<li>Zero (<code>OK</code>) is returned on success; a negated <code>errno</code> value is return to indicate the nature of any failure.
</ul>
<p>

View File

@ -1493,7 +1493,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
ret = wd_start(priv->wdog, (int)ticks, spi_dma_timeout, 1, (uint32_t)priv);
if (ret < 0)
{
spierr("ERROR: Failed to start timeout\n");
spierr("ERROR: Failed to start timeout: %d\n", ret);
}
/* Then wait for each to complete. TX should complete first */

View File

@ -1183,7 +1183,7 @@ static int kinetis_i2c_transfer(struct i2c_master_s *dev,
/* Wait for transfer complete */
wd_start(priv->timeout, I2C_TIMEOUT, kinetis_i2c_timeout, 1,
(void)wd_start(priv->timeout, I2C_TIMEOUT, kinetis_i2c_timeout, 1,
(uint32_t)priv);
kinetis_i2c_wait(priv);

View File

@ -2465,7 +2465,7 @@ static sdio_eventset_t kinetis_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)kinetis_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1112,7 +1112,8 @@ static void khci_delayedrestart(struct khci_usbdev_s *priv, uint8_t epno)
/* And start (or re-start) the watchdog timer */
wd_start(priv->wdog, RESTART_DELAY, khci_rqrestart, 1, (uint32_t)priv);
(void)wd_start(priv->wdog, RESTART_DELAY, khci_rqrestart, 1,
(uint32_t)priv);
}
/****************************************************************************

View File

@ -215,7 +215,8 @@ static int lpc11_i2c_start(struct lpc11_i2cdev_s *priv)
priv->base + LPC11_I2C_CONCLR_OFFSET);
putreg32(I2C_CONSET_STA, priv->base + LPC11_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc11_i2c_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, I2C_TIMEOUT, lpc11_i2c_timeout, 1,
(uint32_t)priv);
nxsem_wait(&priv->wait);
wd_cancel(priv->timeout);

View File

@ -215,7 +215,8 @@ static int lpc17_i2c_start(struct lpc17_i2cdev_s *priv)
priv->base + LPC17_I2C_CONCLR_OFFSET);
putreg32(I2C_CONSET_STA, priv->base + LPC17_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc17_i2c_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, I2C_TIMEOUT, lpc17_i2c_timeout, 1,
(uint32_t)priv);
nxsem_wait(&priv->wait);
wd_cancel(priv->timeout);

View File

@ -2307,7 +2307,7 @@ static sdio_eventset_t lpc17_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)lpc17_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -220,7 +220,8 @@ static int lpc2378_i2c_start(struct lpc2378_i2cdev_s *priv)
priv->base + I2C_CONCLR_OFFSET);
putreg32(I2C_CONSET_STA, priv->base + I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc2378_i2c_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, I2C_TIMEOUT, lpc2378_i2c_timeout, 1,
(uint32_t)priv);
nxsem_wait(&priv->wait);
wd_cancel(priv->timeout);

View File

@ -490,7 +490,7 @@ static int i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs
/* Start a watchdog to timeout the transfer if the bus is locked up... */
wd_start(priv->timeout, I2C_TIMEOUT, i2c_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, I2C_TIMEOUT, i2c_timeout, 1, (uint32_t)priv);
/* Wait for the transfer to complete */

View File

@ -202,7 +202,8 @@ static int lpc43_i2c_start(struct lpc43_i2cdev_s *priv)
priv->base + LPC43_I2C_CONCLR_OFFSET);
putreg32(I2C_CONSET_STA, priv->base + LPC43_I2C_CONSET_OFFSET);
wd_start(priv->timeout, I2C_TIMEOUT, lpc43_i2c_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, I2C_TIMEOUT, lpc43_i2c_timeout, 1,i
(uint32_t)priv);
nxsem_wait(&priv->wait);
wd_cancel(priv->timeout);

View File

@ -2262,7 +2262,7 @@ static sdio_eventset_t lpc43_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)lpc43_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -765,10 +765,9 @@ static int lpc54_i2c_transfer(FAR struct i2c_master_s *dev,
priv->result = OK;
/* Set up the transfer timeout */
/* wd_start(priv->timeout ...); */
wd_start(priv->timeout, priv->nmsgs * I2C_WDOG_TIMEOUT, lpc54_i2c_timeout,
1, (uint32_t)priv);
(void)wd_start(priv->timeout, priv->nmsgs * I2C_WDOG_TIMEOUT,
lpc54_i2c_timeout, 1, (uint32_t)priv);
/* Initiate the transfer */

View File

@ -2262,7 +2262,7 @@ static sdio_eventset_t lpc54_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)lpc54_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -2317,7 +2317,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)sam_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1590,7 +1590,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
ret = wd_start(spics->dmadog, DMA_TIMEOUT_TICKS,
(wdentry_t)spi_dmatimeout, 1, (uint32_t)spics);
if (ret != OK)
if (ret < 0)
{
spierr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -386,7 +386,7 @@ static int twi_wait(struct twi_dev_s *priv)
{
/* Start a timeout to avoid hangs */
wd_start(priv->timeout, TWI_TIMEOUT, twi_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, TWI_TIMEOUT, twi_timeout, 1, (uint32_t)priv);
/* Wait for either the TWI transfer or the timeout to complete */

View File

@ -2745,7 +2745,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)sam_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
lcderr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1520,7 +1520,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
ret = wd_start(spics->dmadog, DMA_TIMEOUT_TICKS,
(wdentry_t)spi_dmatimeout, 1, (uint32_t)spics);
if (ret != OK)
if (ret < 0)
{
spierr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -597,7 +597,8 @@ static void sam_tsd_bottomhalf(void *arg)
* this case; we rely on the timer expiry to get us going again.
*/
wd_start(priv->wdog, TSD_WDOG_DELAY, sam_tsd_expiry, 1, (uint32_t)priv);
(void)wd_start(priv->wdog, TSD_WDOG_DELAY, sam_tsd_expiry, 1,
(uint32_t)priv);
ier = 0;
goto ignored;
}
@ -675,7 +676,8 @@ static void sam_tsd_bottomhalf(void *arg)
/* Continue to sample the position while the pen is down */
wd_start(priv->wdog, TSD_WDOG_DELAY, sam_tsd_expiry, 1, (uint32_t)priv);
(void)wd_start(priv->wdog, TSD_WDOG_DELAY, sam_tsd_expiry, 1,
(uint32_t)priv);
/* Check the thresholds. Bail if (1) this is not the first
* measurement and (2) there is no significant difference from

View File

@ -487,7 +487,7 @@ static int twi_wait(struct twi_dev_s *priv, unsigned int size)
* TWI transfer stalls.
*/
wd_start(priv->timeout, timeout, twi_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, timeout, twi_timeout, 1, (uint32_t)priv);
/* Wait for either the TWI transfer or the timeout to complete */

View File

@ -2791,7 +2791,7 @@ static sdio_eventset_t sam_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)sam_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -885,7 +885,7 @@ static int qspi_memory_dma(struct sam_qspidev_s *priv,
ret = wd_start(priv->dmadog, DMA_TIMEOUT_TICKS,
(wdentry_t)qspi_dma_timeout, 1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
spierr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1864,7 +1864,7 @@ static void spi_exchange(struct spi_dev_s *dev, const void *txbuffer,
ret = wd_start(spics->dmadog, DMA_TIMEOUT_TICKS,
(wdentry_t)spi_dmatimeout, 1, (uint32_t)spics);
if (ret != OK)
if (ret < 0)
{
spierr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -491,7 +491,8 @@ static int twi_wait(struct twi_dev_s *priv, unsigned int size)
* TWIHS transfer stalls.
*/
wd_start(priv->timeout, (timeout * size), twi_timeout, 1, (uint32_t)priv);
(void)wd_start(priv->timeout, (timeout * size), twi_timeout, 1,
(uint32_t)priv);
/* Wait for either the TWIHS transfer or the timeout to complete */

View File

@ -2500,7 +2500,7 @@ static sdio_eventset_t stm32_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)stm32_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -2691,7 +2691,7 @@ static sdio_eventset_t stm32_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)stm32_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1447,7 +1447,7 @@ static int qspi_memory_dma(struct stm32l4_qspidev_s *priv,
ret = wd_start(priv->dmadog, DMA_TIMEOUT_TICKS,
(wdentry_t)qspi_dma_timeout, 1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
spierr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -2637,7 +2637,7 @@ static sdio_eventset_t stm32_eventwait(FAR struct sdio_dev_s *dev,
delay = MSEC2TICK(timeout);
ret = wd_start(priv->waitwdog, delay, (wdentry_t)stm32_eventtimeout,
1, (uint32_t)priv);
if (ret != OK)
if (ret < 0)
{
mcerr("ERROR: wd_start failed: %d\n", ret);
}

View File

@ -1031,7 +1031,8 @@ static void pic32mx_delayedrestart(struct pic32mx_usbdev_s *priv, uint8_t epno)
/* And start (or re-start) the watchdog timer */
wd_start(priv->wdog, RESTART_DELAY, pic32mx_rqrestart, 1, (uint32_t)priv);
(void)wd_start(priv->wdog, RESTART_DELAY, pic32mx_rqrestart, 1,
(uint32_t)priv);
}
/****************************************************************************

View File

@ -607,7 +607,8 @@ static void ads7843e_worker(FAR void *arg)
* later.
*/
wd_start(priv->wdog, ADS7843E_WDOG_DELAY, ads7843e_wdog, 1, (uint32_t)priv);
(void)wd_start(priv->wdog, ADS7843E_WDOG_DELAY, ads7843e_wdog, 1,
(uint32_t)priv);
goto ignored;
}
else

View File

@ -592,7 +592,7 @@ static void max11802_worker(FAR void *arg)
iinfo("Previous pen up event still in buffer\n");
max11802_notify(priv);
wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1,
(void)wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1,
(uint32_t)priv);
goto ignored;
}
@ -632,8 +632,8 @@ static void max11802_worker(FAR void *arg)
/* Continue to sample the position while the pen is down */
wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1,
(uint32_t)priv);
(void)wd_start(priv->wdog, MAX11802_WDOG_DELAY, max11802_wdog, 1,
i (uint32_t)priv);
/* Check if data is valid */

View File

@ -886,7 +886,7 @@ int bcmf_wl_start_scan(FAR struct bcmf_dev_s *priv, struct iwreq *iwr)
/* Start scan_timeout timer */
wd_start(priv->scan_timeout, BCMF_SCAN_TIMEOUT_TICK,
(void)wd_start(priv->scan_timeout, BCMF_SCAN_TIMEOUT_TICK,
bcmf_wl_scan_timeout, (wdparm_t)priv);
return OK;

View File

@ -665,8 +665,8 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
/* Start the waitdog timer */
wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK, bcmf_sdio_waitdog_timeout,
(wdparm_t)priv);
(void)wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK,
bcmf_sdio_waitdog_timeout, (wdparm_t)priv);
/* Spawn bcmf daemon thread */
@ -760,7 +760,7 @@ int bcmf_sdio_thread(int argc, char **argv)
/* Restart the waitdog timer */
wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK,
(void)wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK,
bcmf_sdio_waitdog_timeout, (wdparm_t)priv);
/* Wake up device */

View File

@ -303,11 +303,8 @@ static int automount_unmount(FAR struct automounter_state_s *priv)
(uint32_t)((uintptr_t)priv));
if (ret < 0)
{
errcode = get_errno();
DEBUGASSERT(errcode > 0);
ferr("ERROR: wd_start failed: %d\n", errcode);
return -ret;
ferr("ERROR: wd_start failed: %d\n", ret);
return ret;
}
}

View File

@ -1,7 +1,8 @@
/****************************************************************************
* include/nuttx/wdog.h
*
* Copyright (C) 2007-2009, 2014-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2014-2015, 2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -196,7 +197,8 @@ WDOG_ID wd_create(void);
* watchdog structure.
*
* Return Value:
* Returns OK or ERROR
* Zero (OK) is returned on success; a negated errno value is return to
* indicate the nature of any failure.
*
* Assumptions:
* The caller has assured that the watchdog is no longer in use.
@ -230,7 +232,8 @@ int wd_delete(WDOG_ID wdog);
* parm1..4 - parameters to pass to wdentry
*
* Return Value:
* OK or ERROR
* Zero (OK) is returned on success; a negated errno value is return to
* indicate the nature of any failure.
*
* Assumptions:
* The watchdog routine runs in the context of the timer interrupt handler

View File

@ -239,7 +239,7 @@ ssize_t nxmq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen,
/* Start the watchdog */
wd_start(rtcb->waitdog, ticks, (wdentry_t)nxmq_rcvtimeout,
(void)wd_start(rtcb->waitdog, ticks, (wdentry_t)nxmq_rcvtimeout,
1, getpid());
}

View File

@ -271,7 +271,8 @@ int nxmq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio,
/* Start the watchdog and begin the wait for MQ not full */
wd_start(rtcb->waitdog, ticks, (wdentry_t)nxmq_sndtimeout, 1, getpid());
(void)wd_start(rtcb->waitdog, ticks, (wdentry_t)nxmq_sndtimeout,
1, getpid());
/* And wait for the message queue to be non-empty */

View File

@ -274,8 +274,10 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex,
{
/* Start the watchdog */
wd_start(rtcb->waitdog, ticks, (wdentry_t)pthread_condtimedout,
2, (uint32_t)mypid, (uint32_t)SIGCONDTIMEDOUT);
(void)wd_start(rtcb->waitdog, ticks,
(wdentry_t)pthread_condtimedout,
2, (uint32_t)mypid,
(uint32_t)SIGCONDTIMEDOUT);
/* Take the condition semaphore. Do not restore interrupts
* until we return from the wait. This is necessary to

View File

@ -356,8 +356,8 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
/* Start the watchdog */
wd_start(rtcb->waitdog, waitticks, (wdentry_t)nxsig_timeout,
1, wdparm.pvarg);
(void)wd_start(rtcb->waitdog, waitticks,
(wdentry_t)nxsig_timeout, 1, wdparm.pvarg);
/* Now wait for either the signal or the watchdog */

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/timer/timer_settime.c
*
* Copyright (C) 2007-2010, 2013-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2010, 2013-2016, 2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -390,6 +391,15 @@ int timer_settime(timer_t timerid, int flags,
timer->pt_last = delay;
ret = wd_start(timer->pt_wdog, delay, (wdentry_t)timer_timeout,
1, (uint32_t)((wdparm_t)timer));
if (ret < 0)
{
set_errno(-ret);
ret = ERROR;
}
else
{
ret = OK;
}
}
leave_critical_section(intflags);

View File

@ -68,7 +68,8 @@
* watchdog structure.
*
* Return Value:
* Returns OK or ERROR
* Zero (OK) is returned on success; a negated errno value is return to
* indicate the nature of any failure.
*
* Assumptions:
* The caller has assured that the watchdog is no longer in use.

View File

@ -1,7 +1,8 @@
/****************************************************************************
* sched/wdog/wd_start.c
*
* Copyright (C) 2007-2009, 2012, 2014, 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2012, 2014, 2016, 2018 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -103,8 +104,6 @@ typedef void (*wdentry4_t)(int argc, wdparm_t arg1, wdparm_t arg2,
* Return Value:
* None
*
* Assumptions:
*
****************************************************************************/
static inline void wd_expiration(void)
@ -211,7 +210,8 @@ static inline void wd_expiration(void)
* parm1..4 - parameters to pass to wdentry
*
* Return Value:
* OK or ERROR
* Zero (OK) is returned on success; a negated errno value is return to
* indicate the nature of any failure.
*
* Assumptions:
* The watchdog routine runs in the context of the timer interrupt handler
@ -229,12 +229,11 @@ int wd_start(WDOG_ID wdog, int32_t delay, wdentry_t wdentry, int argc, ...)
irqstate_t flags;
int i;
/* Verify the wdog */
/* Verify the wdog and setup parameters */
if (!wdog || argc > CONFIG_MAX_WDOGPARMS || delay < 0)
if (wdog == NULL || argc > CONFIG_MAX_WDOGPARMS || delay < 0)
{
set_errno(EINVAL);
return ERROR;
return -EINVAL;
}
/* Check if the watchdog has been started. If so, stop it.