Reviewed-by: Jorge Lopez <jorge.lopez2@xxxxxx> Regards, Jorge Lopez HP Inc "Once you stop learning, you start dying" Albert Einstein > -----Original Message----- > From: Li Zetao <lizetao1@xxxxxxxxxx> > Sent: Wednesday, August 2, 2023 10:20 PM > To: Lopez, Jorge A (Security) <jorge.lopez2@xxxxxx>; > hdegoede@xxxxxxxxxx; markgross@xxxxxxxxxx > Cc: lizetao1@xxxxxxxxxx; platform-driver-x86@xxxxxxxxxxxxxxx > Subject: [PATCH -next] platform/x86: hp-bioscfg: Use kmemdup() to replace > kmalloc + memcpy > > CAUTION: External Email > > 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: Li Zetao <lizetao1@xxxxxxxxxx> > --- > .../platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c > b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c > index 02291e32684f..86f90238750c 100644 > --- a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c > +++ b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c > @@ -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: > -- > 2.34.1