efivars.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  1. /*
  2. * EFI Variables - efivars.c
  3. *
  4. * Copyright (C) 2001,2003,2004 Dell <Matt_Domsch@dell.com>
  5. * Copyright (C) 2004 Intel Corporation <matthew.e.tolentino@intel.com>
  6. *
  7. * This code takes all variables accessible from EFI runtime and
  8. * 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_unparse()
  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
  66. */
  67. #include <linux/capability.h>
  68. #include <linux/types.h>
  69. #include <linux/errno.h>
  70. #include <linux/init.h>
  71. #include <linux/mm.h>
  72. #include <linux/module.h>
  73. #include <linux/string.h>
  74. #include <linux/smp.h>
  75. #include <linux/efi.h>
  76. #include <linux/sysfs.h>
  77. #include <linux/kobject.h>
  78. #include <linux/device.h>
  79. #include <linux/slab.h>
  80. #include <linux/pstore.h>
  81. #include <asm/uaccess.h>
  82. #define EFIVARS_VERSION "0.08"
  83. #define EFIVARS_DATE "2004-May-17"
  84. MODULE_AUTHOR("Matt Domsch <Matt_Domsch@Dell.com>");
  85. MODULE_DESCRIPTION("sysfs interface to EFI Variables");
  86. MODULE_LICENSE("GPL");
  87. MODULE_VERSION(EFIVARS_VERSION);
  88. #define DUMP_NAME_LEN 52
  89. /*
  90. * The maximum size of VariableName + Data = 1024
  91. * Therefore, it's reasonable to save that much
  92. * space in each part of the structure,
  93. * and we use a page for reading/writing.
  94. */
  95. struct efi_variable {
  96. efi_char16_t VariableName[1024/sizeof(efi_char16_t)];
  97. efi_guid_t VendorGuid;
  98. unsigned long DataSize;
  99. __u8 Data[1024];
  100. efi_status_t Status;
  101. __u32 Attributes;
  102. } __attribute__((packed));
  103. struct efivar_entry {
  104. struct efivars *efivars;
  105. struct efi_variable var;
  106. struct list_head list;
  107. struct kobject kobj;
  108. };
  109. struct efivar_attribute {
  110. struct attribute attr;
  111. ssize_t (*show) (struct efivar_entry *entry, char *buf);
  112. ssize_t (*store)(struct efivar_entry *entry, const char *buf, size_t count);
  113. };
  114. #define PSTORE_EFI_ATTRIBUTES \
  115. (EFI_VARIABLE_NON_VOLATILE | \
  116. EFI_VARIABLE_BOOTSERVICE_ACCESS | \
  117. EFI_VARIABLE_RUNTIME_ACCESS)
  118. #define EFIVAR_ATTR(_name, _mode, _show, _store) \
  119. struct efivar_attribute efivar_attr_##_name = { \
  120. .attr = {.name = __stringify(_name), .mode = _mode}, \
  121. .show = _show, \
  122. .store = _store, \
  123. };
  124. #define to_efivar_attr(_attr) container_of(_attr, struct efivar_attribute, attr)
  125. #define to_efivar_entry(obj) container_of(obj, struct efivar_entry, kobj)
  126. /*
  127. * Prototype for sysfs creation function
  128. */
  129. static int
  130. efivar_create_sysfs_entry(struct efivars *efivars,
  131. unsigned long variable_name_size,
  132. efi_char16_t *variable_name,
  133. efi_guid_t *vendor_guid);
  134. /* Return the number of unicode characters in data */
  135. static unsigned long
  136. utf16_strnlen(efi_char16_t *s, size_t maxlength)
  137. {
  138. unsigned long length = 0;
  139. while (*s++ != 0 && length < maxlength)
  140. length++;
  141. return length;
  142. }
  143. static inline unsigned long
  144. utf16_strlen(efi_char16_t *s)
  145. {
  146. return utf16_strnlen(s, ~0UL);
  147. }
  148. /*
  149. * Return the number of bytes is the length of this string
  150. * Note: this is NOT the same as the number of unicode characters
  151. */
  152. static inline unsigned long
  153. utf16_strsize(efi_char16_t *data, unsigned long maxlength)
  154. {
  155. return utf16_strnlen(data, maxlength/sizeof(efi_char16_t)) * sizeof(efi_char16_t);
  156. }
  157. static inline int
  158. utf16_strncmp(const efi_char16_t *a, const efi_char16_t *b, size_t len)
  159. {
  160. while (1) {
  161. if (len == 0)
  162. return 0;
  163. if (*a < *b)
  164. return -1;
  165. if (*a > *b)
  166. return 1;
  167. if (*a == 0) /* implies *b == 0 */
  168. return 0;
  169. a++;
  170. b++;
  171. len--;
  172. }
  173. }
  174. static bool
  175. validate_device_path(struct efi_variable *var, int match, u8 *buffer,
  176. unsigned long len)
  177. {
  178. struct efi_generic_dev_path *node;
  179. int offset = 0;
  180. node = (struct efi_generic_dev_path *)buffer;
  181. if (len < sizeof(*node))
  182. return false;
  183. while (offset <= len - sizeof(*node) &&
  184. node->length >= sizeof(*node) &&
  185. node->length <= len - offset) {
  186. offset += node->length;
  187. if ((node->type == EFI_DEV_END_PATH ||
  188. node->type == EFI_DEV_END_PATH2) &&
  189. node->sub_type == EFI_DEV_END_ENTIRE)
  190. return true;
  191. node = (struct efi_generic_dev_path *)(buffer + offset);
  192. }
  193. /*
  194. * If we're here then either node->length pointed past the end
  195. * of the buffer or we reached the end of the buffer without
  196. * finding a device path end node.
  197. */
  198. return false;
  199. }
  200. static bool
  201. validate_boot_order(struct efi_variable *var, int match, u8 *buffer,
  202. unsigned long len)
  203. {
  204. /* An array of 16-bit integers */
  205. if ((len % 2) != 0)
  206. return false;
  207. return true;
  208. }
  209. static bool
  210. validate_load_option(struct efi_variable *var, int match, u8 *buffer,
  211. unsigned long len)
  212. {
  213. u16 filepathlength;
  214. int i, desclength = 0, namelen;
  215. namelen = utf16_strnlen(var->VariableName, sizeof(var->VariableName));
  216. /* Either "Boot" or "Driver" followed by four digits of hex */
  217. for (i = match; i < match+4; i++) {
  218. if (var->VariableName[i] > 127 ||
  219. hex_to_bin(var->VariableName[i] & 0xff) < 0)
  220. return true;
  221. }
  222. /* Reject it if there's 4 digits of hex and then further content */
  223. if (namelen > match + 4)
  224. return false;
  225. /* A valid entry must be at least 8 bytes */
  226. if (len < 8)
  227. return false;
  228. filepathlength = buffer[4] | buffer[5] << 8;
  229. /*
  230. * There's no stored length for the description, so it has to be
  231. * found by hand
  232. */
  233. desclength = utf16_strsize((efi_char16_t *)(buffer + 6), len - 6) + 2;
  234. /* Each boot entry must have a descriptor */
  235. if (!desclength)
  236. return false;
  237. /*
  238. * If the sum of the length of the description, the claimed filepath
  239. * length and the original header are greater than the length of the
  240. * variable, it's malformed
  241. */
  242. if ((desclength + filepathlength + 6) > len)
  243. return false;
  244. /*
  245. * And, finally, check the filepath
  246. */
  247. return validate_device_path(var, match, buffer + desclength + 6,
  248. filepathlength);
  249. }
  250. static bool
  251. validate_uint16(struct efi_variable *var, int match, u8 *buffer,
  252. unsigned long len)
  253. {
  254. /* A single 16-bit integer */
  255. if (len != 2)
  256. return false;
  257. return true;
  258. }
  259. static bool
  260. validate_ascii_string(struct efi_variable *var, int match, u8 *buffer,
  261. unsigned long len)
  262. {
  263. int i;
  264. for (i = 0; i < len; i++) {
  265. if (buffer[i] > 127)
  266. return false;
  267. if (buffer[i] == 0)
  268. return true;
  269. }
  270. return false;
  271. }
  272. struct variable_validate {
  273. char *name;
  274. bool (*validate)(struct efi_variable *var, int match, u8 *data,
  275. unsigned long len);
  276. };
  277. static const struct variable_validate variable_validate[] = {
  278. { "BootNext", validate_uint16 },
  279. { "BootOrder", validate_boot_order },
  280. { "DriverOrder", validate_boot_order },
  281. { "Boot*", validate_load_option },
  282. { "Driver*", validate_load_option },
  283. { "ConIn", validate_device_path },
  284. { "ConInDev", validate_device_path },
  285. { "ConOut", validate_device_path },
  286. { "ConOutDev", validate_device_path },
  287. { "ErrOut", validate_device_path },
  288. { "ErrOutDev", validate_device_path },
  289. { "Timeout", validate_uint16 },
  290. { "Lang", validate_ascii_string },
  291. { "PlatformLang", validate_ascii_string },
  292. { "", NULL },
  293. };
  294. static bool
  295. validate_var(struct efi_variable *var, u8 *data, unsigned long len)
  296. {
  297. int i;
  298. u16 *unicode_name = var->VariableName;
  299. for (i = 0; variable_validate[i].validate != NULL; i++) {
  300. const char *name = variable_validate[i].name;
  301. int match;
  302. for (match = 0; ; match++) {
  303. char c = name[match];
  304. u16 u = unicode_name[match];
  305. /* All special variables are plain ascii */
  306. if (u > 127)
  307. return true;
  308. /* Wildcard in the matching name means we've matched */
  309. if (c == '*')
  310. return variable_validate[i].validate(var,
  311. match, data, len);
  312. /* Case sensitive match */
  313. if (c != u)
  314. break;
  315. /* Reached the end of the string while matching */
  316. if (!c)
  317. return variable_validate[i].validate(var,
  318. match, data, len);
  319. }
  320. }
  321. return true;
  322. }
  323. static efi_status_t
  324. get_var_data_locked(struct efivars *efivars, struct efi_variable *var)
  325. {
  326. efi_status_t status;
  327. var->DataSize = 1024;
  328. status = efivars->ops->get_variable(var->VariableName,
  329. &var->VendorGuid,
  330. &var->Attributes,
  331. &var->DataSize,
  332. var->Data);
  333. return status;
  334. }
  335. static efi_status_t
  336. get_var_data(struct efivars *efivars, struct efi_variable *var)
  337. {
  338. efi_status_t status;
  339. spin_lock(&efivars->lock);
  340. status = get_var_data_locked(efivars, var);
  341. spin_unlock(&efivars->lock);
  342. if (status != EFI_SUCCESS) {
  343. printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n",
  344. status);
  345. }
  346. return status;
  347. }
  348. static ssize_t
  349. efivar_guid_read(struct efivar_entry *entry, char *buf)
  350. {
  351. struct efi_variable *var = &entry->var;
  352. char *str = buf;
  353. if (!entry || !buf)
  354. return 0;
  355. efi_guid_unparse(&var->VendorGuid, str);
  356. str += strlen(str);
  357. str += sprintf(str, "\n");
  358. return str - buf;
  359. }
  360. static ssize_t
  361. efivar_attr_read(struct efivar_entry *entry, char *buf)
  362. {
  363. struct efi_variable *var = &entry->var;
  364. char *str = buf;
  365. efi_status_t status;
  366. if (!entry || !buf)
  367. return -EINVAL;
  368. status = get_var_data(entry->efivars, var);
  369. if (status != EFI_SUCCESS)
  370. return -EIO;
  371. if (var->Attributes & EFI_VARIABLE_NON_VOLATILE)
  372. str += sprintf(str, "EFI_VARIABLE_NON_VOLATILE\n");
  373. if (var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)
  374. str += sprintf(str, "EFI_VARIABLE_BOOTSERVICE_ACCESS\n");
  375. if (var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)
  376. str += sprintf(str, "EFI_VARIABLE_RUNTIME_ACCESS\n");
  377. if (var->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD)
  378. str += sprintf(str, "EFI_VARIABLE_HARDWARE_ERROR_RECORD\n");
  379. if (var->Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)
  380. str += sprintf(str,
  381. "EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\n");
  382. if (var->Attributes &
  383. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)
  384. str += sprintf(str,
  385. "EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\n");
  386. if (var->Attributes & EFI_VARIABLE_APPEND_WRITE)
  387. str += sprintf(str, "EFI_VARIABLE_APPEND_WRITE\n");
  388. return str - buf;
  389. }
  390. static ssize_t
  391. efivar_size_read(struct efivar_entry *entry, char *buf)
  392. {
  393. struct efi_variable *var = &entry->var;
  394. char *str = buf;
  395. efi_status_t status;
  396. if (!entry || !buf)
  397. return -EINVAL;
  398. status = get_var_data(entry->efivars, var);
  399. if (status != EFI_SUCCESS)
  400. return -EIO;
  401. str += sprintf(str, "0x%lx\n", var->DataSize);
  402. return str - buf;
  403. }
  404. static ssize_t
  405. efivar_data_read(struct efivar_entry *entry, char *buf)
  406. {
  407. struct efi_variable *var = &entry->var;
  408. efi_status_t status;
  409. if (!entry || !buf)
  410. return -EINVAL;
  411. status = get_var_data(entry->efivars, var);
  412. if (status != EFI_SUCCESS)
  413. return -EIO;
  414. memcpy(buf, var->Data, var->DataSize);
  415. return var->DataSize;
  416. }
  417. /*
  418. * We allow each variable to be edited via rewriting the
  419. * entire efi variable structure.
  420. */
  421. static ssize_t
  422. efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
  423. {
  424. struct efi_variable *new_var, *var = &entry->var;
  425. struct efivars *efivars = entry->efivars;
  426. efi_status_t status = EFI_NOT_FOUND;
  427. if (count != sizeof(struct efi_variable))
  428. return -EINVAL;
  429. new_var = (struct efi_variable *)buf;
  430. /*
  431. * If only updating the variable data, then the name
  432. * and guid should remain the same
  433. */
  434. if (memcmp(new_var->VariableName, var->VariableName, sizeof(var->VariableName)) ||
  435. efi_guidcmp(new_var->VendorGuid, var->VendorGuid)) {
  436. printk(KERN_ERR "efivars: Cannot edit the wrong variable!\n");
  437. return -EINVAL;
  438. }
  439. if ((new_var->DataSize <= 0) || (new_var->Attributes == 0)){
  440. printk(KERN_ERR "efivars: DataSize & Attributes must be valid!\n");
  441. return -EINVAL;
  442. }
  443. if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
  444. validate_var(new_var, new_var->Data, new_var->DataSize) == false) {
  445. printk(KERN_ERR "efivars: Malformed variable content\n");
  446. return -EINVAL;
  447. }
  448. spin_lock(&efivars->lock);
  449. status = efivars->ops->set_variable(new_var->VariableName,
  450. &new_var->VendorGuid,
  451. new_var->Attributes,
  452. new_var->DataSize,
  453. new_var->Data);
  454. spin_unlock(&efivars->lock);
  455. if (status != EFI_SUCCESS) {
  456. printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
  457. status);
  458. return -EIO;
  459. }
  460. memcpy(&entry->var, new_var, count);
  461. return count;
  462. }
  463. static ssize_t
  464. efivar_show_raw(struct efivar_entry *entry, char *buf)
  465. {
  466. struct efi_variable *var = &entry->var;
  467. efi_status_t status;
  468. if (!entry || !buf)
  469. return 0;
  470. status = get_var_data(entry->efivars, var);
  471. if (status != EFI_SUCCESS)
  472. return -EIO;
  473. memcpy(buf, var, sizeof(*var));
  474. return sizeof(*var);
  475. }
  476. /*
  477. * Generic read/write functions that call the specific functions of
  478. * the attributes...
  479. */
  480. static ssize_t efivar_attr_show(struct kobject *kobj, struct attribute *attr,
  481. char *buf)
  482. {
  483. struct efivar_entry *var = to_efivar_entry(kobj);
  484. struct efivar_attribute *efivar_attr = to_efivar_attr(attr);
  485. ssize_t ret = -EIO;
  486. if (!capable(CAP_SYS_ADMIN))
  487. return -EACCES;
  488. if (efivar_attr->show) {
  489. ret = efivar_attr->show(var, buf);
  490. }
  491. return ret;
  492. }
  493. static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
  494. const char *buf, size_t count)
  495. {
  496. struct efivar_entry *var = to_efivar_entry(kobj);
  497. struct efivar_attribute *efivar_attr = to_efivar_attr(attr);
  498. ssize_t ret = -EIO;
  499. if (!capable(CAP_SYS_ADMIN))
  500. return -EACCES;
  501. if (efivar_attr->store)
  502. ret = efivar_attr->store(var, buf, count);
  503. return ret;
  504. }
  505. static const struct sysfs_ops efivar_attr_ops = {
  506. .show = efivar_attr_show,
  507. .store = efivar_attr_store,
  508. };
  509. static void efivar_release(struct kobject *kobj)
  510. {
  511. struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj);
  512. kfree(var);
  513. }
  514. static EFIVAR_ATTR(guid, 0400, efivar_guid_read, NULL);
  515. static EFIVAR_ATTR(attributes, 0400, efivar_attr_read, NULL);
  516. static EFIVAR_ATTR(size, 0400, efivar_size_read, NULL);
  517. static EFIVAR_ATTR(data, 0400, efivar_data_read, NULL);
  518. static EFIVAR_ATTR(raw_var, 0600, efivar_show_raw, efivar_store_raw);
  519. static struct attribute *def_attrs[] = {
  520. &efivar_attr_guid.attr,
  521. &efivar_attr_size.attr,
  522. &efivar_attr_attributes.attr,
  523. &efivar_attr_data.attr,
  524. &efivar_attr_raw_var.attr,
  525. NULL,
  526. };
  527. static struct kobj_type efivar_ktype = {
  528. .release = efivar_release,
  529. .sysfs_ops = &efivar_attr_ops,
  530. .default_attrs = def_attrs,
  531. };
  532. static struct pstore_info efi_pstore_info;
  533. static inline void
  534. efivar_unregister(struct efivar_entry *var)
  535. {
  536. kobject_put(&var->kobj);
  537. }
  538. #ifdef CONFIG_PSTORE
  539. static int efi_pstore_open(struct pstore_info *psi)
  540. {
  541. struct efivars *efivars = psi->data;
  542. spin_lock(&efivars->lock);
  543. efivars->walk_entry = list_first_entry(&efivars->list,
  544. struct efivar_entry, list);
  545. return 0;
  546. }
  547. static int efi_pstore_close(struct pstore_info *psi)
  548. {
  549. struct efivars *efivars = psi->data;
  550. spin_unlock(&efivars->lock);
  551. return 0;
  552. }
  553. static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
  554. struct timespec *timespec,
  555. char **buf, struct pstore_info *psi)
  556. {
  557. efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
  558. struct efivars *efivars = psi->data;
  559. char name[DUMP_NAME_LEN];
  560. int i;
  561. unsigned int part, size;
  562. unsigned long time;
  563. while (&efivars->walk_entry->list != &efivars->list) {
  564. if (!efi_guidcmp(efivars->walk_entry->var.VendorGuid,
  565. vendor)) {
  566. for (i = 0; i < DUMP_NAME_LEN; i++) {
  567. name[i] = efivars->walk_entry->var.VariableName[i];
  568. }
  569. if (sscanf(name, "dump-type%u-%u-%lu", type, &part, &time) == 3) {
  570. *id = part;
  571. timespec->tv_sec = time;
  572. timespec->tv_nsec = 0;
  573. get_var_data_locked(efivars, &efivars->walk_entry->var);
  574. size = efivars->walk_entry->var.DataSize;
  575. *buf = kmalloc(size, GFP_KERNEL);
  576. if (*buf == NULL)
  577. return -ENOMEM;
  578. memcpy(*buf, efivars->walk_entry->var.Data,
  579. size);
  580. efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
  581. struct efivar_entry, list);
  582. return size;
  583. }
  584. }
  585. efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
  586. struct efivar_entry, list);
  587. }
  588. return 0;
  589. }
  590. static int efi_pstore_write(enum pstore_type_id type,
  591. enum kmsg_dump_reason reason, u64 *id,
  592. unsigned int part, size_t size, struct pstore_info *psi)
  593. {
  594. char name[DUMP_NAME_LEN];
  595. char stub_name[DUMP_NAME_LEN];
  596. efi_char16_t efi_name[DUMP_NAME_LEN];
  597. efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
  598. struct efivars *efivars = psi->data;
  599. struct efivar_entry *entry, *found = NULL;
  600. int i, ret = 0;
  601. u64 storage_space, remaining_space, max_variable_size;
  602. efi_status_t status = EFI_NOT_FOUND;
  603. sprintf(stub_name, "dump-type%u-%u-", type, part);
  604. sprintf(name, "%s%lu", stub_name, get_seconds());
  605. spin_lock(&efivars->lock);
  606. /*
  607. * Check if there is a space enough to log.
  608. * size: a size of logging data
  609. * DUMP_NAME_LEN * 2: a maximum size of variable name
  610. */
  611. status = efivars->ops->query_variable_info(PSTORE_EFI_ATTRIBUTES,
  612. &storage_space,
  613. &remaining_space,
  614. &max_variable_size);
  615. if (status || remaining_space < size + DUMP_NAME_LEN * 2) {
  616. spin_unlock(&efivars->lock);
  617. *id = part;
  618. return -ENOSPC;
  619. }
  620. for (i = 0; i < DUMP_NAME_LEN; i++)
  621. efi_name[i] = stub_name[i];
  622. /*
  623. * Clean up any entries with the same name
  624. */
  625. list_for_each_entry(entry, &efivars->list, list) {
  626. get_var_data_locked(efivars, &entry->var);
  627. if (efi_guidcmp(entry->var.VendorGuid, vendor))
  628. continue;
  629. if (utf16_strncmp(entry->var.VariableName, efi_name,
  630. utf16_strlen(efi_name)))
  631. continue;
  632. /* Needs to be a prefix */
  633. if (entry->var.VariableName[utf16_strlen(efi_name)] == 0)
  634. continue;
  635. /* found */
  636. found = entry;
  637. efivars->ops->set_variable(entry->var.VariableName,
  638. &entry->var.VendorGuid,
  639. PSTORE_EFI_ATTRIBUTES,
  640. 0, NULL);
  641. }
  642. if (found)
  643. list_del(&found->list);
  644. for (i = 0; i < DUMP_NAME_LEN; i++)
  645. efi_name[i] = name[i];
  646. efivars->ops->set_variable(efi_name, &vendor, PSTORE_EFI_ATTRIBUTES,
  647. size, psi->buf);
  648. spin_unlock(&efivars->lock);
  649. if (found)
  650. efivar_unregister(found);
  651. if (size)
  652. ret = efivar_create_sysfs_entry(efivars,
  653. utf16_strsize(efi_name,
  654. DUMP_NAME_LEN * 2),
  655. efi_name, &vendor);
  656. *id = part;
  657. return ret;
  658. };
  659. static int efi_pstore_erase(enum pstore_type_id type, u64 id,
  660. struct pstore_info *psi)
  661. {
  662. char stub_name[DUMP_NAME_LEN];
  663. efi_char16_t efi_name[DUMP_NAME_LEN];
  664. efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
  665. struct efivars *efivars = psi->data;
  666. struct efivar_entry *entry, *found = NULL;
  667. int i;
  668. sprintf(stub_name, "dump-type%u-%u-", type, (unsigned int)id);
  669. spin_lock(&efivars->lock);
  670. for (i = 0; i < DUMP_NAME_LEN; i++)
  671. efi_name[i] = stub_name[i];
  672. /*
  673. * Clean up any entries with the same name
  674. */
  675. list_for_each_entry(entry, &efivars->list, list) {
  676. get_var_data_locked(efivars, &entry->var);
  677. if (efi_guidcmp(entry->var.VendorGuid, vendor))
  678. continue;
  679. if (utf16_strncmp(entry->var.VariableName, efi_name,
  680. utf16_strlen(efi_name)))
  681. continue;
  682. /* Needs to be a prefix */
  683. if (entry->var.VariableName[utf16_strlen(efi_name)] == 0)
  684. continue;
  685. /* found */
  686. found = entry;
  687. efivars->ops->set_variable(entry->var.VariableName,
  688. &entry->var.VendorGuid,
  689. PSTORE_EFI_ATTRIBUTES,
  690. 0, NULL);
  691. }
  692. if (found)
  693. list_del(&found->list);
  694. spin_unlock(&efivars->lock);
  695. if (found)
  696. efivar_unregister(found);
  697. return 0;
  698. }
  699. #else
  700. static int efi_pstore_open(struct pstore_info *psi)
  701. {
  702. return 0;
  703. }
  704. static int efi_pstore_close(struct pstore_info *psi)
  705. {
  706. return 0;
  707. }
  708. static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
  709. struct timespec *timespec,
  710. char **buf, struct pstore_info *psi)
  711. {
  712. return -1;
  713. }
  714. static int efi_pstore_write(enum pstore_type_id type,
  715. enum kmsg_dump_reason reason, u64 *id,
  716. unsigned int part, size_t size, struct pstore_info *psi)
  717. {
  718. return 0;
  719. }
  720. static int efi_pstore_erase(enum pstore_type_id type, u64 id,
  721. struct pstore_info *psi)
  722. {
  723. return 0;
  724. }
  725. #endif
  726. static struct pstore_info efi_pstore_info = {
  727. .owner = THIS_MODULE,
  728. .name = "efi",
  729. .open = efi_pstore_open,
  730. .close = efi_pstore_close,
  731. .read = efi_pstore_read,
  732. .write = efi_pstore_write,
  733. .erase = efi_pstore_erase,
  734. };
  735. static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
  736. struct bin_attribute *bin_attr,
  737. char *buf, loff_t pos, size_t count)
  738. {
  739. struct efi_variable *new_var = (struct efi_variable *)buf;
  740. struct efivars *efivars = bin_attr->private;
  741. struct efivar_entry *search_efivar, *n;
  742. unsigned long strsize1, strsize2;
  743. efi_status_t status = EFI_NOT_FOUND;
  744. int found = 0;
  745. if (!capable(CAP_SYS_ADMIN))
  746. return -EACCES;
  747. if ((new_var->Attributes & ~EFI_VARIABLE_MASK) != 0 ||
  748. validate_var(new_var, new_var->Data, new_var->DataSize) == false) {
  749. printk(KERN_ERR "efivars: Malformed variable content\n");
  750. return -EINVAL;
  751. }
  752. spin_lock(&efivars->lock);
  753. /*
  754. * Does this variable already exist?
  755. */
  756. list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
  757. strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024);
  758. strsize2 = utf16_strsize(new_var->VariableName, 1024);
  759. if (strsize1 == strsize2 &&
  760. !memcmp(&(search_efivar->var.VariableName),
  761. new_var->VariableName, strsize1) &&
  762. !efi_guidcmp(search_efivar->var.VendorGuid,
  763. new_var->VendorGuid)) {
  764. found = 1;
  765. break;
  766. }
  767. }
  768. if (found) {
  769. spin_unlock(&efivars->lock);
  770. return -EINVAL;
  771. }
  772. /* now *really* create the variable via EFI */
  773. status = efivars->ops->set_variable(new_var->VariableName,
  774. &new_var->VendorGuid,
  775. new_var->Attributes,
  776. new_var->DataSize,
  777. new_var->Data);
  778. if (status != EFI_SUCCESS) {
  779. printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
  780. status);
  781. spin_unlock(&efivars->lock);
  782. return -EIO;
  783. }
  784. spin_unlock(&efivars->lock);
  785. /* Create the entry in sysfs. Locking is not required here */
  786. status = efivar_create_sysfs_entry(efivars,
  787. utf16_strsize(new_var->VariableName,
  788. 1024),
  789. new_var->VariableName,
  790. &new_var->VendorGuid);
  791. if (status) {
  792. printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n");
  793. }
  794. return count;
  795. }
  796. static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
  797. struct bin_attribute *bin_attr,
  798. char *buf, loff_t pos, size_t count)
  799. {
  800. struct efi_variable *del_var = (struct efi_variable *)buf;
  801. struct efivars *efivars = bin_attr->private;
  802. struct efivar_entry *search_efivar, *n;
  803. unsigned long strsize1, strsize2;
  804. efi_status_t status = EFI_NOT_FOUND;
  805. int found = 0;
  806. if (!capable(CAP_SYS_ADMIN))
  807. return -EACCES;
  808. spin_lock(&efivars->lock);
  809. /*
  810. * Does this variable already exist?
  811. */
  812. list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
  813. strsize1 = utf16_strsize(search_efivar->var.VariableName, 1024);
  814. strsize2 = utf16_strsize(del_var->VariableName, 1024);
  815. if (strsize1 == strsize2 &&
  816. !memcmp(&(search_efivar->var.VariableName),
  817. del_var->VariableName, strsize1) &&
  818. !efi_guidcmp(search_efivar->var.VendorGuid,
  819. del_var->VendorGuid)) {
  820. found = 1;
  821. break;
  822. }
  823. }
  824. if (!found) {
  825. spin_unlock(&efivars->lock);
  826. return -EINVAL;
  827. }
  828. /* force the Attributes/DataSize to 0 to ensure deletion */
  829. del_var->Attributes = 0;
  830. del_var->DataSize = 0;
  831. status = efivars->ops->set_variable(del_var->VariableName,
  832. &del_var->VendorGuid,
  833. del_var->Attributes,
  834. del_var->DataSize,
  835. del_var->Data);
  836. if (status != EFI_SUCCESS) {
  837. printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
  838. status);
  839. spin_unlock(&efivars->lock);
  840. return -EIO;
  841. }
  842. list_del(&search_efivar->list);
  843. /* We need to release this lock before unregistering. */
  844. spin_unlock(&efivars->lock);
  845. efivar_unregister(search_efivar);
  846. /* It's dead Jim.... */
  847. return count;
  848. }
  849. /*
  850. * Let's not leave out systab information that snuck into
  851. * the efivars driver
  852. */
  853. static ssize_t systab_show(struct kobject *kobj,
  854. struct kobj_attribute *attr, char *buf)
  855. {
  856. char *str = buf;
  857. if (!kobj || !buf)
  858. return -EINVAL;
  859. if (efi.mps != EFI_INVALID_TABLE_ADDR)
  860. str += sprintf(str, "MPS=0x%lx\n", efi.mps);
  861. if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  862. str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20);
  863. if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  864. str += sprintf(str, "ACPI=0x%lx\n", efi.acpi);
  865. if (efi.smbios != EFI_INVALID_TABLE_ADDR)
  866. str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
  867. if (efi.hcdp != EFI_INVALID_TABLE_ADDR)
  868. str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp);
  869. if (efi.boot_info != EFI_INVALID_TABLE_ADDR)
  870. str += sprintf(str, "BOOTINFO=0x%lx\n", efi.boot_info);
  871. if (efi.uga != EFI_INVALID_TABLE_ADDR)
  872. str += sprintf(str, "UGA=0x%lx\n", efi.uga);
  873. return str - buf;
  874. }
  875. static struct kobj_attribute efi_attr_systab =
  876. __ATTR(systab, 0400, systab_show, NULL);
  877. static struct attribute *efi_subsys_attrs[] = {
  878. &efi_attr_systab.attr,
  879. NULL, /* maybe more in the future? */
  880. };
  881. static struct attribute_group efi_subsys_attr_group = {
  882. .attrs = efi_subsys_attrs,
  883. };
  884. static struct kobject *efi_kobj;
  885. /*
  886. * efivar_create_sysfs_entry()
  887. * Requires:
  888. * variable_name_size = number of bytes required to hold
  889. * variable_name (not counting the NULL
  890. * character at the end.
  891. * efivars->lock is not held on entry or exit.
  892. * Returns 1 on failure, 0 on success
  893. */
  894. static int
  895. efivar_create_sysfs_entry(struct efivars *efivars,
  896. unsigned long variable_name_size,
  897. efi_char16_t *variable_name,
  898. efi_guid_t *vendor_guid)
  899. {
  900. int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38;
  901. char *short_name;
  902. struct efivar_entry *new_efivar;
  903. short_name = kzalloc(short_name_size + 1, GFP_KERNEL);
  904. new_efivar = kzalloc(sizeof(struct efivar_entry), GFP_KERNEL);
  905. if (!short_name || !new_efivar) {
  906. kfree(short_name);
  907. kfree(new_efivar);
  908. return 1;
  909. }
  910. new_efivar->efivars = efivars;
  911. memcpy(new_efivar->var.VariableName, variable_name,
  912. variable_name_size);
  913. memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t));
  914. /* Convert Unicode to normal chars (assume top bits are 0),
  915. ala UTF-8 */
  916. for (i=0; i < (int)(variable_name_size / sizeof(efi_char16_t)); i++) {
  917. short_name[i] = variable_name[i] & 0xFF;
  918. }
  919. /* This is ugly, but necessary to separate one vendor's
  920. private variables from another's. */
  921. *(short_name + strlen(short_name)) = '-';
  922. efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
  923. new_efivar->kobj.kset = efivars->kset;
  924. i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL,
  925. "%s", short_name);
  926. if (i) {
  927. kfree(short_name);
  928. kfree(new_efivar);
  929. return 1;
  930. }
  931. kobject_uevent(&new_efivar->kobj, KOBJ_ADD);
  932. kfree(short_name);
  933. short_name = NULL;
  934. spin_lock(&efivars->lock);
  935. list_add(&new_efivar->list, &efivars->list);
  936. spin_unlock(&efivars->lock);
  937. return 0;
  938. }
  939. static int
  940. create_efivars_bin_attributes(struct efivars *efivars)
  941. {
  942. struct bin_attribute *attr;
  943. int error;
  944. /* new_var */
  945. attr = kzalloc(sizeof(*attr), GFP_KERNEL);
  946. if (!attr)
  947. return -ENOMEM;
  948. attr->attr.name = "new_var";
  949. attr->attr.mode = 0200;
  950. attr->write = efivar_create;
  951. attr->private = efivars;
  952. efivars->new_var = attr;
  953. /* del_var */
  954. attr = kzalloc(sizeof(*attr), GFP_KERNEL);
  955. if (!attr) {
  956. error = -ENOMEM;
  957. goto out_free;
  958. }
  959. attr->attr.name = "del_var";
  960. attr->attr.mode = 0200;
  961. attr->write = efivar_delete;
  962. attr->private = efivars;
  963. efivars->del_var = attr;
  964. sysfs_bin_attr_init(efivars->new_var);
  965. sysfs_bin_attr_init(efivars->del_var);
  966. /* Register */
  967. error = sysfs_create_bin_file(&efivars->kset->kobj,
  968. efivars->new_var);
  969. if (error) {
  970. printk(KERN_ERR "efivars: unable to create new_var sysfs file"
  971. " due to error %d\n", error);
  972. goto out_free;
  973. }
  974. error = sysfs_create_bin_file(&efivars->kset->kobj,
  975. efivars->del_var);
  976. if (error) {
  977. printk(KERN_ERR "efivars: unable to create del_var sysfs file"
  978. " due to error %d\n", error);
  979. sysfs_remove_bin_file(&efivars->kset->kobj,
  980. efivars->new_var);
  981. goto out_free;
  982. }
  983. return 0;
  984. out_free:
  985. kfree(efivars->del_var);
  986. efivars->del_var = NULL;
  987. kfree(efivars->new_var);
  988. efivars->new_var = NULL;
  989. return error;
  990. }
  991. void unregister_efivars(struct efivars *efivars)
  992. {
  993. struct efivar_entry *entry, *n;
  994. list_for_each_entry_safe(entry, n, &efivars->list, list) {
  995. spin_lock(&efivars->lock);
  996. list_del(&entry->list);
  997. spin_unlock(&efivars->lock);
  998. efivar_unregister(entry);
  999. }
  1000. if (efivars->new_var)
  1001. sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var);
  1002. if (efivars->del_var)
  1003. sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var);
  1004. kfree(efivars->new_var);
  1005. kfree(efivars->del_var);
  1006. kset_unregister(efivars->kset);
  1007. }
  1008. EXPORT_SYMBOL_GPL(unregister_efivars);
  1009. int register_efivars(struct efivars *efivars,
  1010. const struct efivar_operations *ops,
  1011. struct kobject *parent_kobj)
  1012. {
  1013. efi_status_t status = EFI_NOT_FOUND;
  1014. efi_guid_t vendor_guid;
  1015. efi_char16_t *variable_name;
  1016. unsigned long variable_name_size = 1024;
  1017. int error = 0;
  1018. variable_name = kzalloc(variable_name_size, GFP_KERNEL);
  1019. if (!variable_name) {
  1020. printk(KERN_ERR "efivars: Memory allocation failed.\n");
  1021. return -ENOMEM;
  1022. }
  1023. spin_lock_init(&efivars->lock);
  1024. INIT_LIST_HEAD(&efivars->list);
  1025. efivars->ops = ops;
  1026. efivars->kset = kset_create_and_add("vars", NULL, parent_kobj);
  1027. if (!efivars->kset) {
  1028. printk(KERN_ERR "efivars: Subsystem registration failed.\n");
  1029. error = -ENOMEM;
  1030. goto out;
  1031. }
  1032. /*
  1033. * Per EFI spec, the maximum storage allocated for both
  1034. * the variable name and variable data is 1024 bytes.
  1035. */
  1036. do {
  1037. variable_name_size = 1024;
  1038. status = ops->get_next_variable(&variable_name_size,
  1039. variable_name,
  1040. &vendor_guid);
  1041. switch (status) {
  1042. case EFI_SUCCESS:
  1043. efivar_create_sysfs_entry(efivars,
  1044. variable_name_size,
  1045. variable_name,
  1046. &vendor_guid);
  1047. break;
  1048. case EFI_NOT_FOUND:
  1049. break;
  1050. default:
  1051. printk(KERN_WARNING "efivars: get_next_variable: status=%lx\n",
  1052. status);
  1053. status = EFI_NOT_FOUND;
  1054. break;
  1055. }
  1056. } while (status != EFI_NOT_FOUND);
  1057. error = create_efivars_bin_attributes(efivars);
  1058. if (error)
  1059. unregister_efivars(efivars);
  1060. efivars->efi_pstore_info = efi_pstore_info;
  1061. efivars->efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL);
  1062. if (efivars->efi_pstore_info.buf) {
  1063. efivars->efi_pstore_info.bufsize = 1024;
  1064. efivars->efi_pstore_info.data = efivars;
  1065. spin_lock_init(&efivars->efi_pstore_info.buf_lock);
  1066. pstore_register(&efivars->efi_pstore_info);
  1067. }
  1068. out:
  1069. kfree(variable_name);
  1070. return error;
  1071. }
  1072. EXPORT_SYMBOL_GPL(register_efivars);
  1073. static struct efivars __efivars;
  1074. static struct efivar_operations ops;
  1075. /*
  1076. * For now we register the efi subsystem with the firmware subsystem
  1077. * and the vars subsystem with the efi subsystem. In the future, it
  1078. * might make sense to split off the efi subsystem into its own
  1079. * driver, but for now only efivars will register with it, so just
  1080. * include it here.
  1081. */
  1082. static int __init
  1083. efivars_init(void)
  1084. {
  1085. int error = 0;
  1086. printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
  1087. EFIVARS_DATE);
  1088. if (!efi_enabled)
  1089. return 0;
  1090. /* For now we'll register the efi directory at /sys/firmware/efi */
  1091. efi_kobj = kobject_create_and_add("efi", firmware_kobj);
  1092. if (!efi_kobj) {
  1093. printk(KERN_ERR "efivars: Firmware registration failed.\n");
  1094. return -ENOMEM;
  1095. }
  1096. ops.get_variable = efi.get_variable;
  1097. ops.set_variable = efi.set_variable;
  1098. ops.get_next_variable = efi.get_next_variable;
  1099. ops.query_variable_info = efi.query_variable_info;
  1100. error = register_efivars(&__efivars, &ops, efi_kobj);
  1101. if (error)
  1102. goto err_put;
  1103. /* Don't forget the systab entry */
  1104. error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
  1105. if (error) {
  1106. printk(KERN_ERR
  1107. "efivars: Sysfs attribute export failed with error %d.\n",
  1108. error);
  1109. goto err_unregister;
  1110. }
  1111. return 0;
  1112. err_unregister:
  1113. unregister_efivars(&__efivars);
  1114. err_put:
  1115. kobject_put(efi_kobj);
  1116. return error;
  1117. }
  1118. static void __exit
  1119. efivars_exit(void)
  1120. {
  1121. if (efi_enabled) {
  1122. unregister_efivars(&__efivars);
  1123. kobject_put(efi_kobj);
  1124. }
  1125. }
  1126. module_init(efivars_init);
  1127. module_exit(efivars_exit);