drivers/base dmam_declare_coherent_memory leaks
authorVyacheslav V. Yurkov <uvv.mail@gmail.com>
Tue, 14 Jun 2016 07:58:37 +0000 (09:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2016 13:19:55 +0000 (15:19 +0200)
dmam_declare_coherent_memory doesn't take into account the return
value of dma_declare_coherent_memory, which leads to incorrect resource
handling

Signed-off-by: Vyacheslav V. Yurkov <uvv.mail@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/dma-mapping.c

index 2e318ffa019efa1eb16c64bb5153686951a9302c..8f8b68c80986cf35fa89ead7914e8f185aa34bd2 100644 (file)
@@ -198,10 +198,13 @@ int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
 
        rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size,
                                         flags);
-       if (rc == 0)
+       if (rc) {
                devres_add(dev, res);
-       else
+               rc = 0;
+       } else {
                devres_free(res);
+               rc = -ENOMEM;
+       }
 
        return rc;
 }