dmi-sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. ATTRIBUTE_GROUPS(dmi_sysfs_sel);
  265. static const struct kobj_type dmi_system_event_log_ktype = {
  266. .release = dmi_entry_free,
  267. .sysfs_ops = &dmi_sysfs_specialize_attr_ops,
  268. .default_groups = dmi_sysfs_sel_groups,
  269. };
  270. #ifdef CONFIG_HAS_IOPORT
  271. typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel,
  272. loff_t offset);
  273. static DEFINE_MUTEX(io_port_lock);
  274. static u8 read_sel_8bit_indexed_io(const struct dmi_system_event_log *sel,
  275. loff_t offset)
  276. {
  277. u8 ret;
  278. mutex_lock(&io_port_lock);
  279. outb((u8)offset, sel->io.index_addr);
  280. ret = inb(sel->io.data_addr);
  281. mutex_unlock(&io_port_lock);
  282. return ret;
  283. }
  284. static u8 read_sel_2x8bit_indexed_io(const struct dmi_system_event_log *sel,
  285. loff_t offset)
  286. {
  287. u8 ret;
  288. mutex_lock(&io_port_lock);
  289. outb((u8)offset, sel->io.index_addr);
  290. outb((u8)(offset >> 8), sel->io.index_addr + 1);
  291. ret = inb(sel->io.data_addr);
  292. mutex_unlock(&io_port_lock);
  293. return ret;
  294. }
  295. static u8 read_sel_16bit_indexed_io(const struct dmi_system_event_log *sel,
  296. loff_t offset)
  297. {
  298. u8 ret;
  299. mutex_lock(&io_port_lock);
  300. outw((u16)offset, sel->io.index_addr);
  301. ret = inb(sel->io.data_addr);
  302. mutex_unlock(&io_port_lock);
  303. return ret;
  304. }
  305. static sel_io_reader sel_io_readers[] = {
  306. [DMI_SEL_ACCESS_METHOD_IO8] = read_sel_8bit_indexed_io,
  307. [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io,
  308. [DMI_SEL_ACCESS_METHOD_IO16] = read_sel_16bit_indexed_io,
  309. };
  310. static ssize_t dmi_sel_raw_read_io(struct dmi_sysfs_entry *entry,
  311. const struct dmi_system_event_log *sel,
  312. char *buf, loff_t pos, size_t count)
  313. {
  314. ssize_t wrote = 0;
  315. sel_io_reader io_reader = sel_io_readers[sel->access_method];
  316. while (count && pos < sel->area_length) {
  317. count--;
  318. *(buf++) = io_reader(sel, pos++);
  319. wrote++;
  320. }
  321. return wrote;
  322. }
  323. #endif
  324. static ssize_t dmi_sel_raw_read_phys32(struct dmi_sysfs_entry *entry,
  325. const struct dmi_system_event_log *sel,
  326. char *buf, loff_t pos, size_t count)
  327. {
  328. u8 __iomem *mapped;
  329. ssize_t wrote = 0;
  330. mapped = dmi_remap(sel->access_method_address, sel->area_length);
  331. if (!mapped)
  332. return -EIO;
  333. while (count && pos < sel->area_length) {
  334. count--;
  335. *(buf++) = readb(mapped + pos++);
  336. wrote++;
  337. }
  338. dmi_unmap(mapped);
  339. return wrote;
  340. }
  341. static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry,
  342. const struct dmi_header *dh,
  343. void *_state)
  344. {
  345. struct dmi_read_state *state = _state;
  346. struct dmi_system_event_log sel;
  347. if (sizeof(sel) > dmi_entry_length(dh))
  348. return -EIO;
  349. memcpy(&sel, dh, sizeof(sel));
  350. switch (sel.access_method) {
  351. #ifdef CONFIG_HAS_IOPORT
  352. case DMI_SEL_ACCESS_METHOD_IO8:
  353. case DMI_SEL_ACCESS_METHOD_IO2x8:
  354. case DMI_SEL_ACCESS_METHOD_IO16:
  355. return dmi_sel_raw_read_io(entry, &sel, state->buf,
  356. state->pos, state->count);
  357. #endif
  358. case DMI_SEL_ACCESS_METHOD_PHYS32:
  359. return dmi_sel_raw_read_phys32(entry, &sel, state->buf,
  360. state->pos, state->count);
  361. case DMI_SEL_ACCESS_METHOD_GPNV:
  362. pr_info_ratelimited("dmi-sysfs: GPNV support missing.\n");
  363. return -EIO;
  364. default:
  365. pr_info_ratelimited("dmi-sysfs: Unknown access method %02x\n",
  366. sel.access_method);
  367. return -EIO;
  368. }
  369. }
  370. static ssize_t dmi_sel_raw_read(struct file *filp, struct kobject *kobj,
  371. struct bin_attribute *bin_attr,
  372. char *buf, loff_t pos, size_t count)
  373. {
  374. struct dmi_sysfs_entry *entry = to_entry(kobj->parent);
  375. struct dmi_read_state state = {
  376. .buf = buf,
  377. .pos = pos,
  378. .count = count,
  379. };
  380. return find_dmi_entry(entry, dmi_sel_raw_read_helper, &state);
  381. }
  382. static struct bin_attribute dmi_sel_raw_attr = {
  383. .attr = {.name = "raw_event_log", .mode = 0400},
  384. .read = dmi_sel_raw_read,
  385. };
  386. static int dmi_system_event_log(struct dmi_sysfs_entry *entry)
  387. {
  388. int ret;
  389. entry->child = kzalloc(sizeof(*entry->child), GFP_KERNEL);
  390. if (!entry->child)
  391. return -ENOMEM;
  392. ret = kobject_init_and_add(entry->child,
  393. &dmi_system_event_log_ktype,
  394. &entry->kobj,
  395. "system_event_log");
  396. if (ret)
  397. goto out_free;
  398. ret = sysfs_create_bin_file(entry->child, &dmi_sel_raw_attr);
  399. if (ret)
  400. goto out_del;
  401. return 0;
  402. out_del:
  403. kobject_del(entry->child);
  404. out_free:
  405. kfree(entry->child);
  406. return ret;
  407. }
  408. /*************************************************
  409. * Generic DMI entry support.
  410. *************************************************/
  411. static ssize_t dmi_sysfs_entry_length(struct dmi_sysfs_entry *entry, char *buf)
  412. {
  413. return sprintf(buf, "%d\n", entry->dh.length);
  414. }
  415. static ssize_t dmi_sysfs_entry_handle(struct dmi_sysfs_entry *entry, char *buf)
  416. {
  417. return sprintf(buf, "%d\n", entry->dh.handle);
  418. }
  419. static ssize_t dmi_sysfs_entry_type(struct dmi_sysfs_entry *entry, char *buf)
  420. {
  421. return sprintf(buf, "%d\n", entry->dh.type);
  422. }
  423. static ssize_t dmi_sysfs_entry_instance(struct dmi_sysfs_entry *entry,
  424. char *buf)
  425. {
  426. return sprintf(buf, "%d\n", entry->instance);
  427. }
  428. static ssize_t dmi_sysfs_entry_position(struct dmi_sysfs_entry *entry,
  429. char *buf)
  430. {
  431. return sprintf(buf, "%d\n", entry->position);
  432. }
  433. static DMI_SYSFS_ATTR(entry, length);
  434. static DMI_SYSFS_ATTR(entry, handle);
  435. static DMI_SYSFS_ATTR(entry, type);
  436. static DMI_SYSFS_ATTR(entry, instance);
  437. static DMI_SYSFS_ATTR(entry, position);
  438. static struct attribute *dmi_sysfs_entry_attrs[] = {
  439. &dmi_sysfs_attr_entry_length.attr,
  440. &dmi_sysfs_attr_entry_handle.attr,
  441. &dmi_sysfs_attr_entry_type.attr,
  442. &dmi_sysfs_attr_entry_instance.attr,
  443. &dmi_sysfs_attr_entry_position.attr,
  444. NULL,
  445. };
  446. ATTRIBUTE_GROUPS(dmi_sysfs_entry);
  447. static ssize_t dmi_entry_raw_read_helper(struct dmi_sysfs_entry *entry,
  448. const struct dmi_header *dh,
  449. void *_state)
  450. {
  451. struct dmi_read_state *state = _state;
  452. size_t entry_length;
  453. entry_length = dmi_entry_length(dh);
  454. return memory_read_from_buffer(state->buf, state->count,
  455. &state->pos, dh, entry_length);
  456. }
  457. static ssize_t dmi_entry_raw_read(struct file *filp,
  458. struct kobject *kobj,
  459. struct bin_attribute *bin_attr,
  460. char *buf, loff_t pos, size_t count)
  461. {
  462. struct dmi_sysfs_entry *entry = to_entry(kobj);
  463. struct dmi_read_state state = {
  464. .buf = buf,
  465. .pos = pos,
  466. .count = count,
  467. };
  468. return find_dmi_entry(entry, dmi_entry_raw_read_helper, &state);
  469. }
  470. static const struct bin_attribute dmi_entry_raw_attr = {
  471. .attr = {.name = "raw", .mode = 0400},
  472. .read = dmi_entry_raw_read,
  473. };
  474. static void dmi_sysfs_entry_release(struct kobject *kobj)
  475. {
  476. struct dmi_sysfs_entry *entry = to_entry(kobj);
  477. spin_lock(&entry_list_lock);
  478. list_del(&entry->list);
  479. spin_unlock(&entry_list_lock);
  480. kfree(entry);
  481. }
  482. static const struct kobj_type dmi_sysfs_entry_ktype = {
  483. .release = dmi_sysfs_entry_release,
  484. .sysfs_ops = &dmi_sysfs_attr_ops,
  485. .default_groups = dmi_sysfs_entry_groups,
  486. };
  487. static struct kset *dmi_kset;
  488. /* Global count of all instances seen. Only for setup */
  489. static int __initdata instance_counts[MAX_ENTRY_TYPE + 1];
  490. /* Global positional count of all entries seen. Only for setup */
  491. static int __initdata position_count;
  492. static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
  493. void *_ret)
  494. {
  495. struct dmi_sysfs_entry *entry;
  496. int *ret = _ret;
  497. /* If a previous entry saw an error, short circuit */
  498. if (*ret)
  499. return;
  500. /* Allocate and register a new entry into the entries set */
  501. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  502. if (!entry) {
  503. *ret = -ENOMEM;
  504. return;
  505. }
  506. /* Set the key */
  507. memcpy(&entry->dh, dh, sizeof(*dh));
  508. entry->instance = instance_counts[dh->type]++;
  509. entry->position = position_count++;
  510. entry->kobj.kset = dmi_kset;
  511. *ret = kobject_init_and_add(&entry->kobj, &dmi_sysfs_entry_ktype, NULL,
  512. "%d-%d", dh->type, entry->instance);
  513. /* Thread on the global list for cleanup */
  514. spin_lock(&entry_list_lock);
  515. list_add_tail(&entry->list, &entry_list);
  516. spin_unlock(&entry_list_lock);
  517. if (*ret) {
  518. kobject_put(&entry->kobj);
  519. return;
  520. }
  521. /* Handle specializations by type */
  522. switch (dh->type) {
  523. case DMI_ENTRY_SYSTEM_EVENT_LOG:
  524. *ret = dmi_system_event_log(entry);
  525. break;
  526. default:
  527. /* No specialization */
  528. break;
  529. }
  530. if (*ret)
  531. goto out_err;
  532. /* Create the raw binary file to access the entry */
  533. *ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr);
  534. if (*ret)
  535. goto out_err;
  536. return;
  537. out_err:
  538. kobject_put(entry->child);
  539. kobject_put(&entry->kobj);
  540. return;
  541. }
  542. static void cleanup_entry_list(void)
  543. {
  544. struct dmi_sysfs_entry *entry, *next;
  545. /* No locks, we are on our way out */
  546. list_for_each_entry_safe(entry, next, &entry_list, list) {
  547. kobject_put(entry->child);
  548. kobject_put(&entry->kobj);
  549. }
  550. }
  551. static int __init dmi_sysfs_init(void)
  552. {
  553. int error;
  554. int val;
  555. if (!dmi_kobj) {
  556. pr_debug("dmi-sysfs: dmi entry is absent.\n");
  557. error = -ENODATA;
  558. goto err;
  559. }
  560. dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj);
  561. if (!dmi_kset) {
  562. error = -ENOMEM;
  563. goto err;
  564. }
  565. val = 0;
  566. error = dmi_walk(dmi_sysfs_register_handle, &val);
  567. if (error)
  568. goto err;
  569. if (val) {
  570. error = val;
  571. goto err;
  572. }
  573. pr_debug("dmi-sysfs: loaded.\n");
  574. return 0;
  575. err:
  576. cleanup_entry_list();
  577. kset_unregister(dmi_kset);
  578. return error;
  579. }
  580. /* clean up everything. */
  581. static void __exit dmi_sysfs_exit(void)
  582. {
  583. pr_debug("dmi-sysfs: unloading.\n");
  584. cleanup_entry_list();
  585. kset_unregister(dmi_kset);
  586. }
  587. module_init(dmi_sysfs_init);
  588. module_exit(dmi_sysfs_exit);
  589. MODULE_AUTHOR("Mike Waychison <mikew@google.com>");
  590. MODULE_DESCRIPTION("DMI sysfs support");
  591. MODULE_LICENSE("GPL");