Merge branch 'linux-linaro-lsk-v4.4' into linux-linaro-lsk-v4.4-android
[firefly-linux-kernel-4.4.55.git] / fs / pstore / ram.c
index 5b10c2b4146c4ec29137a769de12070bb5714c1a..8d1e5e2db6a1a772daeb6d923a25a189c5c3b6a5 100644 (file)
@@ -396,13 +396,14 @@ static void ramoops_free_przs(struct ramoops_context *cxt)
 {
        int i;
 
-       cxt->max_dump_cnt = 0;
        if (!cxt->przs)
                return;
 
-       for (i = 0; !IS_ERR_OR_NULL(cxt->przs[i]); i++)
+       for (i = 0; i < cxt->max_dump_cnt; i++)
                persistent_ram_free(cxt->przs[i]);
+
        kfree(cxt->przs);
+       cxt->max_dump_cnt = 0;
 }
 
 static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
@@ -427,7 +428,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
                             GFP_KERNEL);
        if (!cxt->przs) {
                dev_err(dev, "failed to initialize a prz array for dumps\n");
-               goto fail_prz;
+               goto fail_mem;
        }
 
        for (i = 0; i < cxt->max_dump_cnt; i++) {
@@ -438,6 +439,11 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
                        err = PTR_ERR(cxt->przs[i]);
                        dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
                                cxt->record_size, (unsigned long long)*paddr, err);
+
+                       while (i > 0) {
+                               i--;
+                               persistent_ram_free(cxt->przs[i]);
+                       }
                        goto fail_prz;
                }
                *paddr += cxt->record_size;
@@ -445,7 +451,9 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
 
        return 0;
 fail_prz:
-       ramoops_free_przs(cxt);
+       kfree(cxt->przs);
+fail_mem:
+       cxt->max_dump_cnt = 0;
        return err;
 }
 
@@ -707,7 +715,6 @@ static int ramoops_remove(struct platform_device *pdev)
        struct ramoops_context *cxt = &oops_cxt;
 
        pstore_unregister(&cxt->pstore);
-       cxt->max_dump_cnt = 0;
 
        kfree(cxt->pstore.buf);
        cxt->pstore.bufsize = 0;