dmi-sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * dmi-sysfs.c
  3. *
  4. * This module exports the DMI tables read-only to userspace through the
  5. * sysfs file system.
  6. *
  7. * Data is currently found below
  8. * /sys/firmware/dmi/...
  9. *
  10. * DMI attributes are presented in attribute files with names
  11. * formatted using %d-%d, so that the first integer indicates the
  12. * structure type (0-255), and the second field is the instance of that
  13. * entry.
  14. *
  15. * Copyright 2011 Google, Inc.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/types.h>
  21. #include <linux/kobject.h>
  22. #include <linux/dmi.h>
  23. #include <linux/capability.h>
  24. #include <linux/slab.h>
  25. #include <linux/list.h>
  26. #include <linux/io.h>
  27. #define MAX_ENTRY_TYPE 255 /* Most of these aren't used, but we consider
  28. the top entry type is only 8 bits */
  29. struct dmi_sysfs_entry {
  30. struct dmi_header dh;
  31. struct kobject kobj;
  32. int instance;
  33. int position;
  34. struct list_head list;
  35. struct kobject *child;
  36. };
  37. /*
  38. * Global list of dmi_sysfs_entry. Even though this should only be
  39. * manipulated at setup and teardown, the lazy nature of the kobject
  40. * system means we get lazy removes.
  41. */
  42. static LIST_HEAD(entry_list);
  43. static DEFINE_SPINLOCK(entry_list_lock);
  44. /* dmi_sysfs_attribute - Top level attribute. used by all entries. */
  45. struct dmi_sysfs_attribute {
  46. struct attribute attr;
  47. ssize_t (*show)(struct dmi_sysfs_entry *entry, char *buf);
  48. };
  49. #define DMI_SYSFS_ATTR(_entry, _name) \
  50. struct dmi_sysfs_attribute dmi_sysfs_attr_##_entry##_##_name = { \
  51. .attr = {.name = __stringify(_name), .mode = 0400}, \
  52. .show = dmi_sysfs_##_entry##_##_name, \
  53. }
  54. /*
  55. * dmi_sysfs_mapped_attribute - Attribute where we require the entry be
  56. * mapped in. Use in conjunction with dmi_sysfs_specialize_attr_ops.
  57. */
  58. struct dmi_sysfs_mapped_attribute {
  59. struct attribute attr;
  60. ssize_t (*show)(struct dmi_sysfs_entry *entry,
  61. const struct dmi_header *dh,
  62. char *buf);
  63. };
  64. #define DMI_SYSFS_MAPPED_ATTR(_entry, _name) \
  65. struct dmi_sysfs_mapped_attribute dmi_sysfs_attr_##_entry##_##_name = { \
  66. .attr = {.name = __stringify(_name), .mode = 0400}, \
  67. .show = dmi_sysfs_##_entry##_##_name, \
  68. }
  69. /*************************************************
  70. * Generic DMI entry support.
  71. *************************************************/
  72. static void dmi_entry_free(struct kobject *kobj)
  73. {
  74. kfree(kobj);
  75. }
  76. static struct dmi_sysfs_entry *to_entry(struct kobject *kobj)
  77. {
  78. return container_of(kobj, struct dmi_sysfs_entry, kobj);
  79. }
  80. static struct dmi_sysfs_attribute *to_attr(struct attribute *attr)
  81. {
  82. return container_of(attr, struct dmi_sysfs_attribute, attr);
  83. }
  84. static ssize_t dmi_sysfs_attr_show(struct kobject *kobj,
  85. struct attribute *_attr, char *buf)
  86. {
  87. struct dmi_sysfs_entry *entry = to_entry(kobj);
  88. struct dmi_sysfs_attribute *attr = to_attr(_attr);
  89. /* DMI stuff is only ever admin visible */
  90. if (!capable(CAP_SYS_ADMIN))
  91. return -EACCES;
  92. return attr->show(entry, buf);
  93. }
  94. static const struct sysfs_ops dmi_sysfs_attr_ops = {
  95. .show = dmi_sysfs_attr_show,
  96. };
  97. typedef ssize_t (*dmi_callback)(struct dmi_sysfs_entry *,
  98. const struct dmi_header *dh, void *);
  99. struct find_dmi_data {
  100. struct dmi_sysfs_entry *entry;
  101. dmi_callback callback;
  102. void *private;
  103. int instance_countdown;
  104. ssize_t ret;
  105. };
  106. static void find_dmi_entry_helper(const struct dmi_header *dh,
  107. void *_data)
  108. {
  109. struct find_dmi_data *data = _data;
  110. struct dmi_sysfs_entry *entry = data->entry;
  111. /* Is this the entry we want? */
  112. if (dh->type != entry->dh.type)
  113. return;
  114. if (data->instance_countdown != 0) {
  115. /* try the next instance? */
  116. data->instance_countdown--;
  117. return;
  118. }
  119. /*
  120. * Don't ever revisit the instance. Short circuit later
  121. * instances by letting the instance_countdown run negative
  122. */
  123. data->instance_countdown--;
  124. /* Found the entry */
  125. data->ret = data->callback(entry, dh, data->private);
  126. }
  127. /* State for passing the read parameters through dmi_find_entry() */
  128. struct dmi_read_state {
  129. char *buf;
  130. loff_t pos;
  131. size_t count;
  132. };
  133. static ssize_t find_dmi_entry(struct dmi_sysfs_entry *entry,
  134. dmi_callback callback, void *private)
  135. {
  136. struct find_dmi_data data = {
  137. .entry = entry,
  138. .callback = callback,
  139. .private = private,
  140. .instance_countdown = entry->instance,
  141. .ret = -EIO, /* To signal the entry disappeared */
  142. };
  143. int ret;
  144. ret = dmi_walk(find_dmi_entry_helper, &data);
  145. /* This shouldn't happen, but just in case. */
  146. if (ret)
  147. return -EINVAL;
  148. return data.ret;
  149. }
  150. /*
  151. * Calculate and return the byte length of the dmi entry identified by
  152. * dh. This includes both the formatted portion as well as the
  153. * unformatted string space, including the two trailing nul characters.
  154. */
  155. static size_t dmi_entry_length(const struct dmi_header *dh)
  156. {
  157. const char *p = (const char *)dh;
  158. p += dh->length;
  159. while (p[0] || p[1])
  160. p++;
  161. return 2 + p - (const char *)dh;
  162. }
  163. /*************************************************
  164. * Support bits for specialized DMI entry support
  165. *************************************************/
  166. struct dmi_entry_attr_show_data {
  167. struct attribute *attr;
  168. char *buf;
  169. };
  170. static ssize_t dmi_entry_attr_show_helper(struct dmi_sysfs_entry *entry,
  171. const struct dmi_header *dh,
  172. void *_data)
  173. {
  174. struct dmi_entry_attr_show_data *data = _data;
  175. struct dmi_sysfs_mapped_attribute *attr;
  176. attr = container_of(data->attr,
  177. struct dmi_sysfs_mapped_attribute, attr);
  178. return attr->show(entry, dh, data->buf);
  179. }
  180. static ssize_t dmi_entry_attr_show(struct kobject *kobj,
  181. struct attribute *attr,
  182. char *buf)
  183. {
  184. struct dmi_entry_attr_show_data data = {
  185. .attr = attr,
  186. .buf = buf,
  187. };
  188. /* Find the entry according to our parent and call the
  189. * normalized show method hanging off of the attribute */
  190. return find_dmi_entry(to_entry(kobj->parent),
  191. dmi_entry_attr_show_helper, &data);
  192. }
  193. static const struct sysfs_ops dmi_sysfs_specialize_attr_ops = {
  194. .show = dmi_entry_attr_show,
  195. };
  196. /*************************************************
  197. * Specialized DMI entry support.
  198. *************************************************/
  199. /*** Type 15 - System Event Table ***/
  200. #define DMI_SEL_ACCESS_METHOD_IO8 0x00
  201. #define DMI_SEL_ACCESS_METHOD_IO2x8 0x01
  202. #define DMI_SEL_ACCESS_METHOD_IO16 0x02
  203. #define DMI_SEL_ACCESS_METHOD_PHYS32 0x03
  204. #define DMI_SEL_ACCESS_METHOD_GPNV 0x04
  205. struct dmi_system_event_log {
  206. struct dmi_header header;
  207. u16 area_length;
  208. u16 header_start_offset;
  209. u16 data_start_offset;
  210. u8 access_method;
  211. u8 status;
  212. u32 change_token;
  213. union {
  214. struct {
  215. u16 index_addr;
  216. u16 data_addr;
  217. } io;
  218. u32 phys_addr32;
  219. u16 gpnv_handle;
  220. u32 access_method_address;
  221. };
  222. u8 header_format;
  223. u8 type_descriptors_supported_count;
  224. u8 per_log_type_descriptor_length;
  225. u8 supported_log_type_descriptos[0];
  226. } __packed;
  227. #define DMI_SYSFS_SEL_FIELD(_field) \
  228. static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \
  229. const struct dmi_header *dh, \
  230. char *buf) \
  231. { \
  232. struct dmi_system_event_log sel; \
  233. if (sizeof(sel) > dmi_entry_length(dh)) \
  234. return -EIO; \
  235. memcpy(&sel, dh, sizeof(sel)); \
  236. return sprintf(buf, "%u\n", sel._field); \
  237. } \
  238. static DMI_SYSFS_MAPPED_ATTR(sel, _field)
  239. DMI_SYSFS_SEL_FIELD(area_length);
  240. DMI_SYSFS_SEL_FIELD(header_start_offset);
  241. DMI_SYSFS_SEL_FIELD(data_start_offset);
  242. DMI_SYSFS_SEL_FIELD(access_method);
  243. DMI_SYSFS_SEL_FIELD(status);
  244. DMI_SYSFS_SEL_FIELD(change_token);
  245. DMI_SYSFS_SEL_FIELD(access_method_address);
  246. DMI_SYSFS_SEL_FIELD(header_format);
  247. DMI_SYSFS_SEL_FIELD(type_descriptors_supported_count);
  248. DMI_SYSFS_SEL_FIELD(per_log_type_descriptor_length);
  249. static struct attribute *dmi_sysfs_sel_attrs[] = {
  250. &dmi_sysfs_attr_sel_area_length.attr,
  251. &dmi_sysfs_attr_sel_header_start_offset.attr,
  252. &dmi_sysfs_attr_sel_data_start_offset.attr,
  253. &dmi_sysfs_attr_sel_access_method.attr,
  254. &dmi_sysfs_attr_sel_status.attr,
  255. &dmi_sysfs_attr_sel_change_token.attr,
  256. &dmi_sysfs_attr_sel_access_method_address.attr,
  257. &dmi_sysfs_attr_sel_header_format.attr,
  258. &dmi_sysfs_attr_sel_type_descriptors_supported_count.attr,
  259. &dmi_sysfs_attr_sel_per_log_type_descriptor_length.attr,
  260. NULL,
  261. };
  262. static struct kobj_type dmi_system_event_log_ktype = {
  263. .release = dmi_entry_free,
  264. .sysfs_ops = &dmi_sysfs_specialize_attr_ops,
  265. .default_attrs = dmi_sysfs_sel_attrs,
  266. };
  267. typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel,
  268. loff_t offset);
  269. static DEFINE_MUTEX(io_port_lock);
  270. static u8 read_sel_8bit_indexed_io(const struct dmi_system_event_log *sel,
  271. loff_t offset)
  272. {
  273. u8 ret;
  274. mutex_lock(&io_port_lock);
  275. outb((u8)offset, sel->io.index_addr);
  276. ret = inb(sel->io.data_addr);
  277. mutex_unlock(&io_port_lock);
  278. return ret;
  279. }
  280. static u8 read_sel_2x8bit_indexed_io(const struct dmi_system_event_log *sel,
  281. loff_t offset)
  282. {
  283. u8 ret;
  284. mutex_lock(&io_port_lock);
  285. outb((u8)offset, sel->io.index_addr);
  286. outb((u8)(offset >> 8), sel->io.index_addr + 1);
  287. ret = inb(sel->io.data_addr);
  288. mutex_unlock(&io_port_lock);
  289. return ret;
  290. }
  291. static u8 read_sel_16bit_indexed_io(const struct dmi_system_event_log *sel,
  292. loff_t offset)
  293. {
  294. u8 ret;
  295. mutex_lock(&io_port_lock);
  296. outw((u16)offset, sel->io.index_addr);
  297. ret = inb(sel->io.data_addr);
  298. mutex_unlock(&io_port_lock);
  299. return ret;
  300. }
  301. static sel_io_reader sel_io_readers[] = {
  302. [DMI_SEL_ACCESS_METHOD_IO8] = read_sel_8bit_indexed_io,
  303. [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io,
  304. [DMI_SEL_ACCESS_METHOD_IO16] = read_sel_16bit_indexed_io,
  305. };
  306. static ssize_t dmi_sel_raw_read_io(struct dmi_sysfs_entry *entry,
  307. const struct dmi_system_event_log *sel,
  308. char *buf, loff_t pos, size_t count)
  309. {
  310. ssize_t wrote = 0;
  311. sel_io_reader io_reader = sel_io_readers[sel->access_method];
  312. while (count && pos < sel->area_length) {
  313. count--;
  314. *(buf++) = io_reader(sel, pos++);
  315. wrote++;
  316. }
  317. return wrote;
  318. }
  319. static ssize_t dmi_sel_raw_read_phys32(struct dmi_sysfs_entry *entry,
  320. const struct dmi_system_event_log *sel,
  321. char *buf, loff_t pos, size_t count)
  322. {
  323. u8 __iomem *mapped;
  324. ssize_t wrote = 0;
  325. mapped = ioremap(sel->access_method_address, sel->area_length);
  326. if (!mapped)
  327. return -EIO;
  328. while (count && pos < sel->area_length) {
  329. count--;
  330. *(buf++) = readb(mapped + pos++);
  331. wrote++;
  332. }
  333. iounmap(mapped);
  334. return wrote;
  335. }
  336. static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry,
  337. const struct dmi_header *dh,
  338. void *_state)
  339. {
  340. struct dmi_read_state *state = _state;
  341. struct dmi_system_event_log sel;
  342. if (sizeof(sel) > dmi_entry_length(dh))
  343. return -EIO;
  344. memcpy(&sel, dh, sizeof(sel));
  345. switch (sel.access_method) {
  346. case DMI_SEL_ACCESS_METHOD_IO8:
  347. case DMI_SEL_ACCESS_METHOD_IO2x8:
  348. case DMI_SEL_ACCESS_METHOD_IO16:
  349. return dmi_sel_raw_read_io(entry, &sel, state->buf,
  350. state->pos, state->count);
  351. case DMI_SEL_ACCESS_METHOD_PHYS32:
  352. return dmi_sel_raw_read_phys32(entry, &sel, state->buf,
  353. state->pos, state->count);
  354. case DMI_SEL_ACCESS_METHOD_GPNV:
  355. pr_info("dmi-sysfs: GPNV support missing.\n");
  356. return -EIO;
  357. default:
  358. pr_info("dmi-sysfs: Unknown access method %02x\n",
  359. sel.access_method);
  360. return -EIO;
  361. }
  362. }
  363. static ssize_t dmi_sel_raw_read(struct file *filp, struct kobject *kobj,
  364. struct bin_attribute *bin_attr,
  365. char *buf, loff_t pos, size_t count)
  366. {
  367. struct dmi_sysfs_entry *entry = to_entry(kobj->parent);
  368. struct dmi_read_state state = {
  369. .buf = buf,
  370. .pos = pos,
  371. .count = count,
  372. };
  373. return find_dmi_entry(entry, dmi_sel_raw_read_helper, &state);
  374. }
  375. static struct bin_attribute dmi_sel_raw_attr = {
  376. .attr = {.name = "raw_event_log", .mode = 0400},
  377. .read = dmi_sel_raw_read,
  378. };
  379. static int dmi_system_event_log(struct dmi_sysfs_entry *entry)
  380. {
  381. int ret;
  382. entry->child = kzalloc(sizeof(*entry->child), GFP_KERNEL);
  383. if (!entry->child)
  384. return -ENOMEM;
  385. ret = kobject_init_and_add(entry->child,
  386. &dmi_system_event_log_ktype,
  387. &entry->kobj,
  388. "system_event_log");
  389. if (ret)
  390. goto out_free;
  391. ret = sysfs_create_bin_file(entry->child, &dmi_sel_raw_attr);
  392. if (ret)
  393. goto out_del;
  394. return 0;
  395. out_del:
  396. kobject_del(entry->child);
  397. out_free:
  398. kfree(entry->child);
  399. return ret;
  400. }
  401. /*************************************************
  402. * Generic DMI entry support.
  403. *************************************************/
  404. static ssize_t dmi_sysfs_entry_length(struct dmi_sysfs_entry *entry, char *buf)
  405. {
  406. return sprintf(buf, "%d\n", entry->dh.length);
  407. }
  408. static ssize_t dmi_sysfs_entry_handle(struct dmi_sysfs_entry *entry, char *buf)
  409. {
  410. return sprintf(buf, "%d\n", entry->dh.handle);
  411. }
  412. static ssize_t dmi_sysfs_entry_type(struct dmi_sysfs_entry *entry, char *buf)
  413. {
  414. return sprintf(buf, "%d\n", entry->dh.type);
  415. }
  416. static ssize_t dmi_sysfs_entry_instance(struct dmi_sysfs_entry *entry,
  417. char *buf)
  418. {
  419. return sprintf(buf, "%d\n", entry->instance);
  420. }
  421. static ssize_t dmi_sysfs_entry_position(struct dmi_sysfs_entry *entry,
  422. char *buf)
  423. {
  424. return sprintf(buf, "%d\n", entry->position);
  425. }
  426. static DMI_SYSFS_ATTR(entry, length);
  427. static DMI_SYSFS_ATTR(entry, handle);
  428. static DMI_SYSFS_ATTR(entry, type);
  429. static DMI_SYSFS_ATTR(entry, instance);
  430. static DMI_SYSFS_ATTR(entry, position);
  431. static struct attribute *dmi_sysfs_entry_attrs[] = {
  432. &dmi_sysfs_attr_entry_length.attr,
  433. &dmi_sysfs_attr_entry_handle.attr,
  434. &dmi_sysfs_attr_entry_type.attr,
  435. &dmi_sysfs_attr_entry_instance.attr,
  436. &dmi_sysfs_attr_entry_position.attr,
  437. NULL,
  438. };
  439. static ssize_t dmi_entry_raw_read_helper(struct dmi_sysfs_entry *entry,
  440. const struct dmi_header *dh,
  441. void *_state)
  442. {
  443. struct dmi_read_state *state = _state;
  444. size_t entry_length;
  445. entry_length = dmi_entry_length(dh);
  446. return memory_read_from_buffer(state->buf, state->count,
  447. &state->pos, dh, entry_length);
  448. }
  449. static ssize_t dmi_entry_raw_read(struct file *filp,
  450. struct kobject *kobj,
  451. struct bin_attribute *bin_attr,
  452. char *buf, loff_t pos, size_t count)
  453. {
  454. struct dmi_sysfs_entry *entry = to_entry(kobj);
  455. struct dmi_read_state state = {
  456. .buf = buf,
  457. .pos = pos,
  458. .count = count,
  459. };
  460. return find_dmi_entry(entry, dmi_entry_raw_read_helper, &state);
  461. }
  462. static const struct bin_attribute dmi_entry_raw_attr = {
  463. .attr = {.name = "raw", .mode = 0400},
  464. .read = dmi_entry_raw_read,
  465. };
  466. static void dmi_sysfs_entry_release(struct kobject *kobj)
  467. {
  468. struct dmi_sysfs_entry *entry = to_entry(kobj);
  469. spin_lock(&entry_list_lock);
  470. list_del(&entry->list);
  471. spin_unlock(&entry_list_lock);
  472. kfree(entry);
  473. }
  474. static struct kobj_type dmi_sysfs_entry_ktype = {
  475. .release = dmi_sysfs_entry_release,
  476. .sysfs_ops = &dmi_sysfs_attr_ops,
  477. .default_attrs = dmi_sysfs_entry_attrs,
  478. };
  479. static struct kset *dmi_kset;
  480. /* Global count of all instances seen. Only for setup */
  481. static int __initdata instance_counts[MAX_ENTRY_TYPE + 1];
  482. /* Global positional count of all entries seen. Only for setup */
  483. static int __initdata position_count;
  484. static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
  485. void *_ret)
  486. {
  487. struct dmi_sysfs_entry *entry;
  488. int *ret = _ret;
  489. /* If a previous entry saw an error, short circuit */
  490. if (*ret)
  491. return;
  492. /* Allocate and register a new entry into the entries set */
  493. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  494. if (!entry) {
  495. *ret = -ENOMEM;
  496. return;
  497. }
  498. /* Set the key */
  499. memcpy(&entry->dh, dh, sizeof(*dh));
  500. entry->instance = instance_counts[dh->type]++;
  501. entry->position = position_count++;
  502. entry->kobj.kset = dmi_kset;
  503. *ret = kobject_init_and_add(&entry->kobj, &dmi_sysfs_entry_ktype, NULL,
  504. "%d-%d", dh->type, entry->instance);
  505. if (*ret) {
  506. kfree(entry);
  507. return;
  508. }
  509. /* Thread on the global list for cleanup */
  510. spin_lock(&entry_list_lock);
  511. list_add_tail(&entry->list, &entry_list);
  512. spin_unlock(&entry_list_lock);
  513. /* Handle specializations by type */
  514. switch (dh->type) {
  515. case DMI_ENTRY_SYSTEM_EVENT_LOG:
  516. *ret = dmi_system_event_log(entry);
  517. break;
  518. default:
  519. /* No specialization */
  520. break;
  521. }
  522. if (*ret)
  523. goto out_err;
  524. /* Create the raw binary file to access the entry */
  525. *ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr);
  526. if (*ret)
  527. goto out_err;
  528. return;
  529. out_err:
  530. kobject_put(entry->child);
  531. kobject_put(&entry->kobj);
  532. return;
  533. }
  534. static void cleanup_entry_list(void)
  535. {
  536. struct dmi_sysfs_entry *entry, *next;
  537. /* No locks, we are on our way out */
  538. list_for_each_entry_safe(entry, next, &entry_list, list) {
  539. kobject_put(entry->child);
  540. kobject_put(&entry->kobj);
  541. }
  542. }
  543. static int __init dmi_sysfs_init(void)
  544. {
  545. int error;
  546. int val;
  547. if (!dmi_kobj) {
  548. pr_err("dmi-sysfs: dmi entry is absent.\n");
  549. error = -ENODATA;
  550. goto err;
  551. }
  552. dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj);
  553. if (!dmi_kset) {
  554. error = -ENOMEM;
  555. goto err;
  556. }
  557. val = 0;
  558. error = dmi_walk(dmi_sysfs_register_handle, &val);
  559. if (error)
  560. goto err;
  561. if (val) {
  562. error = val;
  563. goto err;
  564. }
  565. pr_debug("dmi-sysfs: loaded.\n");
  566. return 0;
  567. err:
  568. cleanup_entry_list();
  569. kset_unregister(dmi_kset);
  570. return error;
  571. }
  572. /* clean up everything. */
  573. static void __exit dmi_sysfs_exit(void)
  574. {
  575. pr_debug("dmi-sysfs: unloading.\n");
  576. cleanup_entry_list();
  577. kset_unregister(dmi_kset);
  578. }
  579. module_init(dmi_sysfs_init);
  580. module_exit(dmi_sysfs_exit);
  581. MODULE_AUTHOR("Mike Waychison <mikew@google.com>");
  582. MODULE_DESCRIPTION("DMI sysfs support");
  583. MODULE_LICENSE("GPL");