Skip to content

Commit 6d74679

Browse files
elfringjrjohansen
authored andcommitted
apparmor: Return directly after a failed kzalloc() in two functions
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 <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 755a22c commit 6d74679

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

security/apparmor/crypto.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ unsigned int aa_hash_size(void)
2828
char *aa_calc_hash(void *data, size_t len)
2929
{
3030
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
31-
char *hash = NULL;
32-
int error = -ENOMEM;
31+
char *hash;
32+
int error;
3333

3434
if (!apparmor_tfm)
3535
return NULL;
3636

3737
hash = kzalloc(apparmor_hash_size, GFP_KERNEL);
3838
if (!hash)
39-
goto fail;
39+
return ERR_PTR(-ENOMEM);
4040

4141
desc->tfm = apparmor_tfm;
4242

@@ -62,7 +62,7 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
6262
size_t len)
6363
{
6464
SHASH_DESC_ON_STACK(desc, apparmor_tfm);
65-
int error = -ENOMEM;
65+
int error;
6666
__le32 le32_version = cpu_to_le32(version);
6767

6868
if (!aa_g_hash_policy)
@@ -73,7 +73,7 @@ int aa_calc_profile_hash(struct aa_profile *profile, u32 version, void *start,
7373

7474
profile->hash = kzalloc(apparmor_hash_size, GFP_KERNEL);
7575
if (!profile->hash)
76-
goto fail;
76+
return -ENOMEM;
7777

7878
desc->tfm = apparmor_tfm;
7979

0 commit comments

Comments
 (0)