sysfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * sysfs.c - sysfs support
  3. *
  4. * (C) 2006-2007 Shaohua Li <shaohua.li@intel.com>
  5. *
  6. * This code is licenced under the GPL.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/cpuidle.h>
  10. #include <linux/sysfs.h>
  11. #include <linux/slab.h>
  12. #include <linux/cpu.h>
  13. #include <linux/completion.h>
  14. #include <linux/capability.h>
  15. #include <linux/device.h>
  16. #include <linux/kobject.h>
  17. #include "cpuidle.h"
  18. static unsigned int sysfs_switch;
  19. static int __init cpuidle_sysfs_setup(char *unused)
  20. {
  21. sysfs_switch = 1;
  22. return 1;
  23. }
  24. __setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup);
  25. static ssize_t show_available_governors(struct device *dev,
  26. struct device_attribute *attr,
  27. char *buf)
  28. {
  29. ssize_t i = 0;
  30. struct cpuidle_governor *tmp;
  31. mutex_lock(&cpuidle_lock);
  32. list_for_each_entry(tmp, &cpuidle_governors, governor_list) {
  33. if (i >= (ssize_t) ((PAGE_SIZE/sizeof(char)) -
  34. CPUIDLE_NAME_LEN - 2))
  35. goto out;
  36. i += scnprintf(&buf[i], CPUIDLE_NAME_LEN, "%s ", tmp->name);
  37. }
  38. out:
  39. i+= sprintf(&buf[i], "\n");
  40. mutex_unlock(&cpuidle_lock);
  41. return i;
  42. }
  43. static ssize_t show_current_driver(struct device *dev,
  44. struct device_attribute *attr,
  45. char *buf)
  46. {
  47. ssize_t ret;
  48. struct cpuidle_driver *drv;
  49. spin_lock(&cpuidle_driver_lock);
  50. drv = cpuidle_get_driver();
  51. if (drv)
  52. ret = sprintf(buf, "%s\n", drv->name);
  53. else
  54. ret = sprintf(buf, "none\n");
  55. spin_unlock(&cpuidle_driver_lock);
  56. return ret;
  57. }
  58. static ssize_t show_current_governor(struct device *dev,
  59. struct device_attribute *attr,
  60. char *buf)
  61. {
  62. ssize_t ret;
  63. mutex_lock(&cpuidle_lock);
  64. if (cpuidle_curr_governor)
  65. ret = sprintf(buf, "%s\n", cpuidle_curr_governor->name);
  66. else
  67. ret = sprintf(buf, "none\n");
  68. mutex_unlock(&cpuidle_lock);
  69. return ret;
  70. }
  71. static ssize_t store_current_governor(struct device *dev,
  72. struct device_attribute *attr,
  73. const char *buf, size_t count)
  74. {
  75. char gov_name[CPUIDLE_NAME_LEN];
  76. int ret = -EINVAL;
  77. size_t len = count;
  78. struct cpuidle_governor *gov;
  79. if (!len || len >= sizeof(gov_name))
  80. return -EINVAL;
  81. memcpy(gov_name, buf, len);
  82. gov_name[len] = '\0';
  83. if (gov_name[len - 1] == '\n')
  84. gov_name[--len] = '\0';
  85. mutex_lock(&cpuidle_lock);
  86. list_for_each_entry(gov, &cpuidle_governors, governor_list) {
  87. if (strlen(gov->name) == len && !strcmp(gov->name, gov_name)) {
  88. ret = cpuidle_switch_governor(gov);
  89. break;
  90. }
  91. }
  92. mutex_unlock(&cpuidle_lock);
  93. if (ret)
  94. return ret;
  95. else
  96. return count;
  97. }
  98. static DEVICE_ATTR(current_driver, 0444, show_current_driver, NULL);
  99. static DEVICE_ATTR(current_governor_ro, 0444, show_current_governor, NULL);
  100. static struct attribute *cpuidle_default_attrs[] = {
  101. &dev_attr_current_driver.attr,
  102. &dev_attr_current_governor_ro.attr,
  103. NULL
  104. };
  105. static DEVICE_ATTR(available_governors, 0444, show_available_governors, NULL);
  106. static DEVICE_ATTR(current_governor, 0644, show_current_governor,
  107. store_current_governor);
  108. static struct attribute *cpuidle_switch_attrs[] = {
  109. &dev_attr_available_governors.attr,
  110. &dev_attr_current_driver.attr,
  111. &dev_attr_current_governor.attr,
  112. NULL
  113. };
  114. static struct attribute_group cpuidle_attr_group = {
  115. .attrs = cpuidle_default_attrs,
  116. .name = "cpuidle",
  117. };
  118. /**
  119. * cpuidle_add_interface - add CPU global sysfs attributes
  120. */
  121. int cpuidle_add_interface(struct device *dev)
  122. {
  123. if (sysfs_switch)
  124. cpuidle_attr_group.attrs = cpuidle_switch_attrs;
  125. return sysfs_create_group(&dev->kobj, &cpuidle_attr_group);
  126. }
  127. /**
  128. * cpuidle_remove_interface - remove CPU global sysfs attributes
  129. */
  130. void cpuidle_remove_interface(struct device *dev)
  131. {
  132. sysfs_remove_group(&dev->kobj, &cpuidle_attr_group);
  133. }
  134. struct cpuidle_attr {
  135. struct attribute attr;
  136. ssize_t (*show)(struct cpuidle_device *, char *);
  137. ssize_t (*store)(struct cpuidle_device *, const char *, size_t count);
  138. };
  139. #define define_one_ro(_name, show) \
  140. static struct cpuidle_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
  141. #define define_one_rw(_name, show, store) \
  142. static struct cpuidle_attr attr_##_name = __ATTR(_name, 0644, show, store)
  143. #define attr_to_cpuidleattr(a) container_of(a, struct cpuidle_attr, attr)
  144. struct cpuidle_device_kobj {
  145. struct cpuidle_device *dev;
  146. struct completion kobj_unregister;
  147. struct kobject kobj;
  148. };
  149. static inline struct cpuidle_device *to_cpuidle_device(struct kobject *kobj)
  150. {
  151. struct cpuidle_device_kobj *kdev =
  152. container_of(kobj, struct cpuidle_device_kobj, kobj);
  153. return kdev->dev;
  154. }
  155. static ssize_t cpuidle_show(struct kobject *kobj, struct attribute *attr,
  156. char *buf)
  157. {
  158. int ret = -EIO;
  159. struct cpuidle_device *dev = to_cpuidle_device(kobj);
  160. struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr);
  161. if (cattr->show) {
  162. mutex_lock(&cpuidle_lock);
  163. ret = cattr->show(dev, buf);
  164. mutex_unlock(&cpuidle_lock);
  165. }
  166. return ret;
  167. }
  168. static ssize_t cpuidle_store(struct kobject *kobj, struct attribute *attr,
  169. const char *buf, size_t count)
  170. {
  171. int ret = -EIO;
  172. struct cpuidle_device *dev = to_cpuidle_device(kobj);
  173. struct cpuidle_attr *cattr = attr_to_cpuidleattr(attr);
  174. if (cattr->store) {
  175. mutex_lock(&cpuidle_lock);
  176. ret = cattr->store(dev, buf, count);
  177. mutex_unlock(&cpuidle_lock);
  178. }
  179. return ret;
  180. }
  181. static const struct sysfs_ops cpuidle_sysfs_ops = {
  182. .show = cpuidle_show,
  183. .store = cpuidle_store,
  184. };
  185. static void cpuidle_sysfs_release(struct kobject *kobj)
  186. {
  187. struct cpuidle_device_kobj *kdev =
  188. container_of(kobj, struct cpuidle_device_kobj, kobj);
  189. complete(&kdev->kobj_unregister);
  190. }
  191. static struct kobj_type ktype_cpuidle = {
  192. .sysfs_ops = &cpuidle_sysfs_ops,
  193. .release = cpuidle_sysfs_release,
  194. };
  195. struct cpuidle_state_attr {
  196. struct attribute attr;
  197. ssize_t (*show)(struct cpuidle_state *, \
  198. struct cpuidle_state_usage *, char *);
  199. ssize_t (*store)(struct cpuidle_state *, \
  200. struct cpuidle_state_usage *, const char *, size_t);
  201. };
  202. #define define_one_state_ro(_name, show) \
  203. static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
  204. #define define_one_state_rw(_name, show, store) \
  205. static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0644, show, store)
  206. #define define_show_state_function(_name) \
  207. static ssize_t show_state_##_name(struct cpuidle_state *state, \
  208. struct cpuidle_state_usage *state_usage, char *buf) \
  209. { \
  210. return sprintf(buf, "%u\n", state->_name);\
  211. }
  212. #define define_store_state_ull_function(_name) \
  213. static ssize_t store_state_##_name(struct cpuidle_state *state, \
  214. struct cpuidle_state_usage *state_usage, \
  215. const char *buf, size_t size) \
  216. { \
  217. unsigned long long value; \
  218. int err; \
  219. if (!capable(CAP_SYS_ADMIN)) \
  220. return -EPERM; \
  221. err = kstrtoull(buf, 0, &value); \
  222. if (err) \
  223. return err; \
  224. if (value) \
  225. state_usage->_name = 1; \
  226. else \
  227. state_usage->_name = 0; \
  228. return size; \
  229. }
  230. #define define_show_state_ull_function(_name) \
  231. static ssize_t show_state_##_name(struct cpuidle_state *state, \
  232. struct cpuidle_state_usage *state_usage, \
  233. char *buf) \
  234. { \
  235. return sprintf(buf, "%llu\n", state_usage->_name);\
  236. }
  237. #define define_show_state_str_function(_name) \
  238. static ssize_t show_state_##_name(struct cpuidle_state *state, \
  239. struct cpuidle_state_usage *state_usage, \
  240. char *buf) \
  241. { \
  242. if (state->_name[0] == '\0')\
  243. return sprintf(buf, "<null>\n");\
  244. return sprintf(buf, "%s\n", state->_name);\
  245. }
  246. define_show_state_function(exit_latency)
  247. define_show_state_function(target_residency)
  248. define_show_state_function(power_usage)
  249. define_show_state_ull_function(usage)
  250. define_show_state_ull_function(time)
  251. define_show_state_str_function(name)
  252. define_show_state_str_function(desc)
  253. define_show_state_ull_function(disable)
  254. define_store_state_ull_function(disable)
  255. define_one_state_ro(name, show_state_name);
  256. define_one_state_ro(desc, show_state_desc);
  257. define_one_state_ro(latency, show_state_exit_latency);
  258. define_one_state_ro(residency, show_state_target_residency);
  259. define_one_state_ro(power, show_state_power_usage);
  260. define_one_state_ro(usage, show_state_usage);
  261. define_one_state_ro(time, show_state_time);
  262. define_one_state_rw(disable, show_state_disable, store_state_disable);
  263. static struct attribute *cpuidle_state_default_attrs[] = {
  264. &attr_name.attr,
  265. &attr_desc.attr,
  266. &attr_latency.attr,
  267. &attr_residency.attr,
  268. &attr_power.attr,
  269. &attr_usage.attr,
  270. &attr_time.attr,
  271. &attr_disable.attr,
  272. NULL
  273. };
  274. struct cpuidle_state_kobj {
  275. struct cpuidle_state *state;
  276. struct cpuidle_state_usage *state_usage;
  277. struct completion kobj_unregister;
  278. struct kobject kobj;
  279. };
  280. #define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
  281. #define kobj_to_state(k) (kobj_to_state_obj(k)->state)
  282. #define kobj_to_state_usage(k) (kobj_to_state_obj(k)->state_usage)
  283. #define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
  284. static ssize_t cpuidle_state_show(struct kobject *kobj, struct attribute *attr,
  285. char * buf)
  286. {
  287. int ret = -EIO;
  288. struct cpuidle_state *state = kobj_to_state(kobj);
  289. struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
  290. struct cpuidle_state_attr * cattr = attr_to_stateattr(attr);
  291. if (cattr->show)
  292. ret = cattr->show(state, state_usage, buf);
  293. return ret;
  294. }
  295. static ssize_t cpuidle_state_store(struct kobject *kobj, struct attribute *attr,
  296. const char *buf, size_t size)
  297. {
  298. int ret = -EIO;
  299. struct cpuidle_state *state = kobj_to_state(kobj);
  300. struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
  301. struct cpuidle_state_attr *cattr = attr_to_stateattr(attr);
  302. if (cattr->store)
  303. ret = cattr->store(state, state_usage, buf, size);
  304. return ret;
  305. }
  306. static const struct sysfs_ops cpuidle_state_sysfs_ops = {
  307. .show = cpuidle_state_show,
  308. .store = cpuidle_state_store,
  309. };
  310. static void cpuidle_state_sysfs_release(struct kobject *kobj)
  311. {
  312. struct cpuidle_state_kobj *state_obj = kobj_to_state_obj(kobj);
  313. complete(&state_obj->kobj_unregister);
  314. }
  315. static struct kobj_type ktype_state_cpuidle = {
  316. .sysfs_ops = &cpuidle_state_sysfs_ops,
  317. .default_attrs = cpuidle_state_default_attrs,
  318. .release = cpuidle_state_sysfs_release,
  319. };
  320. static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
  321. {
  322. kobject_put(&device->kobjs[i]->kobj);
  323. wait_for_completion(&device->kobjs[i]->kobj_unregister);
  324. kfree(device->kobjs[i]);
  325. device->kobjs[i] = NULL;
  326. }
  327. /**
  328. * cpuidle_add_state_sysfs - adds cpuidle states sysfs attributes
  329. * @device: the target device
  330. */
  331. static int cpuidle_add_state_sysfs(struct cpuidle_device *device)
  332. {
  333. int i, ret = -ENOMEM;
  334. struct cpuidle_state_kobj *kobj;
  335. struct cpuidle_device_kobj *kdev = device->kobj_dev;
  336. struct cpuidle_driver *drv = cpuidle_get_cpu_driver(device);
  337. /* state statistics */
  338. for (i = 0; i < drv->state_count; i++) {
  339. kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
  340. if (!kobj)
  341. goto error_state;
  342. kobj->state = &drv->states[i];
  343. kobj->state_usage = &device->states_usage[i];
  344. init_completion(&kobj->kobj_unregister);
  345. ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle,
  346. &kdev->kobj, "state%d", i);
  347. if (ret) {
  348. kfree(kobj);
  349. goto error_state;
  350. }
  351. kobject_uevent(&kobj->kobj, KOBJ_ADD);
  352. device->kobjs[i] = kobj;
  353. }
  354. return 0;
  355. error_state:
  356. for (i = i - 1; i >= 0; i--)
  357. cpuidle_free_state_kobj(device, i);
  358. return ret;
  359. }
  360. /**
  361. * cpuidle_remove_driver_sysfs - removes the cpuidle states sysfs attributes
  362. * @device: the target device
  363. */
  364. static void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
  365. {
  366. struct cpuidle_driver *drv = cpuidle_get_cpu_driver(device);
  367. int i;
  368. for (i = 0; i < drv->state_count; i++)
  369. cpuidle_free_state_kobj(device, i);
  370. }
  371. #ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS
  372. #define kobj_to_driver_kobj(k) container_of(k, struct cpuidle_driver_kobj, kobj)
  373. #define attr_to_driver_attr(a) container_of(a, struct cpuidle_driver_attr, attr)
  374. #define define_one_driver_ro(_name, show) \
  375. static struct cpuidle_driver_attr attr_driver_##_name = \
  376. __ATTR(_name, 0444, show, NULL)
  377. struct cpuidle_driver_kobj {
  378. struct cpuidle_driver *drv;
  379. struct completion kobj_unregister;
  380. struct kobject kobj;
  381. };
  382. struct cpuidle_driver_attr {
  383. struct attribute attr;
  384. ssize_t (*show)(struct cpuidle_driver *, char *);
  385. ssize_t (*store)(struct cpuidle_driver *, const char *, size_t);
  386. };
  387. static ssize_t show_driver_name(struct cpuidle_driver *drv, char *buf)
  388. {
  389. ssize_t ret;
  390. spin_lock(&cpuidle_driver_lock);
  391. ret = sprintf(buf, "%s\n", drv ? drv->name : "none");
  392. spin_unlock(&cpuidle_driver_lock);
  393. return ret;
  394. }
  395. static void cpuidle_driver_sysfs_release(struct kobject *kobj)
  396. {
  397. struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
  398. complete(&driver_kobj->kobj_unregister);
  399. }
  400. static ssize_t cpuidle_driver_show(struct kobject *kobj, struct attribute *attr,
  401. char *buf)
  402. {
  403. int ret = -EIO;
  404. struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
  405. struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);
  406. if (dattr->show)
  407. ret = dattr->show(driver_kobj->drv, buf);
  408. return ret;
  409. }
  410. static ssize_t cpuidle_driver_store(struct kobject *kobj, struct attribute *attr,
  411. const char *buf, size_t size)
  412. {
  413. int ret = -EIO;
  414. struct cpuidle_driver_kobj *driver_kobj = kobj_to_driver_kobj(kobj);
  415. struct cpuidle_driver_attr *dattr = attr_to_driver_attr(attr);
  416. if (dattr->store)
  417. ret = dattr->store(driver_kobj->drv, buf, size);
  418. return ret;
  419. }
  420. define_one_driver_ro(name, show_driver_name);
  421. static const struct sysfs_ops cpuidle_driver_sysfs_ops = {
  422. .show = cpuidle_driver_show,
  423. .store = cpuidle_driver_store,
  424. };
  425. static struct attribute *cpuidle_driver_default_attrs[] = {
  426. &attr_driver_name.attr,
  427. NULL
  428. };
  429. static struct kobj_type ktype_driver_cpuidle = {
  430. .sysfs_ops = &cpuidle_driver_sysfs_ops,
  431. .default_attrs = cpuidle_driver_default_attrs,
  432. .release = cpuidle_driver_sysfs_release,
  433. };
  434. /**
  435. * cpuidle_add_driver_sysfs - adds the driver name sysfs attribute
  436. * @device: the target device
  437. */
  438. static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
  439. {
  440. struct cpuidle_driver_kobj *kdrv;
  441. struct cpuidle_device_kobj *kdev = dev->kobj_dev;
  442. struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
  443. int ret;
  444. kdrv = kzalloc(sizeof(*kdrv), GFP_KERNEL);
  445. if (!kdrv)
  446. return -ENOMEM;
  447. kdrv->drv = drv;
  448. init_completion(&kdrv->kobj_unregister);
  449. ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle,
  450. &kdev->kobj, "driver");
  451. if (ret) {
  452. kfree(kdrv);
  453. return ret;
  454. }
  455. kobject_uevent(&kdrv->kobj, KOBJ_ADD);
  456. dev->kobj_driver = kdrv;
  457. return ret;
  458. }
  459. /**
  460. * cpuidle_remove_driver_sysfs - removes the driver name sysfs attribute
  461. * @device: the target device
  462. */
  463. static void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
  464. {
  465. struct cpuidle_driver_kobj *kdrv = dev->kobj_driver;
  466. kobject_put(&kdrv->kobj);
  467. wait_for_completion(&kdrv->kobj_unregister);
  468. kfree(kdrv);
  469. }
  470. #else
  471. static inline int cpuidle_add_driver_sysfs(struct cpuidle_device *dev)
  472. {
  473. return 0;
  474. }
  475. static inline void cpuidle_remove_driver_sysfs(struct cpuidle_device *dev)
  476. {
  477. ;
  478. }
  479. #endif
  480. /**
  481. * cpuidle_add_device_sysfs - adds device specific sysfs attributes
  482. * @device: the target device
  483. */
  484. int cpuidle_add_device_sysfs(struct cpuidle_device *device)
  485. {
  486. int ret;
  487. ret = cpuidle_add_state_sysfs(device);
  488. if (ret)
  489. return ret;
  490. ret = cpuidle_add_driver_sysfs(device);
  491. if (ret)
  492. cpuidle_remove_state_sysfs(device);
  493. return ret;
  494. }
  495. /**
  496. * cpuidle_remove_device_sysfs : removes device specific sysfs attributes
  497. * @device : the target device
  498. */
  499. void cpuidle_remove_device_sysfs(struct cpuidle_device *device)
  500. {
  501. cpuidle_remove_driver_sysfs(device);
  502. cpuidle_remove_state_sysfs(device);
  503. }
  504. /**
  505. * cpuidle_add_sysfs - creates a sysfs instance for the target device
  506. * @dev: the target device
  507. */
  508. int cpuidle_add_sysfs(struct cpuidle_device *dev)
  509. {
  510. struct cpuidle_device_kobj *kdev;
  511. struct device *cpu_dev = get_cpu_device((unsigned long)dev->cpu);
  512. int error;
  513. /*
  514. * Return if cpu_device is not setup for this CPU.
  515. *
  516. * This could happen if the arch did not set up cpu_device
  517. * since this CPU is not in cpu_present mask and the
  518. * driver did not send a correct CPU mask during registration.
  519. * Without this check we would end up passing bogus
  520. * value for &cpu_dev->kobj in kobject_init_and_add()
  521. */
  522. if (!cpu_dev)
  523. return -ENODEV;
  524. kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
  525. if (!kdev)
  526. return -ENOMEM;
  527. kdev->dev = dev;
  528. dev->kobj_dev = kdev;
  529. init_completion(&kdev->kobj_unregister);
  530. error = kobject_init_and_add(&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj,
  531. "cpuidle");
  532. if (error) {
  533. kfree(kdev);
  534. return error;
  535. }
  536. kobject_uevent(&kdev->kobj, KOBJ_ADD);
  537. return 0;
  538. }
  539. /**
  540. * cpuidle_remove_sysfs - deletes a sysfs instance on the target device
  541. * @dev: the target device
  542. */
  543. void cpuidle_remove_sysfs(struct cpuidle_device *dev)
  544. {
  545. struct cpuidle_device_kobj *kdev = dev->kobj_dev;
  546. kobject_put(&kdev->kobj);
  547. wait_for_completion(&kdev->kobj_unregister);
  548. kfree(kdev);
  549. }