2021-12-16 02:18:49

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH] drm/nouveau/acr: potential dereference of null pointer

The return value of kmalloc() needs to be checked.
To avoid use in memcpy() in case of the failure of alloc.

Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace "secure boot"")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
index 667fa016496e..776573e77988 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c
@@ -143,6 +143,9 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const char *name, int ver,
hsfw->imem_size = desc->code_size;
hsfw->imem_tag = desc->start_tag;
hsfw->imem = kmalloc(desc->code_size, GFP_KERNEL);
+ if (!hsfw->imem)
+ return -ENOMEM;
+
memcpy(hsfw->imem, data + desc->code_off, desc->code_size);

nvkm_firmware_put(fw);
--
2.25.1