Merge tag 'pstore-v5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Jul 2019 21:40:32 +0000 (14:40 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Jul 2019 21:40:32 +0000 (14:40 -0700)
Pull pstore updates from Kees Cook:

 - Improve backward compatibility with older Chromebooks (Douglas
   Anderson)

 - Refactor debugfs initialization (Greg KH)

 - Fix double-free in pstore_mkfile() failure path (Norbert Manthey)

* tag 'pstore-v5.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore: Fix double-free in pstore_mkfile() failure path
  pstore: no need to check return value of debugfs_create functions
  pstore/ram: Improve backward compatibility with older Chromebooks

fs/pstore/ftrace.c
fs/pstore/inode.c
fs/pstore/ram.c

index 8e0a17ce3180bc5bd172252a86e748d5f8f912fc..bfbfc269807020cc91b1cba4421bafc732e76999 100644 (file)
@@ -112,27 +112,13 @@ static struct dentry *pstore_ftrace_dir;
 
 void pstore_register_ftrace(void)
 {
-       struct dentry *file;
-
        if (!psinfo->write)
                return;
 
        pstore_ftrace_dir = debugfs_create_dir("pstore", NULL);
-       if (!pstore_ftrace_dir) {
-               pr_err("%s: unable to create pstore directory\n", __func__);
-               return;
-       }
-
-       file = debugfs_create_file("record_ftrace", 0600, pstore_ftrace_dir,
-                                  NULL, &pstore_knob_fops);
-       if (!file) {
-               pr_err("%s: unable to create record_ftrace file\n", __func__);
-               goto err_file;
-       }
 
-       return;
-err_file:
-       debugfs_remove(pstore_ftrace_dir);
+       debugfs_create_file("record_ftrace", 0600, pstore_ftrace_dir, NULL,
+                           &pstore_knob_fops);
 }
 
 void pstore_unregister_ftrace(void)
index 89a80b568a179a1ed251312a500b4c649092b706..7fbe8f0582205a3cdb31514d27cd94708c9b8e82 100644 (file)
@@ -318,22 +318,21 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
                goto fail;
        inode->i_mode = S_IFREG | 0444;
        inode->i_fop = &pstore_file_operations;
-       private = kzalloc(sizeof(*private), GFP_KERNEL);
-       if (!private)
-               goto fail_alloc;
-       private->record = record;
-
        scnprintf(name, sizeof(name), "%s-%s-%llu%s",
                        pstore_type_to_name(record->type),
                        record->psi->name, record->id,
                        record->compressed ? ".enc.z" : "");
 
+       private = kzalloc(sizeof(*private), GFP_KERNEL);
+       if (!private)
+               goto fail_inode;
+
        dentry = d_alloc_name(root, name);
        if (!dentry)
                goto fail_private;
 
+       private->record = record;
        inode->i_size = private->total_size = size;
-
        inode->i_private = private;
 
        if (record->time.tv_sec)
@@ -349,7 +348,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
 
 fail_private:
        free_pstore_private(private);
-fail_alloc:
+fail_inode:
        iput(inode);
 
 fail:
index 5b77098944151cb6f37e4516f6c5c02e28fc274f..2bb3468fc93aadc8a4e88e9f2aa911210eea7891 100644 (file)
@@ -655,6 +655,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
                            struct ramoops_platform_data *pdata)
 {
        struct device_node *of_node = pdev->dev.of_node;
+       struct device_node *parent_node;
        struct resource *res;
        u32 value;
        int ret;
@@ -689,6 +690,26 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 
 #undef parse_size
 
+       /*
+        * Some old Chromebooks relied on the kernel setting the
+        * console_size and pmsg_size to the record size since that's
+        * what the downstream kernel did.  These same Chromebooks had
+        * "ramoops" straight under the root node which isn't
+        * according to the current upstream bindings (though it was
+        * arguably acceptable under a prior version of the bindings).
+        * Let's make those old Chromebooks work by detecting that
+        * we're not a child of "reserved-memory" and mimicking the
+        * expected behavior.
+        */
+       parent_node = of_get_parent(of_node);
+       if (!of_node_name_eq(parent_node, "reserved-memory") &&
+           !pdata->console_size && !pdata->ftrace_size &&
+           !pdata->pmsg_size && !pdata->ecc_info.ecc_size) {
+               pdata->console_size = pdata->record_size;
+               pdata->pmsg_size = pdata->record_size;
+       }
+       of_node_put(parent_node);
+
        return 0;
 }