dell-smbios-base.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Common functions for kernel modules using Dell SMBIOS
  4. *
  5. * Copyright (c) Red Hat <mjg@redhat.com>
  6. * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
  7. * Copyright (c) 2014 Pali Rohár <pali@kernel.org>
  8. *
  9. * Based on documentation in the libsmbios package:
  10. * Copyright (C) 2005-2014 Dell Inc.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/capability.h>
  16. #include <linux/dmi.h>
  17. #include <linux/err.h>
  18. #include <linux/mutex.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/slab.h>
  21. #include "dell-smbios.h"
  22. static u32 da_supported_commands;
  23. static int da_num_tokens;
  24. static struct platform_device *platform_device;
  25. static struct calling_interface_token *da_tokens;
  26. static struct device_attribute *token_location_attrs;
  27. static struct device_attribute *token_value_attrs;
  28. static struct attribute **token_attrs;
  29. static DEFINE_MUTEX(smbios_mutex);
  30. struct smbios_device {
  31. struct list_head list;
  32. struct device *device;
  33. int (*call_fn)(struct calling_interface_buffer *arg);
  34. };
  35. struct smbios_call {
  36. u32 need_capability;
  37. int cmd_class;
  38. int cmd_select;
  39. };
  40. /* calls that are whitelisted for given capabilities */
  41. static struct smbios_call call_whitelist[] = {
  42. /* generally tokens are allowed, but may be further filtered or
  43. * restricted by token blacklist or whitelist
  44. */
  45. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_STD},
  46. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_AC},
  47. {CAP_SYS_ADMIN, CLASS_TOKEN_READ, SELECT_TOKEN_BAT},
  48. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD},
  49. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_AC},
  50. {CAP_SYS_ADMIN, CLASS_TOKEN_WRITE, SELECT_TOKEN_BAT},
  51. /* used by userspace: fwupdate */
  52. {CAP_SYS_ADMIN, CLASS_ADMIN_PROP, SELECT_ADMIN_PROP},
  53. /* used by userspace: fwupd */
  54. {CAP_SYS_ADMIN, CLASS_INFO, SELECT_DOCK},
  55. {CAP_SYS_ADMIN, CLASS_FLASH_INTERFACE, SELECT_FLASH_INTERFACE},
  56. };
  57. /* calls that are explicitly blacklisted */
  58. static struct smbios_call call_blacklist[] = {
  59. {0x0000, 1, 7}, /* manufacturing use */
  60. {0x0000, 6, 5}, /* manufacturing use */
  61. {0x0000, 11, 3}, /* write once */
  62. {0x0000, 11, 7}, /* write once */
  63. {0x0000, 11, 11}, /* write once */
  64. {0x0000, 19, -1}, /* diagnostics */
  65. /* handled by kernel: dell-laptop */
  66. {0x0000, CLASS_INFO, SELECT_RFKILL},
  67. {0x0000, CLASS_KBD_BACKLIGHT, SELECT_KBD_BACKLIGHT},
  68. };
  69. struct token_range {
  70. u32 need_capability;
  71. u16 min;
  72. u16 max;
  73. };
  74. /* tokens that are whitelisted for given capabilities */
  75. static struct token_range token_whitelist[] = {
  76. /* used by userspace: fwupdate */
  77. {CAP_SYS_ADMIN, CAPSULE_EN_TOKEN, CAPSULE_DIS_TOKEN},
  78. /* can indicate to userspace that WMI is needed */
  79. {0x0000, WSMT_EN_TOKEN, WSMT_DIS_TOKEN}
  80. };
  81. /* tokens that are explicitly blacklisted */
  82. static struct token_range token_blacklist[] = {
  83. {0x0000, 0x0058, 0x0059}, /* ME use */
  84. {0x0000, 0x00CD, 0x00D0}, /* raid shadow copy */
  85. {0x0000, 0x013A, 0x01FF}, /* sata shadow copy */
  86. {0x0000, 0x0175, 0x0176}, /* write once */
  87. {0x0000, 0x0195, 0x0197}, /* diagnostics */
  88. {0x0000, 0x01DC, 0x01DD}, /* manufacturing use */
  89. {0x0000, 0x027D, 0x0284}, /* diagnostics */
  90. {0x0000, 0x02E3, 0x02E3}, /* manufacturing use */
  91. {0x0000, 0x02FF, 0x02FF}, /* manufacturing use */
  92. {0x0000, 0x0300, 0x0302}, /* manufacturing use */
  93. {0x0000, 0x0325, 0x0326}, /* manufacturing use */
  94. {0x0000, 0x0332, 0x0335}, /* fan control */
  95. {0x0000, 0x0350, 0x0350}, /* manufacturing use */
  96. {0x0000, 0x0363, 0x0363}, /* manufacturing use */
  97. {0x0000, 0x0368, 0x0368}, /* manufacturing use */
  98. {0x0000, 0x03F6, 0x03F7}, /* manufacturing use */
  99. {0x0000, 0x049E, 0x049F}, /* manufacturing use */
  100. {0x0000, 0x04A0, 0x04A3}, /* disagnostics */
  101. {0x0000, 0x04E6, 0x04E7}, /* manufacturing use */
  102. {0x0000, 0x4000, 0x7FFF}, /* internal BIOS use */
  103. {0x0000, 0x9000, 0x9001}, /* internal BIOS use */
  104. {0x0000, 0xA000, 0xBFFF}, /* write only */
  105. {0x0000, 0xEFF0, 0xEFFF}, /* internal BIOS use */
  106. /* handled by kernel: dell-laptop */
  107. {0x0000, BRIGHTNESS_TOKEN, BRIGHTNESS_TOKEN},
  108. {0x0000, KBD_LED_OFF_TOKEN, KBD_LED_AUTO_TOKEN},
  109. {0x0000, KBD_LED_AC_TOKEN, KBD_LED_AC_TOKEN},
  110. {0x0000, KBD_LED_AUTO_25_TOKEN, KBD_LED_AUTO_75_TOKEN},
  111. {0x0000, KBD_LED_AUTO_100_TOKEN, KBD_LED_AUTO_100_TOKEN},
  112. {0x0000, GLOBAL_MIC_MUTE_ENABLE, GLOBAL_MIC_MUTE_DISABLE},
  113. };
  114. static LIST_HEAD(smbios_device_list);
  115. int dell_smbios_error(int value)
  116. {
  117. switch (value) {
  118. case 0: /* Completed successfully */
  119. return 0;
  120. case -1: /* Completed with error */
  121. return -EIO;
  122. case -2: /* Function not supported */
  123. return -ENXIO;
  124. default: /* Unknown error */
  125. return -EINVAL;
  126. }
  127. }
  128. EXPORT_SYMBOL_GPL(dell_smbios_error);
  129. int dell_smbios_register_device(struct device *d, void *call_fn)
  130. {
  131. struct smbios_device *priv;
  132. priv = devm_kzalloc(d, sizeof(struct smbios_device), GFP_KERNEL);
  133. if (!priv)
  134. return -ENOMEM;
  135. get_device(d);
  136. priv->device = d;
  137. priv->call_fn = call_fn;
  138. mutex_lock(&smbios_mutex);
  139. list_add_tail(&priv->list, &smbios_device_list);
  140. mutex_unlock(&smbios_mutex);
  141. dev_dbg(d, "Added device: %s\n", d->driver->name);
  142. return 0;
  143. }
  144. EXPORT_SYMBOL_GPL(dell_smbios_register_device);
  145. void dell_smbios_unregister_device(struct device *d)
  146. {
  147. struct smbios_device *priv;
  148. mutex_lock(&smbios_mutex);
  149. list_for_each_entry(priv, &smbios_device_list, list) {
  150. if (priv->device == d) {
  151. list_del(&priv->list);
  152. put_device(d);
  153. break;
  154. }
  155. }
  156. mutex_unlock(&smbios_mutex);
  157. dev_dbg(d, "Remove device: %s\n", d->driver->name);
  158. }
  159. EXPORT_SYMBOL_GPL(dell_smbios_unregister_device);
  160. int dell_smbios_call_filter(struct device *d,
  161. struct calling_interface_buffer *buffer)
  162. {
  163. u16 t = 0;
  164. int i;
  165. /* can't make calls over 30 */
  166. if (buffer->cmd_class > 30) {
  167. dev_dbg(d, "class too big: %u\n", buffer->cmd_class);
  168. return -EINVAL;
  169. }
  170. /* supported calls on the particular system */
  171. if (!(da_supported_commands & (1 << buffer->cmd_class))) {
  172. dev_dbg(d, "invalid command, supported commands: 0x%8x\n",
  173. da_supported_commands);
  174. return -EINVAL;
  175. }
  176. /* match against call blacklist */
  177. for (i = 0; i < ARRAY_SIZE(call_blacklist); i++) {
  178. if (buffer->cmd_class != call_blacklist[i].cmd_class)
  179. continue;
  180. if (buffer->cmd_select != call_blacklist[i].cmd_select &&
  181. call_blacklist[i].cmd_select != -1)
  182. continue;
  183. dev_dbg(d, "blacklisted command: %u/%u\n",
  184. buffer->cmd_class, buffer->cmd_select);
  185. return -EINVAL;
  186. }
  187. /* if a token call, find token ID */
  188. if ((buffer->cmd_class == CLASS_TOKEN_READ ||
  189. buffer->cmd_class == CLASS_TOKEN_WRITE) &&
  190. buffer->cmd_select < 3) {
  191. /* tokens enabled ? */
  192. if (!da_tokens) {
  193. dev_dbg(d, "no token support on this system\n");
  194. return -EINVAL;
  195. }
  196. /* find the matching token ID */
  197. for (i = 0; i < da_num_tokens; i++) {
  198. if (da_tokens[i].location != buffer->input[0])
  199. continue;
  200. t = da_tokens[i].tokenID;
  201. break;
  202. }
  203. /* token call; but token didn't exist */
  204. if (!t) {
  205. dev_dbg(d, "token at location %04x doesn't exist\n",
  206. buffer->input[0]);
  207. return -EINVAL;
  208. }
  209. /* match against token blacklist */
  210. for (i = 0; i < ARRAY_SIZE(token_blacklist); i++) {
  211. if (!token_blacklist[i].min || !token_blacklist[i].max)
  212. continue;
  213. if (t >= token_blacklist[i].min &&
  214. t <= token_blacklist[i].max)
  215. return -EINVAL;
  216. }
  217. /* match against token whitelist */
  218. for (i = 0; i < ARRAY_SIZE(token_whitelist); i++) {
  219. if (!token_whitelist[i].min || !token_whitelist[i].max)
  220. continue;
  221. if (t < token_whitelist[i].min ||
  222. t > token_whitelist[i].max)
  223. continue;
  224. if (!token_whitelist[i].need_capability ||
  225. capable(token_whitelist[i].need_capability)) {
  226. dev_dbg(d, "whitelisted token: %x\n", t);
  227. return 0;
  228. }
  229. }
  230. }
  231. /* match against call whitelist */
  232. for (i = 0; i < ARRAY_SIZE(call_whitelist); i++) {
  233. if (buffer->cmd_class != call_whitelist[i].cmd_class)
  234. continue;
  235. if (buffer->cmd_select != call_whitelist[i].cmd_select)
  236. continue;
  237. if (!call_whitelist[i].need_capability ||
  238. capable(call_whitelist[i].need_capability)) {
  239. dev_dbg(d, "whitelisted capable command: %u/%u\n",
  240. buffer->cmd_class, buffer->cmd_select);
  241. return 0;
  242. }
  243. dev_dbg(d, "missing capability %d for %u/%u\n",
  244. call_whitelist[i].need_capability,
  245. buffer->cmd_class, buffer->cmd_select);
  246. }
  247. /* not in a whitelist, only allow processes with capabilities */
  248. if (capable(CAP_SYS_RAWIO)) {
  249. dev_dbg(d, "Allowing %u/%u due to CAP_SYS_RAWIO\n",
  250. buffer->cmd_class, buffer->cmd_select);
  251. return 0;
  252. }
  253. return -EACCES;
  254. }
  255. EXPORT_SYMBOL_GPL(dell_smbios_call_filter);
  256. int dell_smbios_call(struct calling_interface_buffer *buffer)
  257. {
  258. int (*call_fn)(struct calling_interface_buffer *) = NULL;
  259. struct device *selected_dev = NULL;
  260. struct smbios_device *priv;
  261. int ret;
  262. mutex_lock(&smbios_mutex);
  263. list_for_each_entry(priv, &smbios_device_list, list) {
  264. if (!selected_dev || priv->device->id >= selected_dev->id) {
  265. dev_dbg(priv->device, "Trying device ID: %d\n",
  266. priv->device->id);
  267. call_fn = priv->call_fn;
  268. selected_dev = priv->device;
  269. }
  270. }
  271. if (!selected_dev) {
  272. ret = -ENODEV;
  273. pr_err("No dell-smbios drivers are loaded\n");
  274. goto out_smbios_call;
  275. }
  276. ret = call_fn(buffer);
  277. out_smbios_call:
  278. mutex_unlock(&smbios_mutex);
  279. return ret;
  280. }
  281. EXPORT_SYMBOL_GPL(dell_smbios_call);
  282. struct calling_interface_token *dell_smbios_find_token(int tokenid)
  283. {
  284. int i;
  285. if (!da_tokens)
  286. return NULL;
  287. for (i = 0; i < da_num_tokens; i++) {
  288. if (da_tokens[i].tokenID == tokenid)
  289. return &da_tokens[i];
  290. }
  291. return NULL;
  292. }
  293. EXPORT_SYMBOL_GPL(dell_smbios_find_token);
  294. static BLOCKING_NOTIFIER_HEAD(dell_laptop_chain_head);
  295. int dell_laptop_register_notifier(struct notifier_block *nb)
  296. {
  297. return blocking_notifier_chain_register(&dell_laptop_chain_head, nb);
  298. }
  299. EXPORT_SYMBOL_GPL(dell_laptop_register_notifier);
  300. int dell_laptop_unregister_notifier(struct notifier_block *nb)
  301. {
  302. return blocking_notifier_chain_unregister(&dell_laptop_chain_head, nb);
  303. }
  304. EXPORT_SYMBOL_GPL(dell_laptop_unregister_notifier);
  305. void dell_laptop_call_notifier(unsigned long action, void *data)
  306. {
  307. blocking_notifier_call_chain(&dell_laptop_chain_head, action, data);
  308. }
  309. EXPORT_SYMBOL_GPL(dell_laptop_call_notifier);
  310. static void __init parse_da_table(const struct dmi_header *dm)
  311. {
  312. /* Final token is a terminator, so we don't want to copy it */
  313. int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
  314. struct calling_interface_token *new_da_tokens;
  315. struct calling_interface_structure *table =
  316. container_of(dm, struct calling_interface_structure, header);
  317. /*
  318. * 4 bytes of table header, plus 7 bytes of Dell header
  319. * plus at least 6 bytes of entry
  320. */
  321. if (dm->length < 17)
  322. return;
  323. da_supported_commands = table->supportedCmds;
  324. new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
  325. sizeof(struct calling_interface_token),
  326. GFP_KERNEL);
  327. if (!new_da_tokens)
  328. return;
  329. da_tokens = new_da_tokens;
  330. memcpy(da_tokens+da_num_tokens, table->tokens,
  331. sizeof(struct calling_interface_token) * tokens);
  332. da_num_tokens += tokens;
  333. }
  334. static void zero_duplicates(struct device *dev)
  335. {
  336. int i, j;
  337. for (i = 0; i < da_num_tokens; i++) {
  338. if (da_tokens[i].tokenID == 0)
  339. continue;
  340. for (j = i+1; j < da_num_tokens; j++) {
  341. if (da_tokens[j].tokenID == 0)
  342. continue;
  343. if (da_tokens[i].tokenID == da_tokens[j].tokenID) {
  344. dev_dbg(dev, "Zeroing dup token ID %x(%x/%x)\n",
  345. da_tokens[j].tokenID,
  346. da_tokens[j].location,
  347. da_tokens[j].value);
  348. da_tokens[j].tokenID = 0;
  349. }
  350. }
  351. }
  352. }
  353. static void __init find_tokens(const struct dmi_header *dm, void *dummy)
  354. {
  355. switch (dm->type) {
  356. case 0xd4: /* Indexed IO */
  357. case 0xd5: /* Protected Area Type 1 */
  358. case 0xd6: /* Protected Area Type 2 */
  359. break;
  360. case 0xda: /* Calling interface */
  361. parse_da_table(dm);
  362. break;
  363. }
  364. }
  365. static int match_attribute(struct device *dev,
  366. struct device_attribute *attr)
  367. {
  368. int i;
  369. for (i = 0; i < da_num_tokens * 2; i++) {
  370. if (!token_attrs[i])
  371. continue;
  372. if (strcmp(token_attrs[i]->name, attr->attr.name) == 0)
  373. return i/2;
  374. }
  375. dev_dbg(dev, "couldn't match: %s\n", attr->attr.name);
  376. return -EINVAL;
  377. }
  378. static ssize_t location_show(struct device *dev,
  379. struct device_attribute *attr, char *buf)
  380. {
  381. int i;
  382. if (!capable(CAP_SYS_ADMIN))
  383. return -EPERM;
  384. i = match_attribute(dev, attr);
  385. if (i > 0)
  386. return scnprintf(buf, PAGE_SIZE, "%08x", da_tokens[i].location);
  387. return 0;
  388. }
  389. static ssize_t value_show(struct device *dev,
  390. struct device_attribute *attr, char *buf)
  391. {
  392. int i;
  393. if (!capable(CAP_SYS_ADMIN))
  394. return -EPERM;
  395. i = match_attribute(dev, attr);
  396. if (i > 0)
  397. return scnprintf(buf, PAGE_SIZE, "%08x", da_tokens[i].value);
  398. return 0;
  399. }
  400. static struct attribute_group smbios_attribute_group = {
  401. .name = "tokens"
  402. };
  403. static struct platform_driver platform_driver = {
  404. .driver = {
  405. .name = "dell-smbios",
  406. },
  407. };
  408. static int build_tokens_sysfs(struct platform_device *dev)
  409. {
  410. char *location_name;
  411. char *value_name;
  412. size_t size;
  413. int ret;
  414. int i, j;
  415. /* (number of tokens + 1 for null terminated */
  416. size = sizeof(struct device_attribute) * (da_num_tokens + 1);
  417. token_location_attrs = kzalloc(size, GFP_KERNEL);
  418. if (!token_location_attrs)
  419. return -ENOMEM;
  420. token_value_attrs = kzalloc(size, GFP_KERNEL);
  421. if (!token_value_attrs)
  422. goto out_allocate_value;
  423. /* need to store both location and value + terminator*/
  424. size = sizeof(struct attribute *) * ((2 * da_num_tokens) + 1);
  425. token_attrs = kzalloc(size, GFP_KERNEL);
  426. if (!token_attrs)
  427. goto out_allocate_attrs;
  428. for (i = 0, j = 0; i < da_num_tokens; i++) {
  429. /* skip empty */
  430. if (da_tokens[i].tokenID == 0)
  431. continue;
  432. /* add location */
  433. location_name = kasprintf(GFP_KERNEL, "%04x_location",
  434. da_tokens[i].tokenID);
  435. if (location_name == NULL)
  436. goto out_unwind_strings;
  437. sysfs_attr_init(&token_location_attrs[i].attr);
  438. token_location_attrs[i].attr.name = location_name;
  439. token_location_attrs[i].attr.mode = 0444;
  440. token_location_attrs[i].show = location_show;
  441. token_attrs[j++] = &token_location_attrs[i].attr;
  442. /* add value */
  443. value_name = kasprintf(GFP_KERNEL, "%04x_value",
  444. da_tokens[i].tokenID);
  445. if (value_name == NULL)
  446. goto loop_fail_create_value;
  447. sysfs_attr_init(&token_value_attrs[i].attr);
  448. token_value_attrs[i].attr.name = value_name;
  449. token_value_attrs[i].attr.mode = 0444;
  450. token_value_attrs[i].show = value_show;
  451. token_attrs[j++] = &token_value_attrs[i].attr;
  452. continue;
  453. loop_fail_create_value:
  454. kfree(location_name);
  455. goto out_unwind_strings;
  456. }
  457. smbios_attribute_group.attrs = token_attrs;
  458. ret = sysfs_create_group(&dev->dev.kobj, &smbios_attribute_group);
  459. if (ret)
  460. goto out_unwind_strings;
  461. return 0;
  462. out_unwind_strings:
  463. while (i--) {
  464. kfree(token_location_attrs[i].attr.name);
  465. kfree(token_value_attrs[i].attr.name);
  466. }
  467. kfree(token_attrs);
  468. out_allocate_attrs:
  469. kfree(token_value_attrs);
  470. out_allocate_value:
  471. kfree(token_location_attrs);
  472. return -ENOMEM;
  473. }
  474. static void free_group(struct platform_device *pdev)
  475. {
  476. int i;
  477. sysfs_remove_group(&pdev->dev.kobj,
  478. &smbios_attribute_group);
  479. for (i = 0; i < da_num_tokens; i++) {
  480. kfree(token_location_attrs[i].attr.name);
  481. kfree(token_value_attrs[i].attr.name);
  482. }
  483. kfree(token_attrs);
  484. kfree(token_value_attrs);
  485. kfree(token_location_attrs);
  486. }
  487. static int __init dell_smbios_init(void)
  488. {
  489. int ret, wmi, smm;
  490. if (!dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "Dell System", NULL) &&
  491. !dmi_find_device(DMI_DEV_TYPE_OEM_STRING, "www.dell.com", NULL)) {
  492. pr_err("Unable to run on non-Dell system\n");
  493. return -ENODEV;
  494. }
  495. dmi_walk(find_tokens, NULL);
  496. ret = platform_driver_register(&platform_driver);
  497. if (ret)
  498. goto fail_platform_driver;
  499. platform_device = platform_device_alloc("dell-smbios", 0);
  500. if (!platform_device) {
  501. ret = -ENOMEM;
  502. goto fail_platform_device_alloc;
  503. }
  504. ret = platform_device_add(platform_device);
  505. if (ret)
  506. goto fail_platform_device_add;
  507. /* register backends */
  508. wmi = init_dell_smbios_wmi();
  509. if (wmi)
  510. pr_debug("Failed to initialize WMI backend: %d\n", wmi);
  511. smm = init_dell_smbios_smm();
  512. if (smm)
  513. pr_debug("Failed to initialize SMM backend: %d\n", smm);
  514. if (wmi && smm) {
  515. pr_err("No SMBIOS backends available (wmi: %d, smm: %d)\n",
  516. wmi, smm);
  517. ret = -ENODEV;
  518. goto fail_create_group;
  519. }
  520. if (da_tokens) {
  521. /* duplicate tokens will cause problems building sysfs files */
  522. zero_duplicates(&platform_device->dev);
  523. ret = build_tokens_sysfs(platform_device);
  524. if (ret)
  525. goto fail_sysfs;
  526. }
  527. return 0;
  528. fail_sysfs:
  529. free_group(platform_device);
  530. fail_create_group:
  531. platform_device_del(platform_device);
  532. fail_platform_device_add:
  533. platform_device_put(platform_device);
  534. fail_platform_device_alloc:
  535. platform_driver_unregister(&platform_driver);
  536. fail_platform_driver:
  537. kfree(da_tokens);
  538. return ret;
  539. }
  540. static void __exit dell_smbios_exit(void)
  541. {
  542. exit_dell_smbios_wmi();
  543. exit_dell_smbios_smm();
  544. mutex_lock(&smbios_mutex);
  545. if (platform_device) {
  546. if (da_tokens)
  547. free_group(platform_device);
  548. platform_device_unregister(platform_device);
  549. platform_driver_unregister(&platform_driver);
  550. }
  551. kfree(da_tokens);
  552. mutex_unlock(&smbios_mutex);
  553. }
  554. module_init(dell_smbios_init);
  555. module_exit(dell_smbios_exit);
  556. MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
  557. MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
  558. MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
  559. MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
  560. MODULE_DESCRIPTION("Common functions for kernel modules using Dell SMBIOS");
  561. MODULE_LICENSE("GPL");