dell-smbios.c 17 KB

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