From: GONG, Ruiqi Date: Mon, 6 Jun 2022 08:17:14 +0000 (+0800) Subject: smack: Replace kzalloc + strncpy with kstrndup X-Git-Tag: v6.1-rc5~759^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63c3b5d2ca96b4a2a88ae01bea94021e874ce8fe;p=platform%2Fkernel%2Flinux-starfive.git smack: Replace kzalloc + strncpy with kstrndup Simplify the code by using kstrndup instead of kzalloc and strncpy in smk_parse_smack(), which meanwhile remove strncpy as [1] suggests. [1]: https://github.com/KSPP/linux/issues/90 Signed-off-by: GONG, Ruiqi Signed-off-by: Casey Schaufler --- diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index d2186e27..585e5e3 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -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; }