OSDN Git Service

pstore/ram: Run without kernel crash dump region
[android-x86/kernel.git] / fs / pstore / ram.c
index f4fd2e7..316c164 100644 (file)
@@ -713,18 +713,15 @@ static int ramoops_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct ramoops_platform_data *pdata = dev->platform_data;
+       struct ramoops_platform_data pdata_local;
        struct ramoops_context *cxt = &oops_cxt;
        size_t dump_mem_sz;
        phys_addr_t paddr;
        int err = -EINVAL;
 
        if (dev_of_node(dev) && !pdata) {
-               pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
-               if (!pdata) {
-                       pr_err("cannot allocate platform data buffer\n");
-                       err = -ENOMEM;
-                       goto fail_out;
-               }
+               pdata = &pdata_local;
+               memset(pdata, 0, sizeof(*pdata));
 
                err = ramoops_parse_dt(pdev, pdata);
                if (err < 0)
@@ -806,30 +803,36 @@ static int ramoops_probe(struct platform_device *pdev)
 
        cxt->pstore.data = cxt;
        /*
-        * Console can handle any buffer size, so prefer LOG_LINE_MAX. If we
-        * have to handle dumps, we must have at least record_size buffer. And
-        * for ftrace, bufsize is irrelevant (if bufsize is 0, buf will be
-        * ZERO_SIZE_PTR).
+        * Prepare frontend flags based on which areas are initialized.
+        * For ramoops_init_przs() cases, the "max count" variable tells
+        * if there are regions present. For ramoops_init_prz() cases,
+        * the single region size is how to check.
         */
-       if (cxt->console_size)
-               cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */
-       cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize);
-       cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);
-       if (!cxt->pstore.buf) {
-               pr_err("cannot allocate pstore buffer\n");
-               err = -ENOMEM;
-               goto fail_clear;
-       }
-       spin_lock_init(&cxt->pstore.buf_lock);
-
-       cxt->pstore.flags = PSTORE_FLAGS_DMESG;
+       cxt->pstore.flags = 0;
+       if (cxt->max_dump_cnt)
+               cxt->pstore.flags |= PSTORE_FLAGS_DMESG;
        if (cxt->console_size)
                cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE;
-       if (cxt->ftrace_size)
+       if (cxt->max_ftrace_cnt)
                cxt->pstore.flags |= PSTORE_FLAGS_FTRACE;
        if (cxt->pmsg_size)
                cxt->pstore.flags |= PSTORE_FLAGS_PMSG;
 
+       /*
+        * Since bufsize is only used for dmesg crash dumps, it
+        * must match the size of the dprz record (after PRZ header
+        * and ECC bytes have been accounted for).
+        */
+       if (cxt->pstore.flags & PSTORE_FLAGS_DMESG) {
+               cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size;
+               cxt->pstore.buf = kzalloc(cxt->pstore.bufsize, GFP_KERNEL);
+               if (!cxt->pstore.buf) {
+                       pr_err("cannot allocate pstore crash dump buffer\n");
+                       err = -ENOMEM;
+                       goto fail_clear;
+               }
+       }
+
        err = pstore_register(&cxt->pstore);
        if (err) {
                pr_err("registering with pstore failed\n");
@@ -962,7 +965,7 @@ static int __init ramoops_init(void)
 
        return ret;
 }
-late_initcall(ramoops_init);
+postcore_initcall(ramoops_init);
 
 static void __exit ramoops_exit(void)
 {