forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/firmware/efi/efivars.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Originally from efivars.c,
34 *
....@@ -6,63 +7,6 @@
67 *
78 * This code takes all variables accessible from EFI runtime and
89 * exports them via sysfs
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
- *
24
- * Changelog:
25
- *
26
- * 17 May 2004 - Matt Domsch <Matt_Domsch@dell.com>
27
- * remove check for efi_enabled in exit
28
- * add MODULE_VERSION
29
- *
30
- * 26 Apr 2004 - Matt Domsch <Matt_Domsch@dell.com>
31
- * minor bug fixes
32
- *
33
- * 21 Apr 2004 - Matt Tolentino <matthew.e.tolentino@intel.com)
34
- * converted driver to export variable information via sysfs
35
- * and moved to drivers/firmware directory
36
- * bumped revision number to v0.07 to reflect conversion & move
37
- *
38
- * 10 Dec 2002 - Matt Domsch <Matt_Domsch@dell.com>
39
- * fix locking per Peter Chubb's findings
40
- *
41
- * 25 Mar 2002 - Matt Domsch <Matt_Domsch@dell.com>
42
- * move uuid_unparse() to include/asm-ia64/efi.h:efi_guid_to_str()
43
- *
44
- * 12 Feb 2002 - Matt Domsch <Matt_Domsch@dell.com>
45
- * use list_for_each_safe when deleting vars.
46
- * remove ifdef CONFIG_SMP around include <linux/smp.h>
47
- * v0.04 release to linux-ia64@linuxia64.org
48
- *
49
- * 20 April 2001 - Matt Domsch <Matt_Domsch@dell.com>
50
- * Moved vars from /proc/efi to /proc/efi/vars, and made
51
- * efi.c own the /proc/efi directory.
52
- * v0.03 release to linux-ia64@linuxia64.org
53
- *
54
- * 26 March 2001 - Matt Domsch <Matt_Domsch@dell.com>
55
- * At the request of Stephane, moved ownership of /proc/efi
56
- * to efi.c, and now efivars lives under /proc/efi/vars.
57
- *
58
- * 12 March 2001 - Matt Domsch <Matt_Domsch@dell.com>
59
- * Feedback received from Stephane Eranian incorporated.
60
- * efivar_write() checks copy_from_user() return value.
61
- * efivar_read/write() returns proper errno.
62
- * v0.02 release to linux-ia64@linuxia64.org
63
- *
64
- * 26 February 2001 - Matt Domsch <Matt_Domsch@dell.com>
65
- * v0.01 release to linux-ia64@linuxia64.org
6610 */
6711
6812 #include <linux/efi.h>
....@@ -78,10 +22,8 @@
7822 MODULE_DESCRIPTION("sysfs interface to EFI Variables");
7923 MODULE_LICENSE("GPL");
8024 MODULE_VERSION(EFIVARS_VERSION);
81
-MODULE_ALIAS("platform:efivars");
8225
83
-LIST_HEAD(efivar_sysfs_list);
84
-EXPORT_SYMBOL_GPL(efivar_sysfs_list);
26
+static LIST_HEAD(efivar_sysfs_list);
8527
8628 static struct kset *efivars_kset;
8729
....@@ -238,14 +180,6 @@
238180 return 0;
239181 }
240182
241
-static inline bool is_compat(void)
242
-{
243
- if (IS_ENABLED(CONFIG_COMPAT) && in_compat_syscall())
244
- return true;
245
-
246
- return false;
247
-}
248
-
249183 static void
250184 copy_out_compat(struct efi_variable *dst, struct compat_efi_variable *src)
251185 {
....@@ -275,7 +209,7 @@
275209 if (!entry || !buf)
276210 return -EINVAL;
277211
278
- if (is_compat()) {
212
+ if (in_compat_syscall()) {
279213 struct compat_efi_variable *compat;
280214
281215 if (count != sizeof(*compat))
....@@ -338,7 +272,7 @@
338272 if (ret)
339273 return -EIO;
340274
341
- if (is_compat()) {
275
+ if (in_compat_syscall()) {
342276 compat = (struct compat_efi_variable *)buf;
343277
344278 size = sizeof(*compat);
....@@ -432,7 +366,7 @@
432366 struct compat_efi_variable *compat = (struct compat_efi_variable *)buf;
433367 struct efi_variable *new_var = (struct efi_variable *)buf;
434368 struct efivar_entry *new_entry;
435
- bool need_compat = is_compat();
369
+ bool need_compat = in_compat_syscall();
436370 efi_char16_t *name;
437371 unsigned long size;
438372 u32 attributes;
....@@ -509,7 +443,7 @@
509443 if (!capable(CAP_SYS_ADMIN))
510444 return -EACCES;
511445
512
- if (is_compat()) {
446
+ if (in_compat_syscall()) {
513447 if (count != sizeof(*compat))
514448 return -EINVAL;
515449
....@@ -655,42 +589,6 @@
655589 return error;
656590 }
657591
658
-static int efivar_update_sysfs_entry(efi_char16_t *name, efi_guid_t vendor,
659
- unsigned long name_size, void *data)
660
-{
661
- struct efivar_entry *entry = data;
662
-
663
- if (efivar_entry_find(name, vendor, &efivar_sysfs_list, false))
664
- return 0;
665
-
666
- memcpy(entry->var.VariableName, name, name_size);
667
- memcpy(&(entry->var.VendorGuid), &vendor, sizeof(efi_guid_t));
668
-
669
- return 1;
670
-}
671
-
672
-static void efivar_update_sysfs_entries(struct work_struct *work)
673
-{
674
- struct efivar_entry *entry;
675
- int err;
676
-
677
- /* Add new sysfs entries */
678
- while (1) {
679
- entry = kzalloc(sizeof(*entry), GFP_KERNEL);
680
- if (!entry)
681
- return;
682
-
683
- err = efivar_init(efivar_update_sysfs_entry, entry,
684
- false, &efivar_sysfs_list);
685
- if (!err)
686
- break;
687
-
688
- efivar_create_sysfs_entry(entry);
689
- }
690
-
691
- kfree(entry);
692
-}
693
-
694592 static int efivars_sysfs_callback(efi_char16_t *name, efi_guid_t vendor,
695593 unsigned long name_size, void *data)
696594 {
....@@ -739,16 +637,13 @@
739637 kset_unregister(efivars_kset);
740638 }
741639
742
-int efivars_sysfs_init(void)
640
+static int efivars_sysfs_init(void)
743641 {
744642 struct kobject *parent_kobj = efivars_kobject();
745643 int error = 0;
746644
747
- if (!efi_enabled(EFI_RUNTIME_SERVICES))
748
- return -ENODEV;
749
-
750645 /* No efivars has been registered yet */
751
- if (!parent_kobj)
646
+ if (!parent_kobj || !efivar_supports_writes())
752647 return 0;
753648
754649 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
....@@ -768,11 +663,8 @@
768663 return error;
769664 }
770665
771
- INIT_WORK(&efivar_work, efivar_update_sysfs_entries);
772
-
773666 return 0;
774667 }
775
-EXPORT_SYMBOL_GPL(efivars_sysfs_init);
776668
777669 module_init(efivars_sysfs_init);
778670 module_exit(efivars_sysfs_exit);