]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
apparmor: Return directly after a failed kzalloc() in two functions
authorMarkus Elfring <elfring@users.sourceforge.net>
Wed, 29 Mar 2023 09:50:44 +0000 (11:50 +0200)
committerJohn Johansen <john.johansen@canonical.com>
Thu, 6 Jul 2023 17:58:49 +0000 (10:58 -0700)
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>
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/crypto.c

index b498ed3024610f406d15a204fec2c650bc8c1ac8..6724e2ff6da8900127a19ea609fabf81764e12a0 100644 (file)
@@ -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;