]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm/dmapool.c: remove redundant NULL check for dev in dma_pool_create()
authorDaeseok Youn <daeseok.youn@gmail.com>
Wed, 14 May 2014 00:01:59 +0000 (10:01 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 14 May 2014 00:01:59 +0000 (10:01 +1000)
"dev" cannot be NULL because it is already checked before calling
dma_pool_create().

If dev ever was NULL, the code would oops in dev_to_node() after enabling
CONFIG_NUMA.

It is possible that some driver is using dev==NULL and has never been run
on a NUMA machine.  Such a driver is probably outdated, possibly buggy and
will need some attention if it starts triggering NULL derefs.

Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/dmapool.c

index c69781e97cf968076583cc29ef1dbfa53a535c46..38dfcddc0595eaab80fb5a120e1a7367a508cea6 100644 (file)
@@ -170,24 +170,16 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
        retval->boundary = boundary;
        retval->allocation = allocation;
 
-       if (dev) {
-               int ret;
+       INIT_LIST_HEAD(&retval->pools);
 
-               mutex_lock(&pools_lock);
-               if (list_empty(&dev->dma_pools))
-                       ret = device_create_file(dev, &dev_attr_pools);
-               else
-                       ret = 0;
-               /* note:  not currently insisting "name" be unique */
-               if (!ret)
-                       list_add(&retval->pools, &dev->dma_pools);
-               else {
-                       kfree(retval);
-                       retval = NULL;
-               }
-               mutex_unlock(&pools_lock);
+       mutex_lock(&pools_lock);
+       if (list_empty(&dev->dma_pools) &&
+           device_create_file(dev, &dev_attr_pools)) {
+               kfree(retval);
+               return NULL;
        } else
-               INIT_LIST_HEAD(&retval->pools);
+               list_add(&retval->pools, &dev->dma_pools);
+       mutex_unlock(&pools_lock);
 
        return retval;
 }