dmi-sysfs.c 17 KB

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