linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: xiakaixu1987@gmail.com
Cc: linux-ext4@vger.kernel.org, adilger.kernel@dilger.ca,
	Kaixu Xia <kaixuxia@tencent.com>
Subject: Re: [PATCH] ext4: do the quotafile name safe check before allocating new string
Date: Thu, 3 Dec 2020 09:28:33 -0500	[thread overview]
Message-ID: <20201203142833.GI441757@mit.edu> (raw)
In-Reply-To: <1603723397-14344-1-git-send-email-kaixuxia@tencent.com>

On Mon, Oct 26, 2020 at 10:43:17PM +0800, xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> Now we do the quotafile name safe check after allocating the new string
> by using kmalloc(), and have to release the string with kfree() if check
> fails. Maybe we can check them before allocating memory and directly
> return error if check fails to avoid the unnecessary kmalloc()/kfree()
> operations.
> 
> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> ---
>  fs/ext4/super.c | 29 +++++++++++++----------------
>  1 file changed, 13 insertions(+), 16 deletions(-)

This patch reduces the line count by 3, which is good, but...

(a) It makes the code more complex, harder to read, and harder to be
    sure things are correct:

compare:

> -		if (strcmp(old_qname, qname) == 0)

with

> +		if (strlen(old_qname) != args->to - args->from ||
> +		    strncmp(old_qname, args->from, args->to - args->from)) {

(b) This is optimizing the error path, which is uncommon, and saving
    the allocation and free is not really worth trading off making the code
    slightly harder to read and maintain.

So I don't think taking this patch is worthwhile.

Cheers,

					- Ted

      reply	other threads:[~2020-12-03 14:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 14:43 [PATCH] ext4: do the quotafile name safe check before allocating new string xiakaixu1987
2020-12-03 14:28 ` Theodore Y. Ts'o [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=20201203142833.GI441757@mit.edu \
    --to=tytso@mit.edu \
    --cc=adilger.kernel@dilger.ca \
    --cc=kaixuxia@tencent.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=xiakaixu1987@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).