dmi-sysfs.c 17 KB

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