From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org,
linux-security-module@vger.kernel.org, apparmor@lists.ubuntu.com,
James Morris <jmorris@namei.org>,
John Johansen <john.johansen@canonical.com>,
Paul Moore <paul@paul-moore.com>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: [cocci] [PATCH] apparmor: Return directly after a failed kzalloc() in two functions
Date: Wed, 29 Mar 2023 12:12:23 +0200 [thread overview]
Message-ID: <d33ebeca-0900-8c6c-ac44-f301daf24a5b@web.de> (raw)
In-Reply-To: <6cbcf640-55e5-2f11-4a09-716fe681c0d2@web.de>
Date: Wed, 29 Mar 2023 11:50:44 +0200
1. Return directly after a call of the function “kzalloc” failed
at the beginning in these function implementations.
2. Omit extra initialisations (for a few local variables)
which became unnecessary with this refactoring.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
security/apparmor/crypto.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/security/apparmor/crypto.c b/security/apparmor/crypto.c
index b498ed302461..6724e2ff6da8 100644
--- a/security/apparmor/crypto.c
+++ b/security/apparmor/crypto.c
@@ -28,15 +28,15 @@ unsigned int aa_hash_size(void)
char *aa_calc_hash(void *data, size_t len)
{
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
- char *hash = NULL;
- int error = -ENOMEM;
+ char *hash;
+ int error;
if (!apparmor_tfm)
return NULL;
hash = kzalloc(apparmor_hash_size, GFP_KERNEL);
if (!hash)
- goto fail;
+ return ERR_PTR(-ENOMEM);
desc->tfm = apparmor_tfm;
@@ -62,7 +62,7 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
size_t len)
{
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
- int error = -ENOMEM;
+ int error;
__le32 le32_version = cpu_to_le32(version);
if (!aa_g_hash_policy)
@@ -73,7 +73,7 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
profile->hash = kzalloc(apparmor_hash_size, GFP_KERNEL);
if (!profile->hash)
- goto fail;
+ return -ENOMEM;
desc->tfm = apparmor_tfm;
--
2.40.0
next prev parent reply other threads:[~2023-03-29 10:13 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 15:55 [cocci] Reconsidering kfree() calls for null pointers (with SmPL) Markus Elfring
2023-03-28 16:05 ` Vlastimil Babka
2023-03-29 6:18 ` Markus Elfring
2023-03-29 7:25 ` Vlastimil Babka
2023-03-28 17:13 ` [cocci] [PATCH 0/2] ARM: Adjustments for init_atags_procfs() Markus Elfring
2023-03-28 17:15 ` [cocci] [PATCH 1/2] ARM: Delete an error message for a failed memory allocation in init_atags_procfs() Markus Elfring
2023-03-28 17:17 ` [cocci] [PATCH 2/2] ARM: Return directly after a failed kmalloc() " Markus Elfring
2024-01-10 11:48 ` [cocci] [PATCH 0/2] ARM: Adjustments for init_atags_procfs() Markus Elfring
2024-01-10 11:52 ` [cocci] [0/2] " Markus Elfring
[not found] ` <ZZ6MZl14bcIaCaQn@shell.armlinux.org.uk>
2024-01-10 12:44 ` Markus Elfring
[not found] ` <ZZ6R6KSQo9ph3ARZ@shell.armlinux.org.uk>
2024-01-10 12:52 ` Markus Elfring
[not found] ` <ZZ6gq5sOFf33GhM7@shell.armlinux.org.uk>
2024-01-10 14:00 ` Markus Elfring
[not found] ` <vltzbtbcuzrfgjoeg5oovdyoe34fnhte25uhb3gln56pzvmqzb@5u7u7cwgzzen>
2024-01-10 13:46 ` Markus Elfring
2023-03-28 18:45 ` [cocci] [PATCH 0/2] perf/x86/intel/pt: Adjustments for pt_pmu_hw_init() Markus Elfring
2023-03-28 18:50 ` [cocci] [PATCH 1/2] perf/x86/intel/pt: Use -ENOMEM directly for a return statement in pt_pmu_hw_init() Markus Elfring
2023-03-28 18:52 ` [cocci] [PATCH 2/2] perf/x86/intel/pt: Return directly after a failed kzalloc() " Markus Elfring
2024-01-10 11:45 ` [cocci] [PATCH 0/2] perf/x86/intel/pt: Adjustments for pt_pmu_hw_init() Markus Elfring
2023-03-29 10:12 ` Markus Elfring [this message]
2023-03-29 13:36 ` [cocci] [PATCH 0/3] lru_cache: Adjustments for lc_create() Markus Elfring
2023-03-29 13:40 ` [cocci] [PATCH 1/3] lru_cache: Return directly after a failed kzalloc() in lc_create() Markus Elfring
2023-03-29 13:42 ` [cocci] [PATCH 2/3] lru_cache: Improve two size determinations " Markus Elfring
2023-03-29 13:44 ` [cocci] [PATCH 3/3] lru_cache: Improve exception handling " Markus Elfring
2024-01-10 11:40 ` [cocci] [PATCH 0/3] lru_cache: Adjustments for lc_create() Markus Elfring
2023-03-29 15:46 ` [cocci] [PATCH] io_uring: Fix exception handling in io_ring_ctx_alloc() Markus Elfring
2024-01-10 11:23 ` [cocci] " Markus Elfring
2024-01-10 16:55 ` [cocci] [PATCH] " Gabriel Krisman Bertazi
2023-03-30 8:50 ` [cocci] [PATCH 0/4] overlayfs: Adjustments for ovl_fill_super() Markus Elfring
2023-03-30 8:55 ` [cocci] [PATCH 1/4] overlayfs: Return directly for two checks in ovl_fill_super() Markus Elfring
2023-03-30 8:57 ` [cocci] [PATCH 2/4] overlayfs: Improve two size determinations " Markus Elfring
2023-03-30 9:00 ` [cocci] [PATCH 3/4] overlayfs: Improve exception handling " Markus Elfring
2023-03-30 9:02 ` [cocci] [PATCH 4/4] overlayfs: Move some assignments for the variable “err” " Markus Elfring
2024-01-10 12:24 ` [cocci] [PATCH 0/4] overlayfs: Adjustments for ovl_fill_super() Markus Elfring
[not found] ` <CAOQ4uxiRaTQyT1nxeRD7B89=VuA+KKEqi01LL1kqfJ17-qKKpw@mail.gmail.com>
2024-01-10 13:01 ` [cocci] [0/4] " Markus Elfring
[not found] ` <CAOQ4uxjsuYy8BzgaHXaNa-S0+HZ_P-Fb1UEgOkbrdxQPz0Y6rQ@mail.gmail.com>
2024-01-10 13:33 ` Markus Elfring
2023-03-30 16:18 ` [cocci] [PATCH] squashfs: Improve exception handling in squashfs_decompressor_create() Markus Elfring
2024-01-05 20:32 ` Markus Elfring
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=d33ebeca-0900-8c6c-ac44-f301daf24a5b@web.de \
--to=markus.elfring@web.de \
--cc=apparmor@lists.ubuntu.com \
--cc=cocci@inria.fr \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.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).