1
0
Fork 0
forked from nuttx/nuttx-update

drivers/mtd/mtd_config: switch from semaphore to mutex for exclusive access

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2023-01-25 22:58:40 +02:00 committed by Xiang Xiao
parent 6e3cb04531
commit e3a8e1e3ef

View file

@ -42,6 +42,7 @@
#include <debug.h>
#include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/mtd/mtd.h>
@ -72,7 +73,7 @@
struct mtdconfig_struct_s
{
FAR struct mtd_dev_s *mtd; /* Contained MTD interface */
sem_t exclsem; /* Supports mutual exclusion */
mutex_t lock; /* Supports mutual exclusion */
uint32_t blocksize; /* Size of blocks in contained MTD */
uint32_t erasesize; /* Size of erase block in contained MTD */
size_t nblocks; /* Number of blocks available */
@ -1004,7 +1005,7 @@ errout:
* Name: mtdconfig_open
****************************************************************************/
static int mtdconfig_open(FAR struct file *filep)
static int mtdconfig_open(FAR struct file *filep)
{
FAR struct inode *inode = filep->f_inode;
FAR struct mtdconfig_struct_s *dev = inode->i_private;
@ -1012,7 +1013,7 @@ static int mtdconfig_open(FAR struct file *filep)
/* Get exclusive access to the device */
ret = nxsem_wait(&dev->exclsem);
ret = nxmutex_lock(&dev->lock);
if (ret < 0)
{
ferr("ERROR: nxsem_wait failed: %d\n", ret);
@ -1036,7 +1037,7 @@ static int mtdconfig_close(FAR struct file *filep)
/* Release exclusive access to the device */
nxsem_post(&dev->exclsem);
nxmutex_unlock(&dev->lock);
return OK;
}
@ -1774,7 +1775,7 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
goto errout;
}
nxsem_init(&dev->exclsem, 0, 1);
nxmutex_init(&dev->lock);
register_driver("/dev/config", &mtdconfig_fops, 0666, dev);
}
@ -1806,7 +1807,7 @@ int mtdconfig_unregister(void)
inode = file.f_inode;
dev = (FAR struct mtdconfig_struct_s *)inode->i_private;
nxsem_destroy(&dev->exclsem);
nxmutex_destroy(&dev->lock);
kmm_free(dev);
file_close(&file);