public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Dmitry Antipov <dmantipov@yandex.ru>,
	Richard Weinberger <richard@nod.at>
Cc: <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH v5 3/3] ubifs: avoid redundant calls to memset()
Date: Thu, 16 Apr 2026 11:52:08 +0800	[thread overview]
Message-ID: <91ddedbd-9df3-8d9e-2928-3ba090a4ee2b@huawei.com> (raw)
In-Reply-To: <20260415071812.1139054-3-dmantipov@yandex.ru>

在 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@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) {
>   		/*
> 


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-04-16  3:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  7:18 [PATCH v5 1/3] ubifs: prefer kstrtobool_from_user() over custom helper Dmitry Antipov
2026-04-15  7:18 ` [PATCH v5 2/3] ubifs: use strscpy() and kmemdup_nul() where appropriate Dmitry Antipov
2026-04-16  3:37   ` Zhihao Cheng
2026-04-16  5:09     ` Dmitry Antipov
2026-04-16  6:41       ` Zhihao Cheng
2026-04-15  7:18 ` [PATCH v5 3/3] ubifs: avoid redundant calls to memset() Dmitry Antipov
2026-04-16  3:52   ` Zhihao Cheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=91ddedbd-9df3-8d9e-2928-3ba090a4ee2b@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=dmantipov@yandex.ru \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox