From: Dan Carpenter <dan.carpenter@linaro.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: Scott Guo <scott_gzh@163.com>,
Phillip Lougher <phillip@squashfs.org.uk>,
Scott Guo <scottzhguo@tencent.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: squashfs: Avoid mem leak in squashfs_fill_super
Date: Tue, 12 Aug 2025 12:20:38 +0300 [thread overview]
Message-ID: <aJsHZmHN2I712xX3@stanley.mountain> (raw)
In-Reply-To: <dceb4471-82d9-48f0-94dc-e9277eadeada@web.de>
On Tue, Aug 12, 2025 at 10:38:59AM +0200, Markus Elfring wrote:
> > Please, don't introduce more of those e_inval, e_nomem labels.
>
> Would you find any other label identifiers more helpful for sharing
> error code assignments according to better exception handling?
Just assign "err = -EINVAL" before the goto everyone else does.
The common kernel error handling style is called an "unwind ladder".
Assigning the error code is not part of the unwind process and it
messes up the top rung of the unwind ladder.
//=================== Good =============================
return 0;
err_free_thing:
free(thing);
return ret;
//=================== Bad ==============================
return 0;
e_inval:
ret = -EINVAL;
free(something);
return ret;
Now imagine you need to add a new free:
//=================== Good =============================
return 0;
err_free_other_thing:
free(other_thing);
err_free_thing:
free(thing);
return ret;
//=================== Bad ==============================
return 0;
e_inval:
ret = -EINVAL;
goto fail;
free_other_thing:
free(other_thing);
fail:
free(something);
return ret;
Also, in places which basically hardcode -EINVAL into of the unwind, then
it's pretty common for later updates to carry on returning -EINVAL even
when it's the wrong error code.
regards,
dan carpenter
next prev parent reply other threads:[~2025-08-12 9:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 6:19 [PATCH] squashfs: Avoid mem leak in squashfs_fill_super scott_gzh
2025-08-11 7:02 ` Markus Elfring
2025-08-12 2:11 ` Scott Guo
2025-08-12 8:18 ` Dan Carpenter
2025-08-12 8:38 ` Markus Elfring
2025-08-12 9:20 ` Dan Carpenter [this message]
2025-08-11 22:35 ` [PATCH] " Phillip Lougher
2025-08-12 2:11 ` Scott Guo
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=aJsHZmHN2I712xX3@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=Markus.Elfring@web.de \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=phillip@squashfs.org.uk \
--cc=scott_gzh@163.com \
--cc=scottzhguo@tencent.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