X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Ffirmware%2Fefivars.c;h=343379f23a53cf432b98118c00e095b497aa6e6c;hb=987b0145d94eecf292d8b301228356f44611ab7c;hp=bac72bbaf7236ecf74c12197eea707e6533e1788;hpb=5167311cae6aa3a5ff5afd39f88c32a435c969ef;p=linux-2.6.git diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index bac72bbaf..343379f23 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c @@ -65,11 +65,11 @@ * v0.01 release to linux-ia64@linuxia64.org */ +#include #include #include #include #include -#include /* for capable() */ #include #include #include @@ -97,7 +97,7 @@ MODULE_VERSION(EFIVARS_VERSION); * efi.get_next_variable() is only called from efivars_init(), * which is protected by the BKL, so that path is safe. */ -static spinlock_t efivars_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(efivars_lock); static LIST_HEAD(efivar_list); /* @@ -352,7 +352,7 @@ static ssize_t efivar_attr_show(struct kobject *kobj, struct attribute *attr, { struct efivar_entry *var = to_efivar_entry(kobj); struct efivar_attribute *efivar_attr = to_efivar_attr(attr); - ssize_t ret = 0; + ssize_t ret = -EIO; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -368,7 +368,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr, { struct efivar_entry *var = to_efivar_entry(kobj); struct efivar_attribute *efivar_attr = to_efivar_attr(attr); - ssize_t ret = 0; + ssize_t ret = -EIO; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -614,16 +614,14 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, char *short_name; struct efivar_entry *new_efivar; - short_name = kmalloc(short_name_size + 1, GFP_KERNEL); - new_efivar = kmalloc(sizeof(struct efivar_entry), GFP_KERNEL); + short_name = kzalloc(short_name_size + 1, GFP_KERNEL); + new_efivar = kzalloc(sizeof(struct efivar_entry), GFP_KERNEL); if (!short_name || !new_efivar) { - if (short_name) kfree(short_name); - if (new_efivar) kfree(new_efivar); + kfree(short_name); + kfree(new_efivar); return 1; } - memset(short_name, 0, short_name_size+1); - memset(new_efivar, 0, sizeof(struct efivar_entry)); memcpy(new_efivar->var.VariableName, variable_name, variable_name_size); @@ -644,7 +642,8 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, kobj_set_kset_s(new_efivar, vars_subsys); kobject_register(&new_efivar->kobj); - kfree(short_name); short_name = NULL; + kfree(short_name); + short_name = NULL; spin_lock(&efivars_lock); list_add(&new_efivar->list, &efivar_list); @@ -665,14 +664,20 @@ efivars_init(void) { efi_status_t status = EFI_NOT_FOUND; efi_guid_t vendor_guid; - efi_char16_t *variable_name = kmalloc(1024, GFP_KERNEL); + efi_char16_t *variable_name; struct subsys_attribute *attr; unsigned long variable_name_size = 1024; - int i, rc = 0, error = 0; + int i, error = 0; if (!efi_enabled) return -ENODEV; + variable_name = kzalloc(variable_name_size, GFP_KERNEL); + if (!variable_name) { + printk(KERN_ERR "efivars: Memory allocation failed.\n"); + return -ENOMEM; + } + printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, EFIVARS_DATE); @@ -680,21 +685,27 @@ efivars_init(void) * For now we'll register the efi subsys within this driver */ - rc = firmware_register(&efi_subsys); + error = firmware_register(&efi_subsys); - if (rc) - return rc; + if (error) { + printk(KERN_ERR "efivars: Firmware registration failed with error %d.\n", error); + goto out_free; + } kset_set_kset_s(&vars_subsys, efi_subsys); - subsystem_register(&vars_subsys); + + error = subsystem_register(&vars_subsys); + + if (error) { + printk(KERN_ERR "efivars: Subsystem registration failed with error %d.\n", error); + goto out_firmware_unregister; + } /* * Per EFI spec, the maximum storage allocated for both * the variable name and variable data is 1024 bytes. */ - memset(variable_name, 0, 1024); - do { variable_name_size = 1024; @@ -734,8 +745,20 @@ efivars_init(void) error = subsys_create_file(&efi_subsys, attr); } + if (error) + printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error); + else + goto out_free; + + subsystem_unregister(&vars_subsys); + +out_firmware_unregister: + firmware_unregister(&efi_subsys); + +out_free: kfree(variable_name); - return 0; + + return error; } static void __exit