diff options
author | Mike Waychison <mikew@google.com> | 2011-03-11 20:43:06 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-03-14 11:40:50 -0400 |
commit | d502fbb0dc4d4babe5fb330257fa49a83fbf86a6 (patch) | |
tree | 881fa3719f41f6f0f2a7ab22a3a479789590d48c /drivers/firmware/efivars.c | |
parent | 29422693c410c68071bdd60e0a0ec590490781aa (diff) |
efivars: Make efivars bin_attributes dynamic
In preparation for encapsulating efivars, we need to have the
bin_attributes be dynamically allocated so that we can use their
->private fields to get back to the struct efivars structure.
Signed-off-by: Mike Waychison <mikew@google.com>
Cc: Matt Domsch <Matt_Domsch@dell.com>,
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/firmware/efivars.c')
-rw-r--r-- | drivers/firmware/efivars.c | 93 |
1 files changed, 68 insertions, 25 deletions
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index f10ecb6d04b2..528ce47c1368 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
@@ -101,6 +101,7 @@ struct efivars { | |||
101 | spinlock_t lock; | 101 | spinlock_t lock; |
102 | struct list_head list; | 102 | struct list_head list; |
103 | struct kset *kset; | 103 | struct kset *kset; |
104 | struct bin_attribute *new_var, *del_var; | ||
104 | }; | 105 | }; |
105 | static struct efivars __efivars; | 106 | static struct efivars __efivars; |
106 | static struct efivars *efivars = &__efivars; | 107 | static struct efivars *efivars = &__efivars; |
@@ -525,16 +526,6 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj, | |||
525 | return count; | 526 | return count; |
526 | } | 527 | } |
527 | 528 | ||
528 | static struct bin_attribute var_subsys_attr_new_var = { | ||
529 | .attr = {.name = "new_var", .mode = 0200}, | ||
530 | .write = efivar_create, | ||
531 | }; | ||
532 | |||
533 | static struct bin_attribute var_subsys_attr_del_var = { | ||
534 | .attr = {.name = "del_var", .mode = 0200}, | ||
535 | .write = efivar_delete, | ||
536 | }; | ||
537 | |||
538 | /* | 529 | /* |
539 | * Let's not leave out systab information that snuck into | 530 | * Let's not leave out systab information that snuck into |
540 | * the efivars driver | 531 | * the efivars driver |
@@ -640,6 +631,66 @@ efivar_create_sysfs_entry(unsigned long variable_name_size, | |||
640 | 631 | ||
641 | return 0; | 632 | return 0; |
642 | } | 633 | } |
634 | |||
635 | static int | ||
636 | create_efivars_bin_attributes(struct efivars *efivars) | ||
637 | { | ||
638 | struct bin_attribute *attr; | ||
639 | int error; | ||
640 | |||
641 | /* new_var */ | ||
642 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | ||
643 | if (!attr) | ||
644 | return -ENOMEM; | ||
645 | |||
646 | attr->attr.name = "new_var"; | ||
647 | attr->attr.mode = 0200; | ||
648 | attr->write = efivar_create; | ||
649 | attr->private = efivars; | ||
650 | efivars->new_var = attr; | ||
651 | |||
652 | /* del_var */ | ||
653 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); | ||
654 | if (!attr) { | ||
655 | error = -ENOMEM; | ||
656 | goto out_free; | ||
657 | } | ||
658 | attr->attr.name = "del_var"; | ||
659 | attr->attr.mode = 0200; | ||
660 | attr->write = efivar_delete; | ||
661 | attr->private = efivars; | ||
662 | efivars->del_var = attr; | ||
663 | |||
664 | sysfs_bin_attr_init(efivars->new_var); | ||
665 | sysfs_bin_attr_init(efivars->del_var); | ||
666 | |||
667 | /* Register */ | ||
668 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
669 | efivars->new_var); | ||
670 | if (error) { | ||
671 | printk(KERN_ERR "efivars: unable to create new_var sysfs file" | ||
672 | " due to error %d\n", error); | ||
673 | goto out_free; | ||
674 | } | ||
675 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
676 | efivars->del_var); | ||
677 | if (error) { | ||
678 | printk(KERN_ERR "efivars: unable to create del_var sysfs file" | ||
679 | " due to error %d\n", error); | ||
680 | sysfs_remove_bin_file(&efivars->kset->kobj, | ||
681 | efivars->new_var); | ||
682 | goto out_free; | ||
683 | } | ||
684 | |||
685 | return 0; | ||
686 | out_free: | ||
687 | kfree(efivars->new_var); | ||
688 | efivars->new_var = NULL; | ||
689 | kfree(efivars->new_var); | ||
690 | efivars->new_var = NULL; | ||
691 | return error; | ||
692 | } | ||
693 | |||
643 | /* | 694 | /* |
644 | * For now we register the efi subsystem with the firmware subsystem | 695 | * For now we register the efi subsystem with the firmware subsystem |
645 | * and the vars subsystem with the efi subsystem. In the future, it | 696 | * and the vars subsystem with the efi subsystem. In the future, it |
@@ -714,20 +765,7 @@ efivars_init(void) | |||
714 | } | 765 | } |
715 | } while (status != EFI_NOT_FOUND); | 766 | } while (status != EFI_NOT_FOUND); |
716 | 767 | ||
717 | /* | 768 | error = create_efivars_bin_attributes(efivars); |
718 | * Now add attributes to allow creation of new vars | ||
719 | * and deletion of existing ones... | ||
720 | */ | ||
721 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
722 | &var_subsys_attr_new_var); | ||
723 | if (error) | ||
724 | printk(KERN_ERR "efivars: unable to create new_var sysfs file" | ||
725 | " due to error %d\n", error); | ||
726 | error = sysfs_create_bin_file(&efivars->kset->kobj, | ||
727 | &var_subsys_attr_del_var); | ||
728 | if (error) | ||
729 | printk(KERN_ERR "efivars: unable to create del_var sysfs file" | ||
730 | " due to error %d\n", error); | ||
731 | 769 | ||
732 | /* Don't forget the systab entry */ | 770 | /* Don't forget the systab entry */ |
733 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); | 771 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); |
@@ -758,7 +796,12 @@ efivars_exit(void) | |||
758 | spin_unlock(&efivars->lock); | 796 | spin_unlock(&efivars->lock); |
759 | efivar_unregister(entry); | 797 | efivar_unregister(entry); |
760 | } | 798 | } |
761 | 799 | if (efivars->new_var) | |
800 | sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var); | ||
801 | if (efivars->del_var) | ||
802 | sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var); | ||
803 | kfree(efivars->new_var); | ||
804 | kfree(efivars->del_var); | ||
762 | kset_unregister(efivars->kset); | 805 | kset_unregister(efivars->kset); |
763 | kobject_put(efi_kobj); | 806 | kobject_put(efi_kobj); |
764 | } | 807 | } |