memory.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * drivers/base/memory.c - basic Memory class support
  3. *
  4. * Written by Matt Tolentino <matthew.e.tolentino@intel.com>
  5. * Dave Hansen <haveblue@us.ibm.com>
  6. *
  7. * This file provides the necessary infrastructure to represent
  8. * a SPARSEMEM-memory-model system's physical memory in /sysfs.
  9. * All arch-independent code that assumes MEMORY_HOTPLUG requires
  10. * SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
  11. */
  12. #include <linux/sysdev.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/topology.h>
  16. #include <linux/capability.h>
  17. #include <linux/device.h>
  18. #include <linux/memory.h>
  19. #include <linux/kobject.h>
  20. #include <linux/memory_hotplug.h>
  21. #include <linux/mm.h>
  22. #include <linux/mutex.h>
  23. #include <linux/stat.h>
  24. #include <linux/slab.h>
  25. #include <linux/atomic.h>
  26. #include <asm/uaccess.h>
  27. static DEFINE_MUTEX(mem_sysfs_mutex);
  28. #define MEMORY_CLASS_NAME "memory"
  29. static int sections_per_block;
  30. static inline int base_memory_block_id(int section_nr)
  31. {
  32. return section_nr / sections_per_block;
  33. }
  34. static struct sysdev_class memory_sysdev_class = {
  35. .name = MEMORY_CLASS_NAME,
  36. };
  37. static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
  38. {
  39. return MEMORY_CLASS_NAME;
  40. }
  41. static int memory_uevent(struct kset *kset, struct kobject *obj,
  42. struct kobj_uevent_env *env)
  43. {
  44. int retval = 0;
  45. return retval;
  46. }
  47. static const struct kset_uevent_ops memory_uevent_ops = {
  48. .name = memory_uevent_name,
  49. .uevent = memory_uevent,
  50. };
  51. static BLOCKING_NOTIFIER_HEAD(memory_chain);
  52. int register_memory_notifier(struct notifier_block *nb)
  53. {
  54. return blocking_notifier_chain_register(&memory_chain, nb);
  55. }
  56. EXPORT_SYMBOL(register_memory_notifier);
  57. void unregister_memory_notifier(struct notifier_block *nb)
  58. {
  59. blocking_notifier_chain_unregister(&memory_chain, nb);
  60. }
  61. EXPORT_SYMBOL(unregister_memory_notifier);
  62. static ATOMIC_NOTIFIER_HEAD(memory_isolate_chain);
  63. int register_memory_isolate_notifier(struct notifier_block *nb)
  64. {
  65. return atomic_notifier_chain_register(&memory_isolate_chain, nb);
  66. }
  67. EXPORT_SYMBOL(register_memory_isolate_notifier);
  68. void unregister_memory_isolate_notifier(struct notifier_block *nb)
  69. {
  70. atomic_notifier_chain_unregister(&memory_isolate_chain, nb);
  71. }
  72. EXPORT_SYMBOL(unregister_memory_isolate_notifier);
  73. /*
  74. * register_memory - Setup a sysfs device for a memory block
  75. */
  76. static
  77. int register_memory(struct memory_block *memory)
  78. {
  79. int error;
  80. memory->sysdev.cls = &memory_sysdev_class;
  81. memory->sysdev.id = memory->start_section_nr / sections_per_block;
  82. error = sysdev_register(&memory->sysdev);
  83. return error;
  84. }
  85. static void
  86. unregister_memory(struct memory_block *memory)
  87. {
  88. BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
  89. /* drop the ref. we got in remove_memory_block() */
  90. kobject_put(&memory->sysdev.kobj);
  91. sysdev_unregister(&memory->sysdev);
  92. }
  93. unsigned long __weak memory_block_size_bytes(void)
  94. {
  95. return MIN_MEMORY_BLOCK_SIZE;
  96. }
  97. static unsigned long get_memory_block_size(void)
  98. {
  99. unsigned long block_sz;
  100. block_sz = memory_block_size_bytes();
  101. /* Validate blk_sz is a power of 2 and not less than section size */
  102. if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) {
  103. WARN_ON(1);
  104. block_sz = MIN_MEMORY_BLOCK_SIZE;
  105. }
  106. return block_sz;
  107. }
  108. /*
  109. * use this as the physical section index that this memsection
  110. * uses.
  111. */
  112. static ssize_t show_mem_start_phys_index(struct sys_device *dev,
  113. struct sysdev_attribute *attr, char *buf)
  114. {
  115. struct memory_block *mem =
  116. container_of(dev, struct memory_block, sysdev);
  117. unsigned long phys_index;
  118. phys_index = mem->start_section_nr / sections_per_block;
  119. return sprintf(buf, "%08lx\n", phys_index);
  120. }
  121. static ssize_t show_mem_end_phys_index(struct sys_device *dev,
  122. struct sysdev_attribute *attr, char *buf)
  123. {
  124. struct memory_block *mem =
  125. container_of(dev, struct memory_block, sysdev);
  126. unsigned long phys_index;
  127. phys_index = mem->end_section_nr / sections_per_block;
  128. return sprintf(buf, "%08lx\n", phys_index);
  129. }
  130. /*
  131. * Show whether the section of memory is likely to be hot-removable
  132. */
  133. static ssize_t show_mem_removable(struct sys_device *dev,
  134. struct sysdev_attribute *attr, char *buf)
  135. {
  136. unsigned long i, pfn;
  137. int ret = 1;
  138. struct memory_block *mem =
  139. container_of(dev, struct memory_block, sysdev);
  140. for (i = 0; i < sections_per_block; i++) {
  141. pfn = section_nr_to_pfn(mem->start_section_nr + i);
  142. ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
  143. }
  144. return sprintf(buf, "%d\n", ret);
  145. }
  146. /*
  147. * online, offline, going offline, etc.
  148. */
  149. static ssize_t show_mem_state(struct sys_device *dev,
  150. struct sysdev_attribute *attr, char *buf)
  151. {
  152. struct memory_block *mem =
  153. container_of(dev, struct memory_block, sysdev);
  154. ssize_t len = 0;
  155. /*
  156. * We can probably put these states in a nice little array
  157. * so that they're not open-coded
  158. */
  159. switch (mem->state) {
  160. case MEM_ONLINE:
  161. len = sprintf(buf, "online\n");
  162. break;
  163. case MEM_OFFLINE:
  164. len = sprintf(buf, "offline\n");
  165. break;
  166. case MEM_GOING_OFFLINE:
  167. len = sprintf(buf, "going-offline\n");
  168. break;
  169. default:
  170. len = sprintf(buf, "ERROR-UNKNOWN-%ld\n",
  171. mem->state);
  172. WARN_ON(1);
  173. break;
  174. }
  175. return len;
  176. }
  177. int memory_notify(unsigned long val, void *v)
  178. {
  179. return blocking_notifier_call_chain(&memory_chain, val, v);
  180. }
  181. int memory_isolate_notify(unsigned long val, void *v)
  182. {
  183. return atomic_notifier_call_chain(&memory_isolate_chain, val, v);
  184. }
  185. /*
  186. * The probe routines leave the pages reserved, just as the bootmem code does.
  187. * Make sure they're still that way.
  188. */
  189. static bool pages_correctly_reserved(unsigned long start_pfn,
  190. unsigned long nr_pages)
  191. {
  192. int i, j;
  193. struct page *page;
  194. unsigned long pfn = start_pfn;
  195. /*
  196. * memmap between sections is not contiguous except with
  197. * SPARSEMEM_VMEMMAP. We lookup the page once per section
  198. * and assume memmap is contiguous within each section
  199. */
  200. for (i = 0; i < sections_per_block; i++, pfn += PAGES_PER_SECTION) {
  201. if (WARN_ON_ONCE(!pfn_valid(pfn)))
  202. return false;
  203. page = pfn_to_page(pfn);
  204. for (j = 0; j < PAGES_PER_SECTION; j++) {
  205. if (PageReserved(page + j))
  206. continue;
  207. printk(KERN_WARNING "section number %ld page number %d "
  208. "not reserved, was it already online?\n",
  209. pfn_to_section_nr(pfn), j);
  210. return false;
  211. }
  212. }
  213. return true;
  214. }
  215. /*
  216. * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
  217. * OK to have direct references to sparsemem variables in here.
  218. */
  219. static int
  220. memory_block_action(unsigned long phys_index, unsigned long action)
  221. {
  222. unsigned long start_pfn, start_paddr;
  223. unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
  224. struct page *first_page;
  225. int ret;
  226. first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT);
  227. switch (action) {
  228. case MEM_ONLINE:
  229. start_pfn = page_to_pfn(first_page);
  230. if (!pages_correctly_reserved(start_pfn, nr_pages))
  231. return -EBUSY;
  232. ret = online_pages(start_pfn, nr_pages);
  233. break;
  234. case MEM_OFFLINE:
  235. start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
  236. ret = remove_memory(start_paddr,
  237. nr_pages << PAGE_SHIFT);
  238. break;
  239. default:
  240. WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
  241. "%ld\n", __func__, phys_index, action, action);
  242. ret = -EINVAL;
  243. }
  244. return ret;
  245. }
  246. static int memory_block_change_state(struct memory_block *mem,
  247. unsigned long to_state, unsigned long from_state_req)
  248. {
  249. int ret = 0;
  250. mutex_lock(&mem->state_mutex);
  251. if (mem->state != from_state_req) {
  252. ret = -EINVAL;
  253. goto out;
  254. }
  255. if (to_state == MEM_OFFLINE)
  256. mem->state = MEM_GOING_OFFLINE;
  257. ret = memory_block_action(mem->start_section_nr, to_state);
  258. if (ret)
  259. mem->state = from_state_req;
  260. else
  261. mem->state = to_state;
  262. out:
  263. mutex_unlock(&mem->state_mutex);
  264. return ret;
  265. }
  266. static ssize_t
  267. store_mem_state(struct sys_device *dev,
  268. struct sysdev_attribute *attr, const char *buf, size_t count)
  269. {
  270. struct memory_block *mem;
  271. int ret = -EINVAL;
  272. mem = container_of(dev, struct memory_block, sysdev);
  273. if (!strncmp(buf, "online", min((int)count, 6)))
  274. ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
  275. else if(!strncmp(buf, "offline", min((int)count, 7)))
  276. ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
  277. if (ret)
  278. return ret;
  279. return count;
  280. }
  281. /*
  282. * phys_device is a bad name for this. What I really want
  283. * is a way to differentiate between memory ranges that
  284. * are part of physical devices that constitute
  285. * a complete removable unit or fru.
  286. * i.e. do these ranges belong to the same physical device,
  287. * s.t. if I offline all of these sections I can then
  288. * remove the physical device?
  289. */
  290. static ssize_t show_phys_device(struct sys_device *dev,
  291. struct sysdev_attribute *attr, char *buf)
  292. {
  293. struct memory_block *mem =
  294. container_of(dev, struct memory_block, sysdev);
  295. return sprintf(buf, "%d\n", mem->phys_device);
  296. }
  297. static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
  298. static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
  299. static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
  300. static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
  301. static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
  302. #define mem_create_simple_file(mem, attr_name) \
  303. sysdev_create_file(&mem->sysdev, &attr_##attr_name)
  304. #define mem_remove_simple_file(mem, attr_name) \
  305. sysdev_remove_file(&mem->sysdev, &attr_##attr_name)
  306. /*
  307. * Block size attribute stuff
  308. */
  309. static ssize_t
  310. print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr,
  311. char *buf)
  312. {
  313. return sprintf(buf, "%lx\n", get_memory_block_size());
  314. }
  315. static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL);
  316. static int block_size_init(void)
  317. {
  318. return sysfs_create_file(&memory_sysdev_class.kset.kobj,
  319. &attr_block_size_bytes.attr);
  320. }
  321. /*
  322. * Some architectures will have custom drivers to do this, and
  323. * will not need to do it from userspace. The fake hot-add code
  324. * as well as ppc64 will do all of their discovery in userspace
  325. * and will require this interface.
  326. */
  327. #ifdef CONFIG_ARCH_MEMORY_PROBE
  328. static ssize_t
  329. memory_probe_store(struct class *class, struct class_attribute *attr,
  330. const char *buf, size_t count)
  331. {
  332. u64 phys_addr;
  333. int nid;
  334. int i, ret;
  335. unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block;
  336. phys_addr = simple_strtoull(buf, NULL, 0);
  337. if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
  338. return -EINVAL;
  339. for (i = 0; i < sections_per_block; i++) {
  340. nid = memory_add_physaddr_to_nid(phys_addr);
  341. ret = add_memory(nid, phys_addr,
  342. PAGES_PER_SECTION << PAGE_SHIFT);
  343. if (ret)
  344. goto out;
  345. phys_addr += MIN_MEMORY_BLOCK_SIZE;
  346. }
  347. ret = count;
  348. out:
  349. return ret;
  350. }
  351. static CLASS_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
  352. static int memory_probe_init(void)
  353. {
  354. return sysfs_create_file(&memory_sysdev_class.kset.kobj,
  355. &class_attr_probe.attr);
  356. }
  357. #else
  358. static inline int memory_probe_init(void)
  359. {
  360. return 0;
  361. }
  362. #endif
  363. #ifdef CONFIG_MEMORY_FAILURE
  364. /*
  365. * Support for offlining pages of memory
  366. */
  367. /* Soft offline a page */
  368. static ssize_t
  369. store_soft_offline_page(struct class *class,
  370. struct class_attribute *attr,
  371. const char *buf, size_t count)
  372. {
  373. int ret;
  374. u64 pfn;
  375. if (!capable(CAP_SYS_ADMIN))
  376. return -EPERM;
  377. if (strict_strtoull(buf, 0, &pfn) < 0)
  378. return -EINVAL;
  379. pfn >>= PAGE_SHIFT;
  380. if (!pfn_valid(pfn))
  381. return -ENXIO;
  382. ret = soft_offline_page(pfn_to_page(pfn), 0);
  383. return ret == 0 ? count : ret;
  384. }
  385. /* Forcibly offline a page, including killing processes. */
  386. static ssize_t
  387. store_hard_offline_page(struct class *class,
  388. struct class_attribute *attr,
  389. const char *buf, size_t count)
  390. {
  391. int ret;
  392. u64 pfn;
  393. if (!capable(CAP_SYS_ADMIN))
  394. return -EPERM;
  395. if (strict_strtoull(buf, 0, &pfn) < 0)
  396. return -EINVAL;
  397. pfn >>= PAGE_SHIFT;
  398. ret = __memory_failure(pfn, 0, 0);
  399. return ret ? ret : count;
  400. }
  401. static CLASS_ATTR(soft_offline_page, 0644, NULL, store_soft_offline_page);
  402. static CLASS_ATTR(hard_offline_page, 0644, NULL, store_hard_offline_page);
  403. static __init int memory_fail_init(void)
  404. {
  405. int err;
  406. err = sysfs_create_file(&memory_sysdev_class.kset.kobj,
  407. &class_attr_soft_offline_page.attr);
  408. if (!err)
  409. err = sysfs_create_file(&memory_sysdev_class.kset.kobj,
  410. &class_attr_hard_offline_page.attr);
  411. return err;
  412. }
  413. #else
  414. static inline int memory_fail_init(void)
  415. {
  416. return 0;
  417. }
  418. #endif
  419. /*
  420. * Note that phys_device is optional. It is here to allow for
  421. * differentiation between which *physical* devices each
  422. * section belongs to...
  423. */
  424. int __weak arch_get_memory_phys_device(unsigned long start_pfn)
  425. {
  426. return 0;
  427. }
  428. struct memory_block *find_memory_block_hinted(struct mem_section *section,
  429. struct memory_block *hint)
  430. {
  431. struct kobject *kobj;
  432. struct sys_device *sysdev;
  433. struct memory_block *mem;
  434. char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
  435. int block_id = base_memory_block_id(__section_nr(section));
  436. kobj = hint ? &hint->sysdev.kobj : NULL;
  437. /*
  438. * This only works because we know that section == sysdev->id
  439. * slightly redundant with sysdev_register()
  440. */
  441. sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, block_id);
  442. kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj);
  443. if (!kobj)
  444. return NULL;
  445. sysdev = container_of(kobj, struct sys_device, kobj);
  446. mem = container_of(sysdev, struct memory_block, sysdev);
  447. return mem;
  448. }
  449. /*
  450. * For now, we have a linear search to go find the appropriate
  451. * memory_block corresponding to a particular phys_index. If
  452. * this gets to be a real problem, we can always use a radix
  453. * tree or something here.
  454. *
  455. * This could be made generic for all sysdev classes.
  456. */
  457. struct memory_block *find_memory_block(struct mem_section *section)
  458. {
  459. return find_memory_block_hinted(section, NULL);
  460. }
  461. static int init_memory_block(struct memory_block **memory,
  462. struct mem_section *section, unsigned long state)
  463. {
  464. struct memory_block *mem;
  465. unsigned long start_pfn;
  466. int scn_nr;
  467. int ret = 0;
  468. mem = kzalloc(sizeof(*mem), GFP_KERNEL);
  469. if (!mem)
  470. return -ENOMEM;
  471. scn_nr = __section_nr(section);
  472. mem->start_section_nr =
  473. base_memory_block_id(scn_nr) * sections_per_block;
  474. mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
  475. mem->state = state;
  476. mem->section_count++;
  477. mutex_init(&mem->state_mutex);
  478. start_pfn = section_nr_to_pfn(mem->start_section_nr);
  479. mem->phys_device = arch_get_memory_phys_device(start_pfn);
  480. ret = register_memory(mem);
  481. if (!ret)
  482. ret = mem_create_simple_file(mem, phys_index);
  483. if (!ret)
  484. ret = mem_create_simple_file(mem, end_phys_index);
  485. if (!ret)
  486. ret = mem_create_simple_file(mem, state);
  487. if (!ret)
  488. ret = mem_create_simple_file(mem, phys_device);
  489. if (!ret)
  490. ret = mem_create_simple_file(mem, removable);
  491. *memory = mem;
  492. return ret;
  493. }
  494. static int add_memory_section(int nid, struct mem_section *section,
  495. unsigned long state, enum mem_add_context context)
  496. {
  497. struct memory_block *mem;
  498. int ret = 0;
  499. mutex_lock(&mem_sysfs_mutex);
  500. mem = find_memory_block(section);
  501. if (mem) {
  502. mem->section_count++;
  503. kobject_put(&mem->sysdev.kobj);
  504. } else
  505. ret = init_memory_block(&mem, section, state);
  506. if (!ret) {
  507. if (context == HOTPLUG &&
  508. mem->section_count == sections_per_block)
  509. ret = register_mem_sect_under_node(mem, nid);
  510. }
  511. mutex_unlock(&mem_sysfs_mutex);
  512. return ret;
  513. }
  514. int remove_memory_block(unsigned long node_id, struct mem_section *section,
  515. int phys_device)
  516. {
  517. struct memory_block *mem;
  518. mutex_lock(&mem_sysfs_mutex);
  519. mem = find_memory_block(section);
  520. unregister_mem_sect_under_nodes(mem, __section_nr(section));
  521. mem->section_count--;
  522. if (mem->section_count == 0) {
  523. mem_remove_simple_file(mem, phys_index);
  524. mem_remove_simple_file(mem, end_phys_index);
  525. mem_remove_simple_file(mem, state);
  526. mem_remove_simple_file(mem, phys_device);
  527. mem_remove_simple_file(mem, removable);
  528. unregister_memory(mem);
  529. kfree(mem);
  530. } else
  531. kobject_put(&mem->sysdev.kobj);
  532. mutex_unlock(&mem_sysfs_mutex);
  533. return 0;
  534. }
  535. /*
  536. * need an interface for the VM to add new memory regions,
  537. * but without onlining it.
  538. */
  539. int register_new_memory(int nid, struct mem_section *section)
  540. {
  541. return add_memory_section(nid, section, MEM_OFFLINE, HOTPLUG);
  542. }
  543. int unregister_memory_section(struct mem_section *section)
  544. {
  545. if (!present_section(section))
  546. return -EINVAL;
  547. return remove_memory_block(0, section, 0);
  548. }
  549. /*
  550. * Initialize the sysfs support for memory devices...
  551. */
  552. int __init memory_dev_init(void)
  553. {
  554. unsigned int i;
  555. int ret;
  556. int err;
  557. unsigned long block_sz;
  558. memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops;
  559. ret = sysdev_class_register(&memory_sysdev_class);
  560. if (ret)
  561. goto out;
  562. block_sz = get_memory_block_size();
  563. sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
  564. /*
  565. * Create entries for memory sections that were found
  566. * during boot and have been initialized
  567. */
  568. for (i = 0; i < NR_MEM_SECTIONS; i++) {
  569. if (!present_section_nr(i))
  570. continue;
  571. err = add_memory_section(0, __nr_to_section(i), MEM_ONLINE,
  572. BOOT);
  573. if (!ret)
  574. ret = err;
  575. }
  576. err = memory_probe_init();
  577. if (!ret)
  578. ret = err;
  579. err = memory_fail_init();
  580. if (!ret)
  581. ret = err;
  582. err = block_size_init();
  583. if (!ret)
  584. ret = err;
  585. out:
  586. if (ret)
  587. printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
  588. return ret;
  589. }