]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/firmware/efi/efivars.c
efivar: fix oops in efivar_update_sysfs_entries() caused by memory reuse
[karo-tx-linux.git] / drivers / firmware / efi / efivars.c
index 70635b3b59d39d8751ceb4848d56ca962eb8f210..8bd1bb6dbe4739cf0914a129a12363c1bf157820 100644 (file)
@@ -67,6 +67,8 @@
 
 #include <linux/efi.h>
 #include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/ucs2_string.h>
 
 #define EFIVARS_VERSION "0.08"
 #define EFIVARS_DATE "2004-May-17"
@@ -407,7 +409,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
        efi_char16_t *variable_name;
 
        variable_name = new_var->var.VariableName;
-       variable_name_size = utf16_strlen(variable_name) * sizeof(efi_char16_t);
+       variable_name_size = ucs2_strlen(variable_name) * sizeof(efi_char16_t);
 
        /*
         * Length of the variable bytes in ASCII, plus the '-' separator,
@@ -418,10 +420,8 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
 
        short_name = kzalloc(short_name_size, GFP_KERNEL);
 
-       if (!short_name) {
-               kfree(short_name);
+       if (!short_name)
                return 1;
-       }
 
        /* Convert Unicode to normal chars (assume top bits are 0),
           ala UTF-8 */
@@ -523,13 +523,11 @@ static void efivar_update_sysfs_entries(struct work_struct *work)
        struct efivar_entry *entry;
        int err;
 
-       entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-       if (!entry)
-               return;
-
        /* Add new sysfs entries */
        while (1) {
-               memset(entry, 0, sizeof(*entry));
+               entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+               if (!entry)
+                       return;
 
                err = efivar_init(efivar_update_sysfs_entry, entry,
                                  true, false, &efivar_sysfs_list);