crypto: use 2-arg strscpy where destination size is known
Subsystems (5)
v2 cover crypto: use 2-arg strscpy where destination size is known
To simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
Changes in v2:
- Rebase and split up
- v1: https://lore.kernel.org/r/[email protected]/
Thorsten Blum (6):
crypto: use 2-arg strscpy where destination size is known
crypto: cavium - use 2-arg strscpy where destination size is known
crypto: ccp - use 2-arg strscpy where destination size is known
crypto: hisilicon - use 2-arg strscpy where destination size is known
crypto: qat - use 2-arg strscpy where destination size is known
crypto: octeontx - use 2-arg strscpy where destination size is known
crypto/api.c | 2 +- crypto/crypto_user.c | 9 ++++----- crypto/hctr2.c | 3 +-- crypto/lrw.c | 2 +- crypto/lskcipher.c | 3 +-- crypto/xts.c | 3 ++- drivers/crypto/cavium/nitrox/nitrox_hal.c | 3 ++- drivers/crypto/ccp/ccp-crypto-sha.c | 2 +- drivers/crypto/hisilicon/qm.c | 5 +---- drivers/crypto/intel/qat/qat_common/adf_cfg.c | 7 ++++--- drivers/crypto/intel/qat/qat_common/adf_cfg_services.c | 2 +- drivers/crypto/intel/qat/qat_common/adf_mstate_mgr.c | 3 ++- .../crypto/intel/qat/qat_common/adf_transport_debug.c | 3 ++- drivers/crypto/intel/qat/qat_common/qat_compression.c | 3 ++- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 4 ++-- drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c | 4 ++-- 16 files changed, 29 insertions(+), 29 deletions(-)
base-commit: 5624ea54f3ba5c83d2e5503411a31a8be0278c1e
PATCH v2 1/6 crypto: use 2-arg strscpy where destination size is known
To simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- crypto/api.c | 2 +- crypto/crypto_user.c | 9 ++++----- crypto/hctr2.c | 3 +-- crypto/lrw.c | 2 +- crypto/lskcipher.c | 3 +-- crypto/xts.c | 3 ++- 6 files changed, 10 insertions(+), 12 deletions(-)
crypto/api.c +1 -1
@@ -116,7 +116,7 @@ struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask) larval->alg.cra_priority =-1 ; larval->alg.cra_destroy = crypto_larval_destroy; -strscpy (larval->alg.cra_name, name,CRYPTO_MAX_ALG_NAME ); +strscpy (larval->alg.cra_name, name);init_completion (&larval->completion);return larval;
crypto/crypto_user.c +4 -5
@@ -11,6 +11,7 @@#include <linux/cryptouser.h> #include <linux/sched.h> #include <linux/security.h> +#include <linux/string.h> #include <net/netlink.h> #include <net/net_namespace.h> #include <net/sock.h>
@@ -87,11 +88,9 @@ static int crypto_report_one(struct crypto_alg *alg, {memset (ualg,0 ,sizeof (*ualg)); -strscpy (ualg->cru_name, alg->cra_name,sizeof (ualg->cru_name)); -strscpy (ualg->cru_driver_name, alg->cra_driver_name, -sizeof (ualg->cru_driver_name)); -strscpy (ualg->cru_module_name,module_name (alg->cra_module), -sizeof (ualg->cru_module_name)); +strscpy (ualg->cru_name, alg->cra_name); +strscpy (ualg->cru_driver_name, alg->cra_driver_name); +strscpy (ualg->cru_module_name,module_name (alg->cra_module)); ualg->cru_type =0 ; ualg->cru_mask =0 ;
crypto/hctr2.c +1 -2
@@ -354,8 +354,7 @@ static int hctr2_create_common(struct crypto_template *tmpl, struct rtattr **tb, err = -EINVAL ;if (strncmp (xctr_alg->base.cra_name,"xctr(" ,5 )) goto err_free_inst; - len =strscpy (blockcipher_name, xctr_alg->base.cra_name +5 , -sizeof (blockcipher_name)); + len =strscpy (blockcipher_name, xctr_alg->base.cra_name +5 );if (len <1 ) goto err_free_inst;if (blockcipher_name[len -1 ] !=')' )
crypto/lrw.c +1 -1
@@ -359,7 +359,7 @@ static int lrw_create(struct crypto_template *tmpl, struct rtattr **tb)if (!memcmp (cipher_name,"ecb(" ,4 )) {int len; - len =strscpy (ecb_name, cipher_name +4 ,sizeof (ecb_name)); + len =strscpy (ecb_name, cipher_name +4 );if (len <2 ) goto err_free_inst;
crypto/lskcipher.c +1 -2
@@ -528,8 +528,7 @@ struct lskcipher_instance *lskcipher_alloc_instance_simple(int len; err = -EINVAL ; - len =strscpy (ecb_name, &cipher_alg->co.base.cra_name[4 ], -sizeof (ecb_name)); + len =strscpy (ecb_name, &cipher_alg->co.base.cra_name[4 ]);if (len <2 ) goto err_free_inst;
crypto/xts.c +2 -1
@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/scatterlist.h> #include <linux/slab.h> +#include <linux/string.h> #include <crypto/xts.h> #include <crypto/b128ops.h>
@@ -400,7 +401,7 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)if (!memcmp (cipher_name,"ecb(" ,4 )) {int len; - len =strscpy (name, cipher_name +4 ,sizeof (name)); + len =strscpy (name, cipher_name +4 );if (len <2 ) goto err_free_inst;
PATCH v2 2/6 crypto: cavium - use 2-arg strscpy where destination size is known
In reply to Thorsten BlumTo simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- drivers/crypto/cavium/nitrox/nitrox_hal.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/cavium/nitrox/nitrox_hal.c +2 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/delay.h> +#include <linux/string.h> #include "nitrox_dev.h" #include "nitrox_csr.h"
@@ -647,7 +648,7 @@ void nitrox_get_hwinfo(struct nitrox_device *ndev) ndev->hw.revision_id);/* copy partname */ -strscpy (ndev->hw.partname, name,sizeof (ndev->hw.partname)); +strscpy (ndev->hw.partname, name); }void enable_pf2vf_mbox_interrupts (struct nitrox_device *ndev)
PATCH v2 3/6 crypto: ccp - use 2-arg strscpy where destination size is known
In reply to Thorsten BlumTo simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- drivers/crypto/ccp/ccp-crypto-sha.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/ccp/ccp-crypto-sha.c +1 -1
@@ -426,7 +426,7 @@ static int ccp_register_hmac_alg(struct list_head *head, *ccp_alg = *base_alg;INIT_LIST_HEAD (&ccp_alg->entry); -strscpy (ccp_alg->child_alg, def->name,CRYPTO_MAX_ALG_NAME ); +strscpy (ccp_alg->child_alg, def->name); alg = &ccp_alg->alg; alg->setkey = ccp_sha_setkey;
PATCH v2 4/6 crypto: hisilicon - use 2-arg strscpy where destination size is known
In reply to Thorsten BlumTo simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- drivers/crypto/hisilicon/qm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/crypto/hisilicon/qm.c +1 -4
@@ -2944,11 +2944,8 @@ static int qm_alloc_uacce(struct hisi_qm *qm) .flags = UACCE_DEV_SVA, .ops = &uacce_qm_ops, }; -int ret; - ret =strscpy (interface.name,dev_driver_string (&pdev->dev), -sizeof (interface.name)); -if (ret <0 ) +if (strscpy (interface.name,dev_driver_string (&pdev->dev)) <0 )return -ENAMETOOLONG ; uacce =uacce_alloc (&pdev->dev, &interface);
PATCH v2 5/6 crypto: qat - use 2-arg strscpy where destination size is known
In reply to Thorsten BlumTo simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- drivers/crypto/intel/qat/qat_common/adf_cfg.c | 7 ++++--- drivers/crypto/intel/qat/qat_common/adf_cfg_services.c | 2 +- drivers/crypto/intel/qat/qat_common/adf_mstate_mgr.c | 3 ++- drivers/crypto/intel/qat/qat_common/adf_transport_debug.c | 3 ++- drivers/crypto/intel/qat/qat_common/qat_compression.c | 3 ++- 5 files changed, 11 insertions(+), 7 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_cfg.c +4 -3
@@ -2,6 +2,7 @@/* Copyright(c) 2014 - 2020 Intel Corporation */ #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/string.h> #include <linux/list.h> #include <linux/seq_file.h> #include "adf_accel_devices.h"
@@ -284,13 +285,13 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,return -ENOMEM ;INIT_LIST_HEAD (&key_val->list); -strscpy (key_val->key, key,sizeof (key_val->key)); +strscpy (key_val->key, key);if (type ==ADF_DEC ) {snprintf (key_val->val,ADF_CFG_MAX_VAL_LEN_IN_BYTES ,"%ld" , (*((long *)val))); }else if (type ==ADF_STR ) { -strscpy (key_val->val, (char *)val,sizeof (key_val->val)); +strscpy (key_val->val, (char *)val); }else if (type ==ADF_HEX ) {snprintf (key_val->val,ADF_CFG_MAX_VAL_LEN_IN_BYTES ,"0x%lx" , (unsigned long )val);
@@ -350,7 +351,7 @@ int adf_cfg_section_add(struct adf_accel_dev *accel_dev, const char *name)if (!sec)return -ENOMEM ; -strscpy (sec->name, name,sizeof (sec->name)); +strscpy (sec->name, name);INIT_LIST_HEAD (&sec->param_head);down_write (&cfg->lock);list_add_tail (&sec->list, &cfg->sec_list);
drivers/crypto/intel/qat/qat_common/adf_cfg_services.c +1 -1
@@ -60,7 +60,7 @@ static int adf_service_string_to_mask(struct adf_accel_dev *accel_dev, const chaif (len >ADF_CFG_MAX_VAL_LEN_IN_BYTES -1 )return -EINVAL ; -strscpy (services, buf,ADF_CFG_MAX_VAL_LEN_IN_BYTES ); +strscpy (services, buf); substr = services;while ((token =strsep (&substr,ADF_SERVICES_DELIMITER ))) {
drivers/crypto/intel/qat/qat_common/adf_mstate_mgr.c +2 -1
@@ -2,6 +2,7 @@/* Copyright(c) 2024 Intel Corporation */ #include <linux/slab.h> +#include <linux/string.h> #include <linux/types.h> #include "adf_mstate_mgr.h"
@@ -158,7 +159,7 @@ static struct adf_mstate_sect_h *adf_mstate_sect_add_header(struct adf_mstate_mgreturn NULL ; } -strscpy (sect->id, id,sizeof (sect->id)); +strscpy (sect->id, id); sect->size =0 ; sect->sub_sects =0 ; mgr->state +=sizeof (*sect);
drivers/crypto/intel/qat/qat_common/adf_transport_debug.c +2 -1
@@ -2,6 +2,7 @@/* Copyright(c) 2014 - 2020 Intel Corporation */ #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/string.h> #include <linux/seq_file.h> #include "adf_accel_devices.h" #include "adf_transport_internal.h"
@@ -103,7 +104,7 @@ int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name)if (!ring_debug)return -ENOMEM ; -strscpy (ring_debug->ring_name, name,sizeof (ring_debug->ring_name)); +strscpy (ring_debug->ring_name, name);snprintf (entry_name,sizeof (entry_name),"ring_%02d" , ring->ring_number);
drivers/crypto/intel/qat/qat_common/qat_compression.c +2 -1
@@ -2,6 +2,7 @@/* Copyright(c) 2022 Intel Corporation */ #include <linux/module.h> #include <linux/slab.h> +#include <linux/string.h> #include "adf_accel_devices.h" #include "adf_common_drv.h" #include "adf_transport.h"
@@ -144,7 +145,7 @@ static int qat_compression_create_instances(struct adf_accel_dev *accel_dev)int i;INIT_LIST_HEAD (&accel_dev->compression_list); -strscpy (key,ADF_NUM_DC ,sizeof (key)); +strscpy (key,ADF_NUM_DC ); ret =adf_cfg_get_param_value (accel_dev,SEC , key, val);if (ret)return ret;
PATCH v2 6/6 crypto: octeontx - use 2-arg strscpy where destination size is known
In reply to Thorsten BlumTo simplify the code, drop explicit and hard-coded size arguments from strscpy() where the destination buffer has a fixed size and strscpy() can automatically determine it using sizeof().
--- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 4 ++-- drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c +2 -2
@@ -99,7 +99,7 @@ static int dev_supports_eng_type(struct otx_cpt_eng_grps *eng_grps,static void set_ucode_filename (struct otx_cpt_ucode *ucode,const char *filename) { -strscpy (ucode->filename, filename,OTX_CPT_UCODE_NAME_LENGTH ); +strscpy (ucode->filename, filename); }static char *get_eng_type_str (int eng_type)
@@ -140,7 +140,7 @@ static int get_ucode_type(struct otx_cpt_ucode_hdr *ucode_hdr, int *ucode_type)u32 i, val =0 ;u8 nn; -strscpy (tmp_ver_str, ucode_hdr->ver_str,OTX_CPT_UCODE_VER_STR_SZ ); +strscpy (tmp_ver_str, ucode_hdr->ver_str);for (i =0 ; i <strlen (tmp_ver_str); i++) tmp_ver_str[i] =tolower (tmp_ver_str[i]);
drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c +2 -2
@@ -74,7 +74,7 @@ static int is_2nd_ucode_used(struct otx2_cpt_eng_grp_info *eng_grp)static void set_ucode_filename (struct otx2_cpt_ucode *ucode,const char *filename) { -strscpy (ucode->filename, filename,OTX2_CPT_NAME_LENGTH ); +strscpy (ucode->filename, filename); }static char *get_eng_type_str (int eng_type)
@@ -130,7 +130,7 @@ static int get_ucode_type(struct device *dev,int i, val =0 ;u8 nn; -strscpy (tmp_ver_str, ucode_hdr->ver_str,OTX2_CPT_UCODE_VER_STR_SZ ); +strscpy (tmp_ver_str, ucode_hdr->ver_str);for (i =0 ; i <strlen (tmp_ver_str); i++) tmp_ver_str[i] =tolower (tmp_ver_str[i]);
Herbert Xu
maintainerQuoted 35 lines · Thorsten Blum
To simplify the code, drop explicit and hard-coded size arguments from
strscpy()where the destination buffer has a fixed size andstrscpy()can automatically determine it usingsizeof().Changes in v2:
- Rebase and split up
- v1: https://lore.kernel.org/r/[email protected]/Thorsten Blum (6):
crypto: use 2-arg strscpy where destination size is known
crypto: cavium - use 2-arg strscpy where destination size is known
crypto: ccp - use 2-arg strscpy where destination size is known
crypto: hisilicon - use 2-arg strscpy where destination size is known
crypto: qat - use 2-arg strscpy where destination size is known
crypto: octeontx - use 2-arg strscpy where destination size is knowncrypto/api.c | 2 +- crypto/crypto_user.c | 9 ++++----- crypto/hctr2.c | 3 +-- crypto/lrw.c | 2 +- crypto/lskcipher.c | 3 +-- crypto/xts.c | 3 ++- drivers/crypto/cavium/nitrox/nitrox_hal.c | 3 ++- drivers/crypto/ccp/ccp-crypto-sha.c | 2 +- drivers/crypto/hisilicon/qm.c | 5 +---- drivers/crypto/intel/qat/qat_common/adf_cfg.c | 7 ++++--- drivers/crypto/intel/qat/qat_common/adf_cfg_services.c | 2 +- drivers/crypto/intel/qat/qat_common/adf_mstate_mgr.c | 3 ++- .../crypto/intel/qat/qat_common/adf_transport_debug.c | 3 ++- drivers/crypto/intel/qat/qat_common/qat_compression.c | 3 ++- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c | 4 ++-- drivers/crypto/marvell/octeontx2/otx2_cptpf_ucode.c | 4 ++-- 16 files changed, 29 insertions(+), 29 deletions(-)
Quoted 1 line
base-commit:
5624ea54f3ba5c83d2e5503411a31a8be0278c1e
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt