From: Markus Elfring <Markus.Elfring@web.de>
To: linux-hardening@vger.kernel.org, kernel-janitors@vger.kernel.org,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
Kees Cook <keescook@chromium.org>,
Tony Luck <tony.luck@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] pstore/ram_core: Improve exception handling in persistent_ram_new()
Date: Thu, 18 Jan 2024 15:06:53 +0100 [thread overview]
Message-ID: <14171fc4-8157-4919-86b8-bdec0493197d@web.de> (raw)
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>
---
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
next reply other threads:[~2024-01-18 14:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-18 14:06 Markus Elfring [this message]
2024-02-01 18:13 ` [PATCH] pstore/ram_core: Improve exception handling in persistent_ram_new() Kees Cook
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=14171fc4-8157-4919-86b8-bdec0493197d@web.de \
--to=markus.elfring@web.de \
--cc=chentao@kylinos.cn \
--cc=gpiccoli@igalia.com \
--cc=keescook@chromium.org \
--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