From: Guennadi Liakhovetski Date: Tue, 8 May 2007 07:31:25 +0000 (-0700) Subject: dma_declare_coherent_memory wrong allocation X-Git-Tag: v2.6.22-rc1~615 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b247e8aaf2837715d31eb25828fa8b4eb0a659cd;p=linux-2.6 dma_declare_coherent_memory wrong allocation dma_declare_coherent_memory() allocates a bitmap 1 bit per page, it calculates the bitmap size based on size of long, but allocates bytes... Thanks to James Bottomley for clarifications and corrections. Signed-off-by: G. Liakhovetski Acked-by: James Bottomley Cc: Mikael Starvik Cc: Andi Kleen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/arch/cris/arch-v32/drivers/pci/dma.c b/arch/cris/arch-v32/drivers/pci/dma.c index 70d3bf0c92..832fc63504 100644 --- a/arch/cris/arch-v32/drivers/pci/dma.c +++ b/arch/cris/arch-v32/drivers/pci/dma.c @@ -76,7 +76,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, { void __iomem *mem_base; int pages = size >> PAGE_SHIFT; - int bitmap_size = (pages + 31)/32; + int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0) goto out; diff --git a/arch/i386/kernel/pci-dma.c b/arch/i386/kernel/pci-dma.c index 3ebcea0336..30b754f7cb 100644 --- a/arch/i386/kernel/pci-dma.c +++ b/arch/i386/kernel/pci-dma.c @@ -77,7 +77,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, { void __iomem *mem_base = NULL; int pages = size >> PAGE_SHIFT; - int bitmap_size = (pages + 31)/32; + int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0) goto out;