Thread (2 messages) 2 messages, 2 authors, 2020-12-03

Re: [PATCH] ext4: do the quotafile name safe check before allocating new string

From: "Theodore Y. Ts'o" <tytso@mit.edu>
Date: 2020-12-03 14:56:32

On Mon, Oct 26, 2020 at 10:43:17PM +0800, xiakaixu1987@gmail.com wrote:
From: Kaixu Xia <redacted>

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help