[PATCH v5 3/3] ubifs: avoid redundant calls to memset()
Zhihao Cheng
chengzhihao1 at huawei.com
Wed Apr 15 20:52:08 PDT 2026
在 2026/4/15 15:18, Dmitry Antipov 写道:
> Rely on partial implicit initialization of 'struct ubifs_budget_req'
> objects and so simplify 'ubifs_release_dirty_inode_budget()', 'do_rename()'
> and 'do_truncation()' by dropping explicit calls to 'memset()'.
>
> Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
> ---
> v5: initial version to join the series
> ---
> fs/ubifs/budget.c | 9 ++++-----
> fs/ubifs/dir.c | 4 +---
> fs/ubifs/file.c | 10 +++++-----
> 3 files changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c
> index d76eb7b39f56..a73f1e969f7c 100644
> --- a/fs/ubifs/budget.c
> +++ b/fs/ubifs/budget.c
> @@ -590,11 +590,10 @@ void ubifs_convert_page_budget(struct ubifs_info *c)
> void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
> struct ubifs_inode *ui)
> {
> - struct ubifs_budget_req req;
> -
> - memset(&req, 0, sizeof(struct ubifs_budget_req));
> - /* The "no space" flags will be cleared because dd_growth is > 0 */
> - req.dd_growth = c->bi.inode_budget + ALIGN(ui->data_len, 8);
> + struct ubifs_budget_req req = {
> + /* The "no space" flags will be cleared because dd_growth is > 0 */
> + .dd_growth = c->bi.inode_budget + ALIGN(ui->data_len, 8)
> + };
> ubifs_release_budget(c, &req);
> }
>
> diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
> index 86d41e077e4d..c1602e8aff01 100644
> --- a/fs/ubifs/dir.c
> +++ b/fs/ubifs/dir.c
> @@ -1335,7 +1335,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
> .dirtied_ino = 3 };
> struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
> .dirtied_ino_d = ALIGN(old_inode_ui->data_len, 8) };
> - struct ubifs_budget_req wht_req;
> + struct ubifs_budget_req wht_req = { .new_ino = 1 };
> unsigned int saved_nlink;
> struct fscrypt_name old_nm, new_nm;
>
> @@ -1422,8 +1422,6 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
> whiteout_ui->data_len = ubifs_encode_dev(dev, MKDEV(0, 0));
> ubifs_assert(c, !whiteout_ui->dirty);
>
> - memset(&wht_req, 0, sizeof(struct ubifs_budget_req));
> - wht_req.new_ino = 1;
> wht_req.new_ino_d = ALIGN(whiteout_ui->data_len, 8);
> /*
> * To avoid deadlock between space budget (holds ui_mutex and
I prefer to keep the orginal logic for do_rename(). it makes 'whiteout'
and 'wht_req' be initialized in the same code block, which is more readable.
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index e73c28b12f97..35061a587e3c 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -1101,13 +1101,16 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
> const struct iattr *attr)
> {
> int err;
> - struct ubifs_budget_req req;
> + struct ubifs_budget_req req = {
> + .dirtied_ino = 1,
> + /* A funny way to budget for truncation node */
> + .dirtied_ino_d = UBIFS_TRUN_NODE_SZ
> + };
> loff_t old_size = inode->i_size, new_size = attr->ia_size;
> int offset = new_size & (UBIFS_BLOCK_SIZE - 1), budgeted = 1;
> struct ubifs_inode *ui = ubifs_inode(inode);
>
> dbg_gen("ino %llu, size %lld -> %lld", inode->i_ino, old_size, new_size);
> - memset(&req, 0, sizeof(struct ubifs_budget_req));
>
> /*
> * If this is truncation to a smaller size, and we do not truncate on a
> @@ -1117,9 +1120,6 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
> if (new_size & (UBIFS_BLOCK_SIZE - 1))
> req.dirtied_page = 1;
>
> - req.dirtied_ino = 1;
> - /* A funny way to budget for truncation node */
> - req.dirtied_ino_d = UBIFS_TRUN_NODE_SZ;
> err = ubifs_budget_space(c, &req);
> if (err) {
> /*
>
More information about the linux-mtd
mailing list