mtd/mtd_config: add mtdconfig_register_by_path/mtdconfig_unregister_by_path api

mtd_config/mtd_config_nvs should all support
mtdconfig_register_by_path/mtdconfig_unregister_by_path api

Signed-off-by: zhaoxingyu1 <zhaoxingyu1@xiaomi.com>
This commit is contained in:
zhaoxingyu1 2025-05-15 01:04:00 +08:00 committed by Donny(董九柱)
parent e4a73edec8
commit 0e1dd46f3b

View file

@ -1730,14 +1730,15 @@ static int mtdconfig_poll(FAR struct file *filep, FAR struct pollfd *fds,
****************************************************************************/
/****************************************************************************
* Name: mtdconfig_register
* Name: mtdconfig_register_by_path
*
* Description:
* Register a /dev/config device backed by an MTD
* Register a "path" device backed by an MTD
*
****************************************************************************/
int mtdconfig_register(FAR struct mtd_dev_s *mtd)
int mtdconfig_register_by_path(FAR struct mtd_dev_s *mtd,
FAR const char *path)
{
int ret = -ENOMEM;
struct mtdconfig_struct_s *dev;
@ -1782,13 +1783,60 @@ int mtdconfig_register(FAR struct mtd_dev_s *mtd)
}
nxmutex_init(&dev->lock);
register_driver("/dev/config", &g_mtdconfig_fops, 0666, dev);
register_driver(path, &g_mtdconfig_fops, 0666, dev);
}
errout:
return ret;
}
/****************************************************************************
* Name: mtdconfig_register
*
* Description:
* Register a /dev/config device backed by an MTD
*
****************************************************************************/
int mtdconfig_register(FAR struct mtd_dev_s *mtd)
{
return mtdconfig_register_by_path(mtd, "/dev/config");
}
/****************************************************************************
* Name: mtdconfig_unregister_by_path
*
* Description:
* Unregister a "path" device backed by a MTD.
*
****************************************************************************/
int mtdconfig_unregister_by_path(FAR const char *path)
{
int ret;
struct file file;
FAR struct inode *inode;
FAR struct mtdconfig_struct_s *dev;
ret = file_open(&file, path, O_CLOEXEC);
if (ret < 0)
{
ferr("ERROR: open %s failed: %d\n", path, ret);
return ret;
}
inode = file.f_inode;
dev = inode->i_private;
nxmutex_destroy(&dev->lock);
kmm_free(dev);
file_close(&file);
unregister_driver(path);
return OK;
}
/****************************************************************************
* Name: mtdconfig_unregister
*
@ -1799,28 +1847,7 @@ errout:
int mtdconfig_unregister(void)
{
int ret;
struct file file;
FAR struct inode *inode;
FAR struct mtdconfig_struct_s *dev;
ret = file_open(&file, "/dev/config", O_CLOEXEC);
if (ret < 0)
{
ferr("ERROR: open /dev/config failed: %d\n", ret);
return ret;
}
inode = file.f_inode;
dev = inode->i_private;
nxmutex_destroy(&dev->lock);
kmm_free(dev);
file_close(&file);
unregister_driver("/dev/config");
return OK;
return mtdconfig_unregister_by_path("/dev/config");
}
#endif /* CONFIG_MTD_CONFIG */