drivers: fix some bad NULL checks

This commit is contained in:
Juha Niskanen 2017-05-15 07:20:32 -06:00 committed by Gregory Nutt
parent 17e9a88d0d
commit b9a769d65d
8 changed files with 50 additions and 30 deletions

View File

@ -653,6 +653,8 @@ static int null_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
FAR struct null_dev_s *priv = (FAR struct null_dev_s *)dev;
bool done;
DEBUGASSERT(priv && apb && priv->dev.upper);
audinfo("apb=%p curbyte=%d nbytes=%d\n", apb, apb->curbyte, apb->nbytes);
/* Say that we consumed all of the data */
@ -663,10 +665,6 @@ static int null_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
done = ((apb->flags & AUDIO_APB_FINAL) != 0);
/* And return the buffer to the upper level */
DEBUGASSERT(priv && apb && priv->dev.upper);
/* The buffer belongs to to an upper level. Just forward the event to
* the next level up.
*/

View File

@ -201,7 +201,7 @@ static inline int ajoy_takesem(sem_t *sem)
#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS)
static void ajoy_enable(FAR struct ajoy_upperhalf_s *priv)
{
FAR const struct ajoy_lowerhalf_s *lower = priv->au_lower;
FAR const struct ajoy_lowerhalf_s *lower;
FAR struct ajoy_open_s *opriv;
ajoy_buttonset_t press;
ajoy_buttonset_t release;
@ -210,8 +210,9 @@ static void ajoy_enable(FAR struct ajoy_upperhalf_s *priv)
int i;
#endif
DEBUGASSERT(priv && priv->au_lower);
DEBUGASSERT(priv);
lower = priv->au_lower;
DEBUGASSERT(lower);
/* This routine is called both task level and interrupt level, so
* interrupts must be disabled.
@ -295,7 +296,7 @@ static void ajoy_interrupt(FAR const struct ajoy_lowerhalf_s *lower,
static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv)
{
FAR const struct ajoy_lowerhalf_s *lower = priv->au_lower;
FAR const struct ajoy_lowerhalf_s *lower;
FAR struct ajoy_open_s *opriv;
ajoy_buttonset_t sample;
#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS)
@ -308,8 +309,9 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv)
int i;
#endif
DEBUGASSERT(priv && priv->au_lower);
DEBUGASSERT(priv);
lower = priv->au_lower;
DEBUGASSERT(lower);
/* This routine is called both task level and interrupt level, so
* interrupts must be disabled.

View File

@ -201,7 +201,7 @@ static inline int djoy_takesem(sem_t *sem)
#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS)
static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
{
FAR const struct djoy_lowerhalf_s *lower = priv->du_lower;
FAR const struct djoy_lowerhalf_s *lower;
FAR struct djoy_open_s *opriv;
djoy_buttonset_t press;
djoy_buttonset_t release;
@ -210,8 +210,9 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
int i;
#endif
DEBUGASSERT(priv && priv->du_lower);
DEBUGASSERT(priv);
lower = priv->du_lower;
DEBUGASSERT(lower);
/* This routine is called both task level and interrupt level, so
* interrupts must be disabled.
@ -295,7 +296,7 @@ static void djoy_interrupt(FAR const struct djoy_lowerhalf_s *lower,
static void djoy_sample(FAR struct djoy_upperhalf_s *priv)
{
FAR const struct djoy_lowerhalf_s *lower = priv->du_lower;
FAR const struct djoy_lowerhalf_s *lower;
FAR struct djoy_open_s *opriv;
djoy_buttonset_t sample;
#if !defined(CONFIG_DISABLE_POLL) || !defined(CONFIG_DISABLE_SIGNALS)
@ -308,8 +309,9 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv)
int i;
#endif
DEBUGASSERT(priv && priv->du_lower);
DEBUGASSERT(priv);
lower = priv->du_lower;
DEBUGASSERT(lower);
/* This routine is called both task level and interrupt level, so
* interrupts must be disabled.

View File

@ -141,13 +141,16 @@ static int ubxmdm_ioctl(FAR struct file* filep,
unsigned long arg)
{
FAR struct inode* inode = filep->f_inode;
FAR struct ubxmdm_upper* upper = inode->i_private;
FAR struct ubxmdm_lower* lower = upper->lower;
FAR struct ubxmdm_upper* upper;
FAR struct ubxmdm_lower* lower;
int ret;
FAR struct ubxmdm_status* status;
m_info("cmd: %d arg: %ld\n", cmd, arg);
DEBUGASSERT(upper && lower);
upper = inode->i_private;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(lower != NULL);
switch (cmd)
{
@ -320,8 +323,9 @@ void ubxmdm_unregister(FAR void *handle)
FAR struct ubxmdm_lower *lower;
upper = (FAR struct ubxmdm_upper*) handle;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(upper && lower);
DEBUGASSERT(lower != NULL);
m_info("Unregistering: %s\n", upper->path);

View File

@ -318,11 +318,13 @@ static ssize_t pwm_write(FAR struct file *filep, FAR const char *buffer,
#ifdef CONFIG_PWM_PULSECOUNT
static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags)
{
FAR struct pwm_lowerhalf_s *lower = upper->dev;
FAR struct pwm_lowerhalf_s *lower;
irqstate_t flags;
int ret = OK;
DEBUGASSERT(upper != NULL && lower->ops->start != NULL);
DEBUGASSERT(upper != NULL);
lower = upper->dev;
DEBUGASSERT(lower != NULL && lower->ops->start != NULL);
/* Verify that the PWM is not already running */
@ -385,10 +387,12 @@ static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags)
#else
static int pwm_start(FAR struct pwm_upperhalf_s *upper, unsigned int oflags)
{
FAR struct pwm_lowerhalf_s *lower = upper->dev;
FAR struct pwm_lowerhalf_s *lower;
int ret = OK;
DEBUGASSERT(upper != NULL && lower->ops->start != NULL);
DEBUGASSERT(upper != NULL);
lower = upper->dev;
DEBUGASSERT(lower != NULL && lower->ops->start != NULL);
/* Verify that the PWM is not already running */

View File

@ -276,12 +276,15 @@ static ssize_t qe_write(FAR struct file *filep, FAR const char *buffer, size_t b
static int qe_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct qe_upperhalf_s *upper = inode->i_private;
FAR struct qe_lowerhalf_s *lower = upper->lower;
FAR struct qe_upperhalf_s *upper;
FAR struct qe_lowerhalf_s *lower;
int ret;
sninfo("cmd: %d arg: %ld\n", cmd, arg);
DEBUGASSERT(upper && lower);
upper = inode->i_private;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(lower != NULL);
/* Get exclusive access to the device structures */

View File

@ -254,12 +254,15 @@ static ssize_t timer_write(FAR struct file *filep, FAR const char *buffer,
static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct timer_upperhalf_s *upper = inode->i_private;
FAR struct timer_lowerhalf_s *lower = upper->lower;
FAR struct timer_upperhalf_s *upper;
FAR struct timer_lowerhalf_s *lower;
int ret;
tmrinfo("cmd: %d arg: %ld\n", cmd, arg);
DEBUGASSERT(upper && lower);
upper = inode->i_private;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(lower != NULL);
/* Handle built-in ioctl commands */

View File

@ -240,12 +240,15 @@ static ssize_t wdog_write(FAR struct file *filep, FAR const char *buffer, size_t
static int wdog_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct watchdog_upperhalf_s *upper = inode->i_private;
FAR struct watchdog_lowerhalf_s *lower = upper->lower;
FAR struct watchdog_upperhalf_s *upper;
FAR struct watchdog_lowerhalf_s *lower;
int ret;
wdinfo("cmd: %d arg: %ld\n", cmd, arg);
DEBUGASSERT(upper && lower);
upper = inode->i_private;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(lower != NULL);
/* Get exclusive access to the device structures */
@ -533,8 +536,9 @@ void watchdog_unregister(FAR void *handle)
/* Recover the pointer to the upper-half driver state */
upper = (FAR struct watchdog_upperhalf_s *)handle;
DEBUGASSERT(upper != NULL);
lower = upper->lower;
DEBUGASSERT(upper && lower);
DEBUGASSERT(lower != NULL);
wdinfo("Unregistering: %s\n", upper->path);