forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/firmware/efi/vars.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Originally from efivars.c
34 *
45 * Copyright (C) 2001,2003,2004 Dell <Matt_Domsch@dell.com>
56 * Copyright (C) 2004 Intel Corporation <matthew.e.tolentino@intel.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
207 */
218
229 #include <linux/capability.h>
....@@ -44,10 +31,6 @@
4431 * 3) (un)registration of __efivars
4532 */
4633 static DEFINE_SEMAPHORE(efivars_lock);
47
-
48
-static bool efivar_wq_enabled = true;
49
-DECLARE_WORK(efivar_work, NULL);
50
-EXPORT_SYMBOL_GPL(efivar_work);
5134
5235 static bool
5336 validate_device_path(efi_char16_t *var_name, int match, u8 *buffer,
....@@ -404,13 +387,6 @@
404387 size_t i, len8 = len16 / sizeof(efi_char16_t);
405388 char *str8;
406389
407
- /*
408
- * Disable the workqueue since the algorithm it uses for
409
- * detecting new variables won't work with this buggy
410
- * implementation of GetNextVariableName().
411
- */
412
- efivar_wq_enabled = false;
413
-
414390 str8 = kzalloc(len8, GFP_KERNEL);
415391 if (!str8)
416392 return;
....@@ -427,7 +403,6 @@
427403 * efivar_init - build the initial list of EFI variables
428404 * @func: callback function to invoke for every variable
429405 * @data: function-specific data to pass to @func
430
- * @atomic: do we need to execute the @func-loop atomically?
431406 * @duplicates: error if we encounter duplicates on @head?
432407 * @head: initialised head of variable list
433408 *
....@@ -509,6 +484,10 @@
509484 }
510485 }
511486
487
+ break;
488
+ case EFI_UNSUPPORTED:
489
+ err = -EOPNOTSUPP;
490
+ status = EFI_NOT_FOUND;
512491 break;
513492 case EFI_NOT_FOUND:
514493 break;
....@@ -763,6 +742,7 @@
763742 {
764743 const struct efivar_operations *ops;
765744 efi_status_t status;
745
+ unsigned long varsize;
766746
767747 if (!__efivars)
768748 return -EINVAL;
....@@ -785,15 +765,17 @@
785765 return efivar_entry_set_nonblocking(name, vendor, attributes,
786766 size, data);
787767
768
+ varsize = size + ucs2_strsize(name, 1024);
788769 if (!block) {
789770 if (down_trylock(&efivars_lock))
790771 return -EBUSY;
772
+ status = check_var_size_nonblocking(attributes, varsize);
791773 } else {
792774 if (down_interruptible(&efivars_lock))
793775 return -EINTR;
776
+ status = check_var_size(attributes, varsize);
794777 }
795778
796
- status = check_var_size(attributes, size + ucs2_strsize(name, 1024));
797779 if (status != EFI_SUCCESS) {
798780 up(&efivars_lock);
799781 return -ENOSPC;
....@@ -1084,7 +1066,7 @@
10841066 * entry on the list. It is safe for @func to remove entries in the
10851067 * list via efivar_entry_delete().
10861068 *
1087
- * You MUST call efivar_enter_iter_begin() before this function, and
1069
+ * You MUST call efivar_entry_iter_begin() before this function, and
10881070 * efivar_entry_iter_end() afterwards.
10891071 *
10901072 * It is possible to begin iteration from an arbitrary entry within
....@@ -1171,16 +1153,6 @@
11711153 EXPORT_SYMBOL_GPL(efivars_kobject);
11721154
11731155 /**
1174
- * efivar_run_worker - schedule the efivar worker thread
1175
- */
1176
-void efivar_run_worker(void)
1177
-{
1178
- if (efivar_wq_enabled)
1179
- schedule_work(&efivar_work);
1180
-}
1181
-EXPORT_SYMBOL_GPL(efivar_run_worker);
1182
-
1183
-/**
11841156 * efivars_register - register an efivars
11851157 * @efivars: efivars to register
11861158 * @ops: efivars operations
....@@ -1242,3 +1214,9 @@
12421214 return rv;
12431215 }
12441216 EXPORT_SYMBOL_GPL(efivars_unregister);
1217
+
1218
+int efivar_supports_writes(void)
1219
+{
1220
+ return __efivars && __efivars->ops->set_variable;
1221
+}
1222
+EXPORT_SYMBOL_GPL(efivar_supports_writes);