Message ID | 20230803032027.3044851-1-lizetao1@huawei.com (mailing list archive) |
---|---|
State | Accepted, archived |
Headers | show |
Series | [-next] platform/x86: hp-bioscfg: Use kmemdup() to replace kmalloc + memcpy | expand |
Reviewed-by: Jorge Lopez <jorge.lopez2@hp.com> Regards, Jorge Lopez HP Inc "Once you stop learning, you start dying" Albert Einstein > -----Original Message----- > From: Li Zetao <lizetao1@huawei.com> > Sent: Wednesday, August 2, 2023 10:20 PM > To: Lopez, Jorge A (Security) <jorge.lopez2@hp.com>; > hdegoede@redhat.com; markgross@kernel.org > Cc: lizetao1@huawei.com; platform-driver-x86@vger.kernel.org > 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@huawei.com> > --- > .../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
Hi, On 8/3/23 05:20, Li Zetao wrote: > 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@huawei.com> Thank you for your patch, I've applied this patch to my review-hans branch: https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while. Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window. Regards, Hans > --- > .../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:
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:
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@huawei.com> --- .../platform/x86/hp/hp-bioscfg/spmobj-attributes.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)