Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

agp/intel: Fix a memory leak on module initialisation failure

In intel_gtt_setup_scratch_page(), pointer "page" is not released if
pci_dma_mapping_error() return an error, leading to a memory leak on
module initialisation failure. Simply fix this issue by freeing "page"
before return.

Fixes: 0e87d2b06cb46 ("intel-gtt: initialize our own scratch page")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20200522083451.7448-1-chris@chris-wilson.co.uk

authored by

Qiushi Wu and committed by
Chris Wilson
b975abbd 2992b543

+3 -1
+3 -1
drivers/char/agp/intel-gtt.c
··· 304 304 if (intel_private.needs_dmar) { 305 305 dma_addr = pci_map_page(intel_private.pcidev, page, 0, 306 306 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 307 - if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) 307 + if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) { 308 + __free_page(page); 308 309 return -EINVAL; 310 + } 309 311 310 312 intel_private.scratch_page_dma = dma_addr; 311 313 } else