devm_memremap: Fix error value when memremap failed
authorToshi Kani <toshi.kani@hpe.com>
Sat, 20 Feb 2016 22:32:24 +0000 (14:32 -0800)
committerDan Williams <dan.j.williams@intel.com>
Wed, 24 Feb 2016 01:17:20 +0000 (17:17 -0800)
devm_memremap() returns an ERR_PTR() value in case of error.
However, it returns NULL when memremap() failed.  This causes
the caller, such as the pmem driver, to proceed and oops later.

Change devm_memremap() to return ERR_PTR(-ENXIO) when memremap()
failed.

Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: <stable@vger.kernel.org>
Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
kernel/memremap.c

index 2c468dea60bc2e688c6a5271fa393ea82a1aacb4..b04ea2f5fbfef8612aee48e17aec90f2cbc21481 100644 (file)
@@ -136,8 +136,10 @@ void *devm_memremap(struct device *dev, resource_size_t offset,
        if (addr) {
                *ptr = addr;
                devres_add(dev, ptr);
-       } else
+       } else {
                devres_free(ptr);
+               return ERR_PTR(-ENXIO);
+       }
 
        return addr;
 }