fs/vfs: Zero file struct field with memset
to avoid set fields to zero one by one Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
22d6f97843
commit
17f173d555
|
@ -253,10 +253,9 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
|
|||
|
||||
/* Associate the inode with a file structure */
|
||||
|
||||
mq->f_oflags = oflags;
|
||||
mq->f_pos = 0;
|
||||
mq->f_inode = inode;
|
||||
mq->f_priv = NULL;
|
||||
memset(mq, 0, sizeof(*mq));
|
||||
mq->f_oflags = oflags;
|
||||
mq->f_inode = inode;
|
||||
|
||||
if (created)
|
||||
{
|
||||
|
@ -303,10 +302,9 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
|
|||
|
||||
/* Associate the inode with a file structure */
|
||||
|
||||
mq->f_oflags = oflags;
|
||||
mq->f_pos = 0;
|
||||
mq->f_inode = inode;
|
||||
mq->f_priv = NULL;
|
||||
memset(mq, 0, sizeof(*mq));
|
||||
mq->f_oflags = oflags;
|
||||
mq->f_inode = inode;
|
||||
|
||||
INODE_SET_MQUEUE(inode);
|
||||
inode->u.i_ops = &g_nxmq_fileops;
|
||||
|
|
|
@ -607,8 +607,8 @@ ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer,
|
|||
|
||||
/* Success.. return the number of bytes written */
|
||||
|
||||
ret = total;
|
||||
filep->f_pos = wrfile->datlen;
|
||||
ret = total;
|
||||
filep->f_pos = wrfile->datlen;
|
||||
|
||||
errout_with_lock:
|
||||
nxmutex_unlock(&volume->lock);
|
||||
|
|
|
@ -141,10 +141,9 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name,
|
|||
|
||||
/* Associate the inode with a file structure */
|
||||
|
||||
memset(shm, 0, sizeof(*shm));
|
||||
shm->f_oflags = oflags;
|
||||
shm->f_pos = 0;
|
||||
shm->f_inode = inode;
|
||||
shm->f_priv = NULL;
|
||||
|
||||
errout_with_sem:
|
||||
inode_unlock();
|
||||
|
|
|
@ -869,7 +869,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||
/* Allocate a container to hold the open file system information */
|
||||
|
||||
uf = (FAR struct unionfs_file_s *)
|
||||
kmm_malloc(sizeof(struct unionfs_file_s));
|
||||
kmm_zalloc(sizeof(struct unionfs_file_s));
|
||||
if (uf == NULL)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
|
@ -883,9 +883,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||
um->um_node->u.i_mops != NULL);
|
||||
|
||||
uf->uf_file.f_oflags = filep->f_oflags;
|
||||
uf->uf_file.f_pos = 0;
|
||||
uf->uf_file.f_inode = um->um_node;
|
||||
uf->uf_file.f_priv = NULL;
|
||||
|
||||
ret = unionfs_tryopen(&uf->uf_file, relpath, um->um_prefix, oflags, mode);
|
||||
if (ret >= 0)
|
||||
|
@ -901,9 +899,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath,
|
|||
um = &ui->ui_fs[1];
|
||||
|
||||
uf->uf_file.f_oflags = filep->f_oflags;
|
||||
uf->uf_file.f_pos = 0;
|
||||
uf->uf_file.f_inode = um->um_node;
|
||||
uf->uf_file.f_priv = NULL;
|
||||
|
||||
ret = unionfs_tryopen(&uf->uf_file, relpath, um->um_prefix, oflags,
|
||||
mode);
|
||||
|
|
|
@ -80,10 +80,7 @@ int file_close(FAR struct file *filep)
|
|||
|
||||
/* Reset the user file struct instance so that it cannot be reused. */
|
||||
|
||||
filep->f_oflags = 0;
|
||||
filep->f_pos = 0;
|
||||
filep->f_inode = NULL;
|
||||
filep->f_priv = NULL;
|
||||
memset(filep, 0, sizeof(*filep));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -607,8 +607,8 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath)
|
|||
return ret;
|
||||
}
|
||||
|
||||
filep->f_inode = &g_dir_inode;
|
||||
filep->f_priv = dir;
|
||||
filep->f_inode = &g_dir_inode;
|
||||
filep->f_priv = dir;
|
||||
inode_addref(&g_dir_inode);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -79,10 +79,10 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
|
|||
|
||||
/* Then clone the file structure */
|
||||
|
||||
memset(&temp, 0, sizeof(temp));
|
||||
temp.f_oflags = filep1->f_oflags;
|
||||
temp.f_pos = filep1->f_pos;
|
||||
temp.f_inode = inode;
|
||||
temp.f_priv = NULL;
|
||||
|
||||
/* Call the open method on the file, driver, mountpoint so that it
|
||||
* can maintain the correct open counts.
|
||||
|
|
|
@ -156,10 +156,9 @@ static int file_vopen(FAR struct file *filep, FAR const char *path,
|
|||
|
||||
/* Associate the inode with a file structure */
|
||||
|
||||
memset(filep, 0, sizeof(*filep));
|
||||
filep->f_oflags = oflags;
|
||||
filep->f_pos = 0;
|
||||
filep->f_inode = inode;
|
||||
filep->f_priv = NULL;
|
||||
|
||||
/* Perform the driver open operation. NOTE that the open method may be
|
||||
* called many times. The driver/mountpoint logic should handle this
|
||||
|
|
Loading…
Reference in New Issue