mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
spi: Optimize access to private data
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
a6cea0d82e
commit
2bf13ffbb0
+16
-15
@@ -116,16 +116,16 @@ static const struct file_operations g_spidrvr_fops =
|
|||||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||||
static int spidrvr_open(FAR struct file *filep)
|
static int spidrvr_open(FAR struct file *filep)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_driver_s *priv;
|
FAR struct spi_driver_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
|
|
||||||
priv = inode->i_private;
|
|
||||||
DEBUGASSERT(priv);
|
|
||||||
|
|
||||||
/* Get exclusive access to the SPI driver state structure */
|
/* 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
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||||
static int spidrvr_close(FAR struct file *filep)
|
static int spidrvr_close(FAR struct file *filep)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_driver_s *priv;
|
FAR struct spi_driver_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
|
|
||||||
priv = inode->i_private;
|
|
||||||
DEBUGASSERT(priv);
|
|
||||||
|
|
||||||
/* Get exclusive access to the SPI driver state structure */
|
/* 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);
|
nxmutex_destroy(&priv->lock);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
|
filep->f_inode->i_private = NULL;
|
||||||
return OK;
|
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)
|
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_driver_s *priv;
|
||||||
FAR struct spi_sequence_s *seq;
|
FAR struct spi_sequence_s *seq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
spiinfo("cmd=%d arg=%lu\n", cmd, arg);
|
spiinfo("cmd=%d arg=%lu\n", cmd, arg);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
|
|
||||||
priv = inode->i_private;
|
|
||||||
DEBUGASSERT(priv);
|
|
||||||
|
|
||||||
/* Get exclusive access to the SPI driver state structure */
|
/* 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);
|
nxmutex_destroy(&priv->lock);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
|
inode->i_private = NULL;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -174,18 +174,17 @@ static const struct spi_slave_devops_s g_spisdev_ops =
|
|||||||
|
|
||||||
static int spi_slave_open(FAR struct file *filep)
|
static int spi_slave_open(FAR struct file *filep)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
spiinfo("filep: %p\n", filep);
|
spiinfo("filep: %p\n", filep);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
priv = inode->i_private;
|
|
||||||
|
|
||||||
/* Get exclusive access to the SPI Slave driver state structure */
|
/* 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)
|
static int spi_slave_close(FAR struct file *filep)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
spiinfo("filep: %p\n", filep);
|
spiinfo("filep: %p\n", filep);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
priv = inode->i_private;
|
|
||||||
|
|
||||||
/* Get exclusive access to the SPI Slave driver state structure */
|
/* 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);
|
nxmutex_destroy(&priv->lock);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
inode->i_private = NULL;
|
filep->f_inode->i_private = NULL;
|
||||||
return OK;
|
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,
|
static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
|
||||||
size_t buflen)
|
size_t buflen)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
size_t read_bytes;
|
size_t read_bytes;
|
||||||
size_t remaining_words;
|
size_t remaining_words;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen);
|
spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
priv = inode->i_private;
|
|
||||||
|
|
||||||
if (buffer == NULL)
|
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,
|
static ssize_t spi_slave_write(FAR struct file *filep,
|
||||||
FAR const char *buffer, size_t buflen)
|
FAR const char *buffer, size_t buflen)
|
||||||
{
|
{
|
||||||
FAR struct inode *inode;
|
|
||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
size_t enqueued_bytes;
|
size_t enqueued_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen);
|
spiinfo("filep=%p buffer=%p buflen=%zu\n", filep, buffer, buflen);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
priv = inode->i_private;
|
|
||||||
|
|
||||||
ret = nxmutex_lock(&priv->lock);
|
ret = nxmutex_lock(&priv->lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -453,13 +453,15 @@ static int spi_slave_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||||||
bool setup)
|
bool setup)
|
||||||
{
|
{
|
||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
FAR struct inode *inode;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
|
DEBUGASSERT(filep->f_inode->i_private != NULL);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
priv = filep->f_inode->i_private;
|
||||||
priv = inode->i_private;
|
|
||||||
|
|
||||||
ret = nxmutex_lock(&priv->lock);
|
ret = nxmutex_lock(&priv->lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -525,6 +527,8 @@ static int spi_slave_unlink(FAR struct inode *inode)
|
|||||||
FAR struct spi_slave_driver_s *priv;
|
FAR struct spi_slave_driver_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
|
||||||
DEBUGASSERT(inode->i_private != NULL);
|
DEBUGASSERT(inode->i_private != NULL);
|
||||||
|
|
||||||
/* Get our private data structure */
|
/* Get our private data structure */
|
||||||
|
|||||||
Reference in New Issue
Block a user