Commit 6f8972a0 authored by Li Zetao's avatar Li Zetao Committed by Hans de Goede
Browse files

platform/x86: hp-bioscfg: Use kmemdup() to replace kmalloc + memcpy



There are some warnings reported by coccinelle:

./drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c:317:35-42:
		WARNING opportunity for kmemdup
./drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c:270:40-47:
		WARNING opportunity for kmemdup
./drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c:233:36-43:
		WARNING opportunity for kmemdup

Use kmemdup rather than duplicating its implementation.

Signed-off-by: default avatarLi Zetao <lizetao1@huawei.com>
Reviewed-by: default avatarJorge Lopez <jorge.lopez2@hp.com>
Link: https://lore.kernel.org/r/20230803032027.3044851-1-lizetao1@huawei.com


Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent bfecbcb5
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -230,12 +230,10 @@ static ssize_t sk_store(struct kobject *kobj,
		length--;

	/* allocate space and copy current signing key */
	bioscfg_drv.spm_data.signing_key = kmalloc(length, GFP_KERNEL);
	bioscfg_drv.spm_data.signing_key = kmemdup(buf, length, GFP_KERNEL);
	if (!bioscfg_drv.spm_data.signing_key)
		return -ENOMEM;

	memcpy(bioscfg_drv.spm_data.signing_key, buf, length);

	/* submit signing key payload */
	ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_SK,
				   HPWMI_SECUREPLATFORM,
@@ -267,14 +265,12 @@ static ssize_t kek_store(struct kobject *kobj,
		length--;

	/* allocate space and copy current signing key */
	bioscfg_drv.spm_data.endorsement_key = kmalloc(length, GFP_KERNEL);
	bioscfg_drv.spm_data.endorsement_key = kmemdup(buf, length, GFP_KERNEL);
	if (!bioscfg_drv.spm_data.endorsement_key) {
		ret = -ENOMEM;
		goto exit_kek;
	}

	memcpy(bioscfg_drv.spm_data.endorsement_key, buf, length);

	ret = hp_wmi_perform_query(HPWMI_SECUREPLATFORM_SET_KEK,
				   HPWMI_SECUREPLATFORM,
				   (void *)bioscfg_drv.spm_data.endorsement_key,
@@ -314,13 +310,12 @@ static ssize_t auth_token_store(struct kobject *kobj,
		length--;

	/* allocate space and copy current auth token */
	bioscfg_drv.spm_data.auth_token = kmalloc(length, GFP_KERNEL);
	bioscfg_drv.spm_data.auth_token = kmemdup(buf, length, GFP_KERNEL);
	if (!bioscfg_drv.spm_data.auth_token) {
		ret = -ENOMEM;
		goto exit_token;
	}

	memcpy(bioscfg_drv.spm_data.auth_token, buf, length);
	return count;

exit_token: