diff --git a/drivers/spi/spi_driver.c b/drivers/spi/spi_driver.c index 23dbad4970..0774dcd956 100644 --- a/drivers/spi/spi_driver.c +++ b/drivers/spi/spi_driver.c @@ -116,16 +116,16 @@ static const struct file_operations g_spidrvr_fops = #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS static int spidrvr_open(FAR struct file *filep) { - FAR struct inode *inode; FAR struct spi_driver_s *priv; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); + /* Get our private data structure */ - inode = filep->f_inode; - - priv = inode->i_private; - DEBUGASSERT(priv); + priv = filep->f_inode->i_private; /* Get exclusive access to the SPI driver state structure */ @@ -152,16 +152,16 @@ static int spidrvr_open(FAR struct file *filep) #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS static int spidrvr_close(FAR struct file *filep) { - FAR struct inode *inode; FAR struct spi_driver_s *priv; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); + /* Get our private data structure */ - inode = filep->f_inode; - - priv = inode->i_private; - DEBUGASSERT(priv); + priv = filep->f_inode->i_private; /* Get exclusive access to the SPI driver state structure */ @@ -184,6 +184,7 @@ static int spidrvr_close(FAR struct file *filep) { nxmutex_destroy(&priv->lock); kmm_free(priv); + filep->f_inode->i_private = NULL; return OK; } @@ -218,19 +219,18 @@ static ssize_t spidrvr_write(FAR struct file *filep, FAR const char *buffer, static int spidrvr_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { - FAR struct inode *inode; FAR struct spi_driver_s *priv; FAR struct spi_sequence_s *seq; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); spiinfo("cmd=%d arg=%lu\n", cmd, arg); /* Get our private data structure */ - inode = filep->f_inode; - - priv = inode->i_private; - DEBUGASSERT(priv); + priv = filep->f_inode->i_private; /* Get exclusive access to the SPI driver state structure */ @@ -305,6 +305,7 @@ static int spidrvr_unlink(FAR struct inode *inode) { nxmutex_destroy(&priv->lock); kmm_free(priv); + inode->i_private = NULL; return OK; } diff --git a/drivers/spi/spi_slave_driver.c b/drivers/spi/spi_slave_driver.c index c80ab1ed39..1e33b4f242 100644 --- a/drivers/spi/spi_slave_driver.c +++ b/drivers/spi/spi_slave_driver.c @@ -174,18 +174,17 @@ static const struct spi_slave_devops_s g_spisdev_ops = static int spi_slave_open(FAR struct file *filep) { - FAR struct inode *inode; FAR struct spi_slave_driver_s *priv; int ret; - DEBUGASSERT(filep->f_inode->i_private != NULL); + /* Sanity check */ + DEBUGASSERT(filep->f_inode->i_private != NULL); spiinfo("filep: %p\n", filep); /* Get our private data structure */ - inode = filep->f_inode; - priv = inode->i_private; + priv = filep->f_inode->i_private; /* Get exclusive access to the SPI Slave driver state structure */ @@ -229,18 +228,17 @@ static int spi_slave_open(FAR struct file *filep) static int spi_slave_close(FAR struct file *filep) { - FAR struct inode *inode; FAR struct spi_slave_driver_s *priv; int ret; - DEBUGASSERT(filep->f_inode->i_private != NULL); + /* Sanity check */ + DEBUGASSERT(filep->f_inode->i_private != NULL); spiinfo("filep: %p\n", filep); /* Get our private data structure */ - inode = filep->f_inode; - priv = inode->i_private; + priv = filep->f_inode->i_private; /* Get exclusive access to the SPI Slave driver state structure */ @@ -273,7 +271,7 @@ static int spi_slave_close(FAR struct file *filep) { nxmutex_destroy(&priv->lock); kmm_free(priv); - inode->i_private = NULL; + filep->f_inode->i_private = NULL; return OK; } @@ -302,18 +300,19 @@ static int spi_slave_close(FAR struct file *filep) static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { - FAR struct inode *inode; FAR struct spi_slave_driver_s *priv; size_t read_bytes; size_t remaining_words; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen); /* Get our private data structure */ - inode = filep->f_inode; - priv = inode->i_private; + priv = filep->f_inode->i_private; if (buffer == NULL) { @@ -394,17 +393,18 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer, static ssize_t spi_slave_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { - FAR struct inode *inode; FAR struct spi_slave_driver_s *priv; size_t enqueued_bytes; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen); /* Get our private data structure */ - inode = filep->f_inode; - priv = inode->i_private; + priv = filep->f_inode->i_private; ret = nxmutex_lock(&priv->lock); if (ret < 0) @@ -453,13 +453,15 @@ static int spi_slave_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) { FAR struct spi_slave_driver_s *priv; - FAR struct inode *inode; int ret; + /* Sanity check */ + + DEBUGASSERT(filep->f_inode->i_private != NULL); + /* Get our private data structure */ - inode = filep->f_inode; - priv = inode->i_private; + priv = filep->f_inode->i_private; ret = nxmutex_lock(&priv->lock); if (ret < 0) @@ -525,6 +527,8 @@ static int spi_slave_unlink(FAR struct inode *inode) FAR struct spi_slave_driver_s *priv; int ret; + /* Sanity check */ + DEBUGASSERT(inode->i_private != NULL); /* Get our private data structure */