From: Xi Wang Date: Wed, 19 Jun 2013 00:07:04 +0000 (+1000) Subject: mm/dmapool.c: fix null dev in dma_pool_create() X-Git-Tag: next-20130619~2^2~327 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=21636e2f8f2e6524e96f462aa85877d4982fb3dd;p=karo-tx-linux.git mm/dmapool.c: fix null dev in dma_pool_create() A few drivers invoke dma_pool_create() with a null dev. Note that dev is dereferenced in dev_to_node(dev), causing a null pointer dereference. A long term solution is to disallow null dev. Once the drivers are fixed, we can simplify the core code here. For now we add WARN_ON(!dev) to notify the driver maintainers and avoid the null pointer dereference. Signed-off-by: Xi Wang Cc: David Rientjes Signed-off-by: Andrew Morton --- diff --git a/mm/dmapool.c b/mm/dmapool.c index c69781e97cf9..668f26316e2e 100644 --- a/mm/dmapool.c +++ b/mm/dmapool.c @@ -132,6 +132,7 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev, { struct dma_pool *retval; size_t allocation; + int node; if (align == 0) { align = 1; @@ -156,7 +157,9 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev, return NULL; } - retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, dev_to_node(dev)); + node = WARN_ON(!dev) ? -1 : dev_to_node(dev); + + retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, node); if (!retval) return retval;