]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: octeontx - use strscpy_pad in ucode_load_store
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 20 May 2026 10:00:30 +0000 (12:00 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 29 May 2026 06:05:29 +0000 (14:05 +0800)
Instead of zero-initializing the temporary buffer and then copying into
it with strscpy(), use strscpy_pad() to copy the string and zero-pad any
trailing bytes. Drop the explicit size argument to further simplify the
code since strscpy_pad() can determine it automatically when the
destination buffer has a fixed length.

Also use strscpy_pad() to check for string truncation instead of the
hard-coded OTX_CPT_UCODE_NAME_LENGTH.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c

index e0f38d32bc935b674f1a40759d79a480b575eb41..205579a6ba2bf06d06b4730e0ed7d367499996b9 100644 (file)
@@ -1318,7 +1318,7 @@ static ssize_t ucode_load_store(struct device *dev,
 {
        struct otx_cpt_engines engs[OTX_CPT_MAX_ETYPES_PER_GRP] = { {0} };
        char *ucode_filename[OTX_CPT_MAX_ETYPES_PER_GRP];
-       char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH] = { 0 };
+       char tmp_buf[OTX_CPT_UCODE_NAME_LENGTH];
        char *start, *val, *err_msg, *tmp;
        struct otx_cpt_eng_grps *eng_grps;
        int grp_idx = 0, ret = -EINVAL;
@@ -1326,12 +1326,11 @@ static ssize_t ucode_load_store(struct device *dev,
        int del_grp_idx = -1;
        int ucode_idx = 0;
 
-       if (count >= OTX_CPT_UCODE_NAME_LENGTH)
+       if (strscpy_pad(tmp_buf, buf) < 0)
                return -EINVAL;
 
        eng_grps = container_of(attr, struct otx_cpt_eng_grps, ucode_load_attr);
        err_msg = "Invalid engine group format";
-       strscpy(tmp_buf, buf, OTX_CPT_UCODE_NAME_LENGTH);
        start = tmp_buf;
 
        has_se = has_ie = has_ae = false;