From: Kees Cook <keescook@chromium.org>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-hardening@vger.kernel.org, kernel-janitors@vger.kernel.org,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
Tony Luck <tony.luck@intel.com>,
LKML <linux-kernel@vger.kernel.org>,
Kunwu Chan <chentao@kylinos.cn>
Subject: Re: [PATCH] pstore/ram_core: Improve exception handling in persistent_ram_new()
Date: Thu, 1 Feb 2024 10:13:50 -0800 [thread overview]
Message-ID: <202402011013.025B9EDDC@keescook> (raw)
In-Reply-To: <14171fc4-8157-4919-86b8-bdec0493197d@web.de>
On Thu, Jan 18, 2024 at 03:06:53PM +0100, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 18 Jan 2024 14:57:21 +0100
>
> * Omit an initialisation (for the variable “ret”)
> which became unnecessary with this refactoring
> because a memory allocation failure will be directly indicated
> by a corresponding return statement in an if branch.
>
> * Move a call of the function “kstrdup” before two other statements.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Thanks for you patch!
I've decided not to apply it because I prefer having a single exit path
for error handling, and it works as-is already.
-Kees
> ---
> fs/pstore/ram_core.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
> index f1848cdd6d34..5047a8502e17 100644
> --- a/fs/pstore/ram_core.c
> +++ b/fs/pstore/ram_core.c
> @@ -586,21 +586,23 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
> unsigned int memtype, u32 flags, char *label)
> {
> struct persistent_ram_zone *prz;
> - int ret = -ENOMEM;
> + int ret;
>
> prz = kzalloc(sizeof(struct persistent_ram_zone), GFP_KERNEL);
> if (!prz) {
> pr_err("failed to allocate persistent ram zone\n");
> - goto err;
> + return ERR_PTR(-ENOMEM);
> + }
> +
> + prz->label = kstrdup(label, GFP_KERNEL);
> + if (!prz->label) {
> + kfree(prz);
> + return ERR_PTR(-ENOMEM);
> }
>
> /* Initialize general buffer state. */
> raw_spin_lock_init(&prz->buffer_lock);
> prz->flags = flags;
> - prz->label = kstrdup(label, GFP_KERNEL);
> - if (!prz->label)
> - goto err;
> -
> ret = persistent_ram_buffer_map(start, size, prz, memtype);
> if (ret)
> goto err;
> --
> 2.43.0
>
--
Kees Cook
prev parent reply other threads:[~2024-02-01 18:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 14:06 [PATCH] pstore/ram_core: Improve exception handling in persistent_ram_new() Markus Elfring
2024-02-01 18:13 ` Kees Cook [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=202402011013.025B9EDDC@keescook \
--to=keescook@chromium.org \
--cc=Markus.Elfring@web.de \
--cc=chentao@kylinos.cn \
--cc=gpiccoli@igalia.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.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