Skip to contentSkip to conversation

drm/nouveau/gk20a: fix NULL dereference on allocation failure

PATCH New Mikko Perttunen 1 participant 1 message Jun 11, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau/gk20a: fix NULL dereference on allocation failure

If memory allocation fails, node->base.imem does not get populated, causing a NULL pointer dereference on instobj destruction. Fix this by dereferencing it only if the allocation was successful.

---
 drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c +2 -2
index 648ecf5a8fbc..66d60d8bec60 100644
@@ -296,12 +296,12 @@ gk20a_instobj_dtor_dma(struct nvkm_memory *memory)
 {
 	struct gk20a_instobj_dma *node = gk20a_instobj_dma(memory);
 	struct gk20a_instmem *imem = node->base.imem;
-	struct device *dev = imem->base.subdev.device->dev;
 
 	if (unlikely(!node->base.vaddr))
 		goto out;
 
-	dma_free_attrs(dev, (u64)node->base.mn->length << PAGE_SHIFT,
+	dma_free_attrs(imem->base.subdev.device->dev,
+		       (u64)node->base.mn->length << PAGE_SHIFT,
 		       node->base.vaddr, node->handle, imem->attrs);
 
 out:
Signature · 1 line
2.30.1