From: Chris Wilson Date: Sat, 24 Jul 2010 17:29:37 +0000 (+0100) Subject: agp/intel: Destroy the scatterlist on allocation failure X-Git-Tag: v2.6.36-rc1~540^2~11^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=831cd4453598b2c8e193f077023910c6b0c39558;p=thirdparty%2Fkernel%2Flinux.git agp/intel: Destroy the scatterlist on allocation failure A side-effect of being able to use custom page allocations with the sg_table is that it cannot reap the partially constructed scatterlist if fails to allocate a page. So we need to call sg_free_table() ourselves if sg_alloc_table() fails. Signed-off-by: Chris Wilson Cc Dave Airlie Signed-off-by: Eric Anholt --- diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index 0c6d0fe32a214..f804325a735e9 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -104,7 +104,7 @@ static int intel_agp_map_memory(struct agp_memory *mem) DBG("try mapping %lu pages\n", (unsigned long)mem->page_count); if (sg_alloc_table(&st, mem->page_count, GFP_KERNEL)) - return -ENOMEM; + goto err; mem->sg_list = sg = st.sgl; @@ -113,11 +113,14 @@ static int intel_agp_map_memory(struct agp_memory *mem) mem->num_sg = pci_map_sg(intel_private.pcidev, mem->sg_list, mem->page_count, PCI_DMA_BIDIRECTIONAL); - if (unlikely(!mem->num_sg)) { - intel_agp_free_sglist(mem); - return -ENOMEM; - } + if (unlikely(!mem->num_sg)) + goto err; + return 0; + +err: + sg_free_table(&st); + return -ENOMEM; } static void intel_agp_unmap_memory(struct agp_memory *mem)