1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/capability.h>
23#include <linux/types.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/module.h>
28#include <linux/string.h>
29#include <linux/smp.h>
30#include <linux/efi.h>
31#include <linux/sysfs.h>
32#include <linux/device.h>
33#include <linux/slab.h>
34#include <linux/ctype.h>
35#include <linux/ucs2_string.h>
36
37
38static struct efivars *__efivars;
39
40
41
42
43
44
45
46static DEFINE_SEMAPHORE(efivars_lock);
47
48static bool efivar_wq_enabled = true;
49DECLARE_WORK(efivar_work, NULL);
50EXPORT_SYMBOL_GPL(efivar_work);
51
52static bool
53validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
54 unsigned long len)
55{
56 struct efi_generic_dev_path *node;
57 int offset = 0;
58
59 node = (struct efi_generic_dev_path *)buffer;
60
61 if (len < sizeof(*node))
62 return false;
63
64 while (offset <= len - sizeof(*node) &&
65 node->length >= sizeof(*node) &&
66 node->length <= len - offset) {
67 offset += node->length;
68
69 if ((node->type == EFI_DEV_END_PATH ||
70 node->type == EFI_DEV_END_PATH2) &&
71 node->sub_type == EFI_DEV_END_ENTIRE)
72 return true;
73
74 node = (struct efi_generic_dev_path *)(buffer + offset);
75 }
76
77
78
79
80
81
82 return false;
83}
84
85static bool
86validate_boot_order(efi_char16_t *var_name, int match, u8 *buffer,
87 unsigned long len)
88{
89
90 if ((len % 2) != 0)
91 return false;
92
93 return true;
94}
95
96static bool
97validate_load_option(efi_char16_t *var_name, int match, u8 *buffer,
98 unsigned long len)
99{
100 u16 filepathlength;
101 int i, desclength = 0, namelen;
102
103 namelen = ucs2_strnlen(var_name, EFI_VAR_NAME_LEN);
104
105
106 for (i = match; i < match+4; i++) {
107 if (var_name[i] > 127 ||
108 hex_to_bin(var_name[i] & 0xff) < 0)
109 return true;
110 }
111
112
113 if (namelen > match + 4)
114 return false;
115
116
117 if (len < 8)
118 return false;
119
120 filepathlength = buffer[4] | buffer[5] << 8;
121
122
123
124
125
126 desclength = ucs2_strsize((efi_char16_t *)(buffer + 6), len - 6) + 2;
127
128
129 if (!desclength)
130 return false;
131
132
133
134
135
136
137 if ((desclength + filepathlength + 6) > len)
138 return false;
139
140
141
142
143 return validate_device_path(var_name, match, buffer + desclength + 6,
144 filepathlength);
145}
146
147static bool
148validate_uint16(efi_char16_t *var_name, int match, u8 *buffer,
149 unsigned long len)
150{
151
152 if (len != 2)
153 return false;
154
155 return true;
156}
157
158static bool
159validate_ascii_string(efi_char16_t *var_name, int match, u8 *buffer,
160 unsigned long len)
161{
162 int i;
163
164 for (i = 0; i < len; i++) {
165 if (buffer[i] > 127)
166 return false;
167
168 if (buffer[i] == 0)
169 return true;
170 }
171
172 return false;
173}
174
175struct variable_validate {
176 efi_guid_t vendor;
177 char *name;
178 bool (*validate)(efi_char16_t *var_name, int match, u8 *data,
179 unsigned long len);
180};
181
182
183
184
185
186
187
188
189
190
191
192
193static const struct variable_validate variable_validate[] = {
194 { EFI_GLOBAL_VARIABLE_GUID, "BootNext", validate_uint16 },
195 { EFI_GLOBAL_VARIABLE_GUID, "BootOrder", validate_boot_order },
196 { EFI_GLOBAL_VARIABLE_GUID, "Boot*", validate_load_option },
197 { EFI_GLOBAL_VARIABLE_GUID, "DriverOrder", validate_boot_order },
198 { EFI_GLOBAL_VARIABLE_GUID, "Driver*", validate_load_option },
199 { EFI_GLOBAL_VARIABLE_GUID, "ConIn", validate_device_path },
200 { EFI_GLOBAL_VARIABLE_GUID, "ConInDev", validate_device_path },
201 { EFI_GLOBAL_VARIABLE_GUID, "ConOut", validate_device_path },
202 { EFI_GLOBAL_VARIABLE_GUID, "ConOutDev", validate_device_path },
203 { EFI_GLOBAL_VARIABLE_GUID, "ErrOut", validate_device_path },
204 { EFI_GLOBAL_VARIABLE_GUID, "ErrOutDev", validate_device_path },
205 { EFI_GLOBAL_VARIABLE_GUID, "Lang", validate_ascii_string },
206 { EFI_GLOBAL_VARIABLE_GUID, "OsIndications", NULL },
207 { EFI_GLOBAL_VARIABLE_GUID, "PlatformLang", validate_ascii_string },
208 { EFI_GLOBAL_VARIABLE_GUID, "Timeout", validate_uint16 },
209 { LINUX_EFI_CRASH_GUID, "*", NULL },
210 { NULL_GUID, "", NULL },
211};
212
213
214
215
216
217
218
219
220
221
222
223
224static bool
225variable_matches(const char *var_name, size_t len, const char *match_name,
226 int *match)
227{
228 for (*match = 0; ; (*match)++) {
229 char c = match_name[*match];
230
231 switch (c) {
232 case '*':
233
234 return true;
235
236 case '\0':
237
238 return (*match == len);
239
240 default:
241
242
243
244
245
246 if (*match < len && c == var_name[*match])
247 continue;
248 return false;
249 }
250 }
251}
252
253bool
254efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
255 unsigned long data_size)
256{
257 int i;
258 unsigned long utf8_size;
259 u8 *utf8_name;
260
261 utf8_size = ucs2_utf8size(var_name);
262 utf8_name = kmalloc(utf8_size + 1, GFP_KERNEL);
263 if (!utf8_name)
264 return false;
265
266 ucs2_as_utf8(utf8_name, var_name, utf8_size);
267 utf8_name[utf8_size] = '\0';
268
269 for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
270 const char *name = variable_validate[i].name;
271 int match = 0;
272
273 if (efi_guidcmp(vendor, variable_validate[i].vendor))
274 continue;
275
276 if (variable_matches(utf8_name, utf8_size+1, name, &match)) {
277 if (variable_validate[i].validate == NULL)
278 break;
279 kfree(utf8_name);
280 return variable_validate[i].validate(var_name, match,
281 data, data_size);
282 }
283 }
284 kfree(utf8_name);
285 return true;
286}
287EXPORT_SYMBOL_GPL(efivar_validate);
288
289bool
290efivar_variable_is_removable(efi_guid_t vendor, const char *var_name,
291 size_t len)
292{
293 int i;
294 bool found = false;
295 int match = 0;
296
297
298
299
300 for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
301 if (efi_guidcmp(variable_validate[i].vendor, vendor))
302 continue;
303
304 if (variable_matches(var_name, len,
305 variable_validate[i].name, &match)) {
306 found = true;
307 break;
308 }
309 }
310
311
312
313
314 return found;
315}
316EXPORT_SYMBOL_GPL(efivar_variable_is_removable);
317
318static efi_status_t
319check_var_size(u32 attributes, unsigned long size)
320{
321 const struct efivar_operations *fops = __efivars->ops;
322
323 if (!fops->query_variable_store)
324 return EFI_UNSUPPORTED;
325
326 return fops->query_variable_store(attributes, size, false);
327}
328
329static efi_status_t
330check_var_size_nonblocking(u32 attributes, unsigned long size)
331{
332 const struct efivar_operations *fops = __efivars->ops;
333
334 if (!fops->query_variable_store)
335 return EFI_UNSUPPORTED;
336
337 return fops->query_variable_store(attributes, size, true);
338}
339
340static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor,
341 struct list_head *head)
342{
343 struct efivar_entry *entry, *n;
344 unsigned long strsize1, strsize2;
345 bool found = false;
346
347 strsize1 = ucs2_strsize(variable_name, 1024);
348 list_for_each_entry_safe(entry, n, head, list) {
349 strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
350 if (strsize1 == strsize2 &&
351 !memcmp(variable_name, &(entry->var.VariableName),
352 strsize2) &&
353 !efi_guidcmp(entry->var.VendorGuid,
354 *vendor)) {
355 found = true;
356 break;
357 }
358 }
359 return found;
360}
361
362
363
364
365
366
367static unsigned long var_name_strnsize(efi_char16_t *variable_name,
368 unsigned long variable_name_size)
369{
370 unsigned long len;
371 efi_char16_t c;
372
373
374
375
376
377
378 for (len = 2; len <= variable_name_size; len += sizeof(c)) {
379 c = variable_name[(len / sizeof(c)) - 1];
380 if (!c)
381 break;
382 }
383
384 return min(len, variable_name_size);
385}
386
387
388
389
390
391static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid,
392 unsigned long len16)
393{
394 size_t i, len8 = len16 / sizeof(efi_char16_t);
395 char *str8;
396
397
398
399
400
401
402 efivar_wq_enabled = false;
403
404 str8 = kzalloc(len8, GFP_KERNEL);
405 if (!str8)
406 return;
407
408 for (i = 0; i < len8; i++)
409 str8[i] = str16[i];
410
411 printk(KERN_WARNING "efivars: duplicate variable: %s-%pUl\n",
412 str8, vendor_guid);
413 kfree(str8);
414}
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
430 void *data, bool duplicates, struct list_head *head)
431{
432 const struct efivar_operations *ops = __efivars->ops;
433 unsigned long variable_name_size = 1024;
434 efi_char16_t *variable_name;
435 efi_status_t status;
436 efi_guid_t vendor_guid;
437 int err = 0;
438
439 variable_name = kzalloc(variable_name_size, GFP_KERNEL);
440 if (!variable_name) {
441 printk(KERN_ERR "efivars: Memory allocation failed.\n");
442 return -ENOMEM;
443 }
444
445 if (down_interruptible(&efivars_lock)) {
446 err = -EINTR;
447 goto free;
448 }
449
450
451
452
453
454
455 do {
456 variable_name_size = 1024;
457
458 status = ops->get_next_variable(&variable_name_size,
459 variable_name,
460 &vendor_guid);
461 switch (status) {
462 case EFI_SUCCESS:
463 if (duplicates)
464 up(&efivars_lock);
465
466 variable_name_size = var_name_strnsize(variable_name,
467 variable_name_size);
468
469
470
471
472
473
474
475
476
477 if (duplicates &&
478 variable_is_present(variable_name, &vendor_guid,
479 head)) {
480 dup_variable_bug(variable_name, &vendor_guid,
481 variable_name_size);
482 status = EFI_NOT_FOUND;
483 } else {
484 err = func(variable_name, vendor_guid,
485 variable_name_size, data);
486 if (err)
487 status = EFI_NOT_FOUND;
488 }
489
490 if (duplicates) {
491 if (down_interruptible(&efivars_lock)) {
492 err = -EINTR;
493 goto free;
494 }
495 }
496
497 break;
498 case EFI_NOT_FOUND:
499 break;
500 default:
501 printk(KERN_WARNING "efivars: get_next_variable: status=%lx\n",
502 status);
503 status = EFI_NOT_FOUND;
504 break;
505 }
506
507 } while (status != EFI_NOT_FOUND);
508
509 up(&efivars_lock);
510free:
511 kfree(variable_name);
512
513 return err;
514}
515EXPORT_SYMBOL_GPL(efivar_init);
516
517
518
519
520
521
522
523
524int efivar_entry_add(struct efivar_entry *entry, struct list_head *head)
525{
526 if (down_interruptible(&efivars_lock))
527 return -EINTR;
528 list_add(&entry->list, head);
529 up(&efivars_lock);
530
531 return 0;
532}
533EXPORT_SYMBOL_GPL(efivar_entry_add);
534
535
536
537
538
539
540
541int efivar_entry_remove(struct efivar_entry *entry)
542{
543 if (down_interruptible(&efivars_lock))
544 return -EINTR;
545 list_del(&entry->list);
546 up(&efivars_lock);
547
548 return 0;
549}
550EXPORT_SYMBOL_GPL(efivar_entry_remove);
551
552
553
554
555
556
557
558
559
560
561
562
563static void efivar_entry_list_del_unlock(struct efivar_entry *entry)
564{
565 list_del(&entry->list);
566 up(&efivars_lock);
567}
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584int __efivar_entry_delete(struct efivar_entry *entry)
585{
586 const struct efivar_operations *ops = __efivars->ops;
587 efi_status_t status;
588
589 status = ops->set_variable(entry->var.VariableName,
590 &entry->var.VendorGuid,
591 0, 0, NULL);
592
593 return efi_status_to_err(status);
594}
595EXPORT_SYMBOL_GPL(__efivar_entry_delete);
596
597
598
599
600
601
602
603
604
605
606
607
608int efivar_entry_delete(struct efivar_entry *entry)
609{
610 const struct efivar_operations *ops = __efivars->ops;
611 efi_status_t status;
612
613 if (down_interruptible(&efivars_lock))
614 return -EINTR;
615
616 status = ops->set_variable(entry->var.VariableName,
617 &entry->var.VendorGuid,
618 0, 0, NULL);
619 if (!(status == EFI_SUCCESS || status == EFI_NOT_FOUND)) {
620 up(&efivars_lock);
621 return efi_status_to_err(status);
622 }
623
624 efivar_entry_list_del_unlock(entry);
625 return 0;
626}
627EXPORT_SYMBOL_GPL(efivar_entry_delete);
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
651 unsigned long size, void *data, struct list_head *head)
652{
653 const struct efivar_operations *ops = __efivars->ops;
654 efi_status_t status;
655 efi_char16_t *name = entry->var.VariableName;
656 efi_guid_t vendor = entry->var.VendorGuid;
657
658 if (down_interruptible(&efivars_lock))
659 return -EINTR;
660 if (head && efivar_entry_find(name, vendor, head, false)) {
661 up(&efivars_lock);
662 return -EEXIST;
663 }
664
665 status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
666 if (status == EFI_SUCCESS || status == EFI_UNSUPPORTED)
667 status = ops->set_variable(name, &vendor,
668 attributes, size, data);
669
670 up(&efivars_lock);
671
672 return efi_status_to_err(status);
673
674}
675EXPORT_SYMBOL_GPL(efivar_entry_set);
676
677
678
679
680
681
682
683
684
685
686static int
687efivar_entry_set_nonblocking(efi_char16_t *name, efi_guid_t vendor,
688 u32 attributes, unsigned long size, void *data)
689{
690 const struct efivar_operations *ops = __efivars->ops;
691 efi_status_t status;
692
693 if (down_trylock(&efivars_lock))
694 return -EBUSY;
695
696 status = check_var_size_nonblocking(attributes,
697 size + ucs2_strsize(name, 1024));
698 if (status != EFI_SUCCESS) {
699 up(&efivars_lock);
700 return -ENOSPC;
701 }
702
703 status = ops->set_variable_nonblocking(name, &vendor, attributes,
704 size, data);
705
706 up(&efivars_lock);
707 return efi_status_to_err(status);
708}
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
728 bool block, unsigned long size, void *data)
729{
730 const struct efivar_operations *ops = __efivars->ops;
731 efi_status_t status;
732
733 if (!ops->query_variable_store)
734 return -ENOSYS;
735
736
737
738
739
740
741
742
743
744
745
746 if (!block && ops->set_variable_nonblocking)
747 return efivar_entry_set_nonblocking(name, vendor, attributes,
748 size, data);
749
750 if (!block) {
751 if (down_trylock(&efivars_lock))
752 return -EBUSY;
753 } else {
754 if (down_interruptible(&efivars_lock))
755 return -EINTR;
756 }
757
758 status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
759 if (status != EFI_SUCCESS) {
760 up(&efivars_lock);
761 return -ENOSPC;
762 }
763
764 status = ops->set_variable(name, &vendor, attributes, size, data);
765
766 up(&efivars_lock);
767
768 return efi_status_to_err(status);
769}
770EXPORT_SYMBOL_GPL(efivar_entry_set_safe);
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
790 struct list_head *head, bool remove)
791{
792 struct efivar_entry *entry, *n;
793 int strsize1, strsize2;
794 bool found = false;
795
796 list_for_each_entry_safe(entry, n, head, list) {
797 strsize1 = ucs2_strsize(name, 1024);
798 strsize2 = ucs2_strsize(entry->var.VariableName, 1024);
799 if (strsize1 == strsize2 &&
800 !memcmp(name, &(entry->var.VariableName), strsize1) &&
801 !efi_guidcmp(guid, entry->var.VendorGuid)) {
802 found = true;
803 break;
804 }
805 }
806
807 if (!found)
808 return NULL;
809
810 if (remove) {
811 if (entry->scanning) {
812
813
814
815
816 entry->deleting = true;
817 } else
818 list_del(&entry->list);
819 }
820
821 return entry;
822}
823EXPORT_SYMBOL_GPL(efivar_entry_find);
824
825
826
827
828
829
830int efivar_entry_size(struct efivar_entry *entry, unsigned long *size)
831{
832 const struct efivar_operations *ops = __efivars->ops;
833 efi_status_t status;
834
835 *size = 0;
836
837 if (down_interruptible(&efivars_lock))
838 return -EINTR;
839 status = ops->get_variable(entry->var.VariableName,
840 &entry->var.VendorGuid, NULL, size, NULL);
841 up(&efivars_lock);
842
843 if (status != EFI_BUFFER_TOO_SMALL)
844 return efi_status_to_err(status);
845
846 return 0;
847}
848EXPORT_SYMBOL_GPL(efivar_entry_size);
849
850
851
852
853
854
855
856
857
858
859
860
861int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
862 unsigned long *size, void *data)
863{
864 const struct efivar_operations *ops = __efivars->ops;
865 efi_status_t status;
866
867 status = ops->get_variable(entry->var.VariableName,
868 &entry->var.VendorGuid,
869 attributes, size, data);
870
871 return efi_status_to_err(status);
872}
873EXPORT_SYMBOL_GPL(__efivar_entry_get);
874
875
876
877
878
879
880
881
882int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
883 unsigned long *size, void *data)
884{
885 const struct efivar_operations *ops = __efivars->ops;
886 efi_status_t status;
887
888 if (down_interruptible(&efivars_lock))
889 return -EINTR;
890 status = ops->get_variable(entry->var.VariableName,
891 &entry->var.VendorGuid,
892 attributes, size, data);
893 up(&efivars_lock);
894
895 return efi_status_to_err(status);
896}
897EXPORT_SYMBOL_GPL(efivar_entry_get);
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
922 unsigned long *size, void *data, bool *set)
923{
924 const struct efivar_operations *ops = __efivars->ops;
925 efi_char16_t *name = entry->var.VariableName;
926 efi_guid_t *vendor = &entry->var.VendorGuid;
927 efi_status_t status;
928 int err;
929
930 *set = false;
931
932 if (efivar_validate(*vendor, name, data, *size) == false)
933 return -EINVAL;
934
935
936
937
938
939
940 if (down_interruptible(&efivars_lock))
941 return -EINTR;
942
943
944
945
946 status = check_var_size(attributes, *size + ucs2_strsize(name, 1024));
947 if (status != EFI_SUCCESS) {
948 if (status != EFI_UNSUPPORTED) {
949 err = efi_status_to_err(status);
950 goto out;
951 }
952
953 if (*size > 65536) {
954 err = -ENOSPC;
955 goto out;
956 }
957 }
958
959 status = ops->set_variable(name, vendor, attributes, *size, data);
960 if (status != EFI_SUCCESS) {
961 err = efi_status_to_err(status);
962 goto out;
963 }
964
965 *set = true;
966
967
968
969
970
971
972
973 *size = 0;
974 status = ops->get_variable(entry->var.VariableName,
975 &entry->var.VendorGuid,
976 NULL, size, NULL);
977
978 if (status == EFI_NOT_FOUND)
979 efivar_entry_list_del_unlock(entry);
980 else
981 up(&efivars_lock);
982
983 if (status && status != EFI_BUFFER_TOO_SMALL)
984 return efi_status_to_err(status);
985
986 return 0;
987
988out:
989 up(&efivars_lock);
990 return err;
991
992}
993EXPORT_SYMBOL_GPL(efivar_entry_set_get_size);
994
995
996
997
998
999
1000
1001
1002int efivar_entry_iter_begin(void)
1003{
1004 return down_interruptible(&efivars_lock);
1005}
1006EXPORT_SYMBOL_GPL(efivar_entry_iter_begin);
1007
1008
1009
1010
1011
1012
1013void efivar_entry_iter_end(void)
1014{
1015 up(&efivars_lock);
1016}
1017EXPORT_SYMBOL_GPL(efivar_entry_iter_end);
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1042 struct list_head *head, void *data,
1043 struct efivar_entry **prev)
1044{
1045 struct efivar_entry *entry, *n;
1046 int err = 0;
1047
1048 if (!prev || !*prev) {
1049 list_for_each_entry_safe(entry, n, head, list) {
1050 err = func(entry, data);
1051 if (err)
1052 break;
1053 }
1054
1055 if (prev)
1056 *prev = entry;
1057
1058 return err;
1059 }
1060
1061
1062 list_for_each_entry_safe_continue((*prev), n, head, list) {
1063 err = func(*prev, data);
1064 if (err)
1065 break;
1066 }
1067
1068 return err;
1069}
1070EXPORT_SYMBOL_GPL(__efivar_entry_iter);
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1087 struct list_head *head, void *data)
1088{
1089 int err = 0;
1090
1091 err = efivar_entry_iter_begin();
1092 if (err)
1093 return err;
1094 err = __efivar_entry_iter(func, head, data, NULL);
1095 efivar_entry_iter_end();
1096
1097 return err;
1098}
1099EXPORT_SYMBOL_GPL(efivar_entry_iter);
1100
1101
1102
1103
1104
1105
1106
1107struct kobject *efivars_kobject(void)
1108{
1109 if (!__efivars)
1110 return NULL;
1111
1112 return __efivars->kobject;
1113}
1114EXPORT_SYMBOL_GPL(efivars_kobject);
1115
1116
1117
1118
1119void efivar_run_worker(void)
1120{
1121 if (efivar_wq_enabled)
1122 schedule_work(&efivar_work);
1123}
1124EXPORT_SYMBOL_GPL(efivar_run_worker);
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134int efivars_register(struct efivars *efivars,
1135 const struct efivar_operations *ops,
1136 struct kobject *kobject)
1137{
1138 if (down_interruptible(&efivars_lock))
1139 return -EINTR;
1140
1141 efivars->ops = ops;
1142 efivars->kobject = kobject;
1143
1144 __efivars = efivars;
1145
1146 pr_info("Registered efivars operations\n");
1147
1148 up(&efivars_lock);
1149
1150 return 0;
1151}
1152EXPORT_SYMBOL_GPL(efivars_register);
1153
1154
1155
1156
1157
1158
1159
1160
1161int efivars_unregister(struct efivars *efivars)
1162{
1163 int rv;
1164
1165 if (down_interruptible(&efivars_lock))
1166 return -EINTR;
1167
1168 if (!__efivars) {
1169 printk(KERN_ERR "efivars not registered\n");
1170 rv = -EINVAL;
1171 goto out;
1172 }
1173
1174 if (__efivars != efivars) {
1175 rv = -EINVAL;
1176 goto out;
1177 }
1178
1179 pr_info("Unregistered efivars operations\n");
1180 __efivars = NULL;
1181
1182 rv = 0;
1183out:
1184 up(&efivars_lock);
1185 return rv;
1186}
1187EXPORT_SYMBOL_GPL(efivars_unregister);
1188