misc: sram: fix check of devm_ioremap*() return value
authorVladimir Zapolskiy <vz@mleia.com>
Wed, 23 Mar 2016 02:52:45 +0000 (04:52 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Apr 2016 21:15:56 +0000 (14:15 -0700)
Both devm_ioremap() and devm_ioremap_wc() functions return either
a pointer to valid iomem region or NULL, check for IS_ERR() is improper
and may result in oops on error path. Now on error -ENOMEM is returned.

Fixes: 0ab163ad1ea0 ("misc: sram: switch to ioremap_wc from ioremap")
Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/sram.c

index 69cdabe..f84b53d 100644 (file)
@@ -364,8 +364,8 @@ static int sram_probe(struct platform_device *pdev)
                sram->virt_base = devm_ioremap(sram->dev, res->start, size);
        else
                sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
-       if (IS_ERR(sram->virt_base))
-               return PTR_ERR(sram->virt_base);
+       if (!sram->virt_base)
+               return -ENOMEM;
 
        sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
                                          NUMA_NO_NODE, NULL);