Zou Wei
2020-Apr-21 12:37 UTC
[Nouveau] [PATCH -next] drm/nouveau/acr: Use kmemdup instead of kmalloc and memcpy
Fixes coccicheck warning: drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c:103:23-30: WARNING opportunity for kmemdup drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c:113:22-29: WARNING opportunity for kmemdup Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace "secure boot"") Reported-by: Hulk Robot <hulkci at huawei.com> Signed-off-by: Zou Wei <zou_wei at huawei.com> --- drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c index aecce2d..667fa01 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c @@ -100,25 +100,21 @@ nvkm_acr_hsfw_load_image(struct nvkm_acr *acr, const char *name, int ver, hsfw->data_size = lhdr->data_size; hsfw->sig.prod.size = fwhdr->sig_prod_size; - hsfw->sig.prod.data = kmalloc(hsfw->sig.prod.size, GFP_KERNEL); + hsfw->sig.prod.data = kmemdup(fw->data + fwhdr->sig_prod_offset + sig, + hsfw->sig.prod.size, GFP_KERNEL); if (!hsfw->sig.prod.data) { ret = -ENOMEM; goto done; } - memcpy(hsfw->sig.prod.data, fw->data + fwhdr->sig_prod_offset + sig, - hsfw->sig.prod.size); - hsfw->sig.dbg.size = fwhdr->sig_dbg_size; - hsfw->sig.dbg.data = kmalloc(hsfw->sig.dbg.size, GFP_KERNEL); + hsfw->sig.dbg.data = kmemdup(fw->data + fwhdr->sig_dbg_offset + sig, + hsfw->sig.dbg.size, GFP_KERNEL); if (!hsfw->sig.dbg.data) { ret = -ENOMEM; goto done; } - memcpy(hsfw->sig.dbg.data, fw->data + fwhdr->sig_dbg_offset + sig, - hsfw->sig.dbg.size); - hsfw->sig.patch_loc = loc; done: nvkm_firmware_put(fw); -- 2.6.2
Ben Skeggs
2020-Apr-30 03:58 UTC
[Nouveau] [PATCH -next] drm/nouveau/acr: Use kmemdup instead of kmalloc and memcpy
Thanks! On Wed, 22 Apr 2020 at 16:56, Zou Wei <zou_wei at huawei.com> wrote:> > Fixes coccicheck warning: > > drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c:103:23-30: WARNING opportunity for kmemdup > drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c:113:22-29: WARNING opportunity for kmemdup > > Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace "secure boot"") > Reported-by: Hulk Robot <hulkci at huawei.com> > Signed-off-by: Zou Wei <zou_wei at huawei.com> > --- > drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 12 ++++-------- > 1 file changed, 4 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > index aecce2d..667fa01 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c > @@ -100,25 +100,21 @@ nvkm_acr_hsfw_load_image(struct nvkm_acr *acr, const char *name, int ver, > hsfw->data_size = lhdr->data_size; > > hsfw->sig.prod.size = fwhdr->sig_prod_size; > - hsfw->sig.prod.data = kmalloc(hsfw->sig.prod.size, GFP_KERNEL); > + hsfw->sig.prod.data = kmemdup(fw->data + fwhdr->sig_prod_offset + sig, > + hsfw->sig.prod.size, GFP_KERNEL); > if (!hsfw->sig.prod.data) { > ret = -ENOMEM; > goto done; > } > > - memcpy(hsfw->sig.prod.data, fw->data + fwhdr->sig_prod_offset + sig, > - hsfw->sig.prod.size); > - > hsfw->sig.dbg.size = fwhdr->sig_dbg_size; > - hsfw->sig.dbg.data = kmalloc(hsfw->sig.dbg.size, GFP_KERNEL); > + hsfw->sig.dbg.data = kmemdup(fw->data + fwhdr->sig_dbg_offset + sig, > + hsfw->sig.dbg.size, GFP_KERNEL); > if (!hsfw->sig.dbg.data) { > ret = -ENOMEM; > goto done; > } > > - memcpy(hsfw->sig.dbg.data, fw->data + fwhdr->sig_dbg_offset + sig, > - hsfw->sig.dbg.size); > - > hsfw->sig.patch_loc = loc; > done: > nvkm_firmware_put(fw); > -- > 2.6.2 > > _______________________________________________ > dri-devel mailing list > dri-devel at lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maybe Matching Threads
- [PATCH] drm/nouveau/acr: Abort loading ACR if no firmware was found
- [PATCH v3 10/11] secboot/gm200: add secure-boot support
- [PATCH] drm/nouveau/acr: fix a coding style in nvkm_acr_lsfw_load_bl_inst_data_sig()
- [PATCH] drm/nouveau/nvfw/acr: set wpr_generic_header_dump storage-class-specifier to static
- [PATCH] drm/nouveau/acr: remove unused loc variable