Skip to content

Commit

Permalink
smack: Replace kzalloc + strncpy with kstrndup
Browse files Browse the repository at this point in the history
Simplify the code by using kstrndup instead of kzalloc and strncpy in
smk_parse_smack(), which meanwhile remove strncpy as [1] suggests.

[1]: KSPP#90

Signed-off-by: GONG, Ruiqi <[email protected]>
  • Loading branch information
GONG, Ruiqi authored and intel-lab-lkp committed Jun 7, 2022
1 parent 047843b commit 67c6e2a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions security/smack/smack_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,9 @@ char *smk_parse_smack(const char *string, int len)
if (i == 0 || i >= SMK_LONGLABEL)
return ERR_PTR(-EINVAL);

smack = kzalloc(i + 1, GFP_NOFS);
if (smack == NULL)
smack = kstrndup(string, i, GFP_NOFS);
if (!smack)
return ERR_PTR(-ENOMEM);

strncpy(smack, string, i);

return smack;
}

Expand Down

0 comments on commit 67c6e2a

Please sign in to comment.