pstore/ram_core: Proper checking for post_init errors (e.g. improper ECC size)
authorAnton Vorontsov <anton.vorontsov@linaro.org>
Tue, 19 Jun 2012 02:15:52 +0000 (19:15 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Jun 2012 23:15:22 +0000 (16:15 -0700)
We will implement variable-sized ECC buffers soon, so post_init routine
might fail much more likely, so we'd better check for its errors.

To make error handling simple, modify persistent_ram_free() to it be safe
at all times.

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/pstore/ram_core.c

index 26531856daf82c7f0bb5eec44020e0002bb68a44..f62ebf2dfed730860ed4826bace0887b464da13d 100644 (file)
@@ -427,11 +427,17 @@ static int __devinit persistent_ram_post_init(struct persistent_ram_zone *prz,
 
 void persistent_ram_free(struct persistent_ram_zone *prz)
 {
-       if (pfn_valid(prz->paddr >> PAGE_SHIFT)) {
-               vunmap(prz->vaddr);
-       } else {
-               iounmap(prz->vaddr);
-               release_mem_region(prz->paddr, prz->size);
+       if (!prz)
+               return;
+
+       if (prz->vaddr) {
+               if (pfn_valid(prz->paddr >> PAGE_SHIFT)) {
+                       vunmap(prz->vaddr);
+               } else {
+                       iounmap(prz->vaddr);
+                       release_mem_region(prz->paddr, prz->size);
+               }
+               prz->vaddr = NULL;
        }
        persistent_ram_free_old(prz);
        kfree(prz);
@@ -454,10 +460,12 @@ struct persistent_ram_zone * __devinit persistent_ram_new(phys_addr_t start,
        if (ret)
                goto err;
 
-       persistent_ram_post_init(prz, ecc);
+       ret = persistent_ram_post_init(prz, ecc);
+       if (ret)
+               goto err;
 
        return prz;
 err:
-       kfree(prz);
+       persistent_ram_free(prz);
        return ERR_PTR(ret);
 }