devres.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * drivers/base/devres.c - device resource management
  3. *
  4. * Copyright (c) 2006 SUSE Linux Products GmbH
  5. * Copyright (c) 2006 Tejun Heo <teheo@suse.de>
  6. *
  7. * This file is released under the GPLv2.
  8. */
  9. #include <linux/device.h>
  10. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include "base.h"
  13. struct devres_node {
  14. struct list_head entry;
  15. dr_release_t release;
  16. #ifdef CONFIG_DEBUG_DEVRES
  17. const char *name;
  18. size_t size;
  19. #endif
  20. };
  21. struct devres {
  22. struct devres_node node;
  23. /* -- 3 pointers */
  24. unsigned long long data[]; /* guarantee ull alignment */
  25. };
  26. struct devres_group {
  27. struct devres_node node[2];
  28. void *id;
  29. int color;
  30. /* -- 8 pointers */
  31. };
  32. #ifdef CONFIG_DEBUG_DEVRES
  33. static int log_devres = 0;
  34. module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR);
  35. static void set_node_dbginfo(struct devres_node *node, const char *name,
  36. size_t size)
  37. {
  38. node->name = name;
  39. node->size = size;
  40. }
  41. static void devres_log(struct device *dev, struct devres_node *node,
  42. const char *op)
  43. {
  44. if (unlikely(log_devres))
  45. dev_printk(KERN_ERR, dev, "DEVRES %3s %p %s (%lu bytes)\n",
  46. op, node, node->name, (unsigned long)node->size);
  47. }
  48. #else /* CONFIG_DEBUG_DEVRES */
  49. #define set_node_dbginfo(node, n, s) do {} while (0)
  50. #define devres_log(dev, node, op) do {} while (0)
  51. #endif /* CONFIG_DEBUG_DEVRES */
  52. /*
  53. * Release functions for devres group. These callbacks are used only
  54. * for identification.
  55. */
  56. static void group_open_release(struct device *dev, void *res)
  57. {
  58. /* noop */
  59. }
  60. static void group_close_release(struct device *dev, void *res)
  61. {
  62. /* noop */
  63. }
  64. static struct devres_group * node_to_group(struct devres_node *node)
  65. {
  66. if (node->release == &group_open_release)
  67. return container_of(node, struct devres_group, node[0]);
  68. if (node->release == &group_close_release)
  69. return container_of(node, struct devres_group, node[1]);
  70. return NULL;
  71. }
  72. static __always_inline struct devres * alloc_dr(dr_release_t release,
  73. size_t size, gfp_t gfp)
  74. {
  75. size_t tot_size = sizeof(struct devres) + size;
  76. struct devres *dr;
  77. dr = kmalloc_track_caller(tot_size, gfp);
  78. if (unlikely(!dr))
  79. return NULL;
  80. memset(dr, 0, tot_size);
  81. INIT_LIST_HEAD(&dr->node.entry);
  82. dr->node.release = release;
  83. return dr;
  84. }
  85. static void add_dr(struct device *dev, struct devres_node *node)
  86. {
  87. devres_log(dev, node, "ADD");
  88. BUG_ON(!list_empty(&node->entry));
  89. list_add_tail(&node->entry, &dev->devres_head);
  90. }
  91. #ifdef CONFIG_DEBUG_DEVRES
  92. void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
  93. const char *name)
  94. {
  95. struct devres *dr;
  96. dr = alloc_dr(release, size, gfp);
  97. if (unlikely(!dr))
  98. return NULL;
  99. set_node_dbginfo(&dr->node, name, size);
  100. return dr->data;
  101. }
  102. EXPORT_SYMBOL_GPL(__devres_alloc);
  103. #else
  104. /**
  105. * devres_alloc - Allocate device resource data
  106. * @release: Release function devres will be associated with
  107. * @size: Allocation size
  108. * @gfp: Allocation flags
  109. *
  110. * Allocate devres of @size bytes. The allocated area is zeroed, then
  111. * associated with @release. The returned pointer can be passed to
  112. * other devres_*() functions.
  113. *
  114. * RETURNS:
  115. * Pointer to allocated devres on success, NULL on failure.
  116. */
  117. void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
  118. {
  119. struct devres *dr;
  120. dr = alloc_dr(release, size, gfp);
  121. if (unlikely(!dr))
  122. return NULL;
  123. return dr->data;
  124. }
  125. EXPORT_SYMBOL_GPL(devres_alloc);
  126. #endif
  127. /**
  128. * devres_for_each_res - Resource iterator
  129. * @dev: Device to iterate resource from
  130. * @release: Look for resources associated with this release function
  131. * @match: Match function (optional)
  132. * @match_data: Data for the match function
  133. * @fn: Function to be called for each matched resource.
  134. * @data: Data for @fn, the 3rd parameter of @fn
  135. *
  136. * Call @fn for each devres of @dev which is associated with @release
  137. * and for which @match returns 1.
  138. *
  139. * RETURNS:
  140. * void
  141. */
  142. void devres_for_each_res(struct device *dev, dr_release_t release,
  143. dr_match_t match, void *match_data,
  144. void (*fn)(struct device *, void *, void *),
  145. void *data)
  146. {
  147. struct devres_node *node;
  148. struct devres_node *tmp;
  149. unsigned long flags;
  150. if (!fn)
  151. return;
  152. spin_lock_irqsave(&dev->devres_lock, flags);
  153. list_for_each_entry_safe_reverse(node, tmp,
  154. &dev->devres_head, entry) {
  155. struct devres *dr = container_of(node, struct devres, node);
  156. if (node->release != release)
  157. continue;
  158. if (match && !match(dev, dr->data, match_data))
  159. continue;
  160. fn(dev, dr->data, data);
  161. }
  162. spin_unlock_irqrestore(&dev->devres_lock, flags);
  163. }
  164. EXPORT_SYMBOL_GPL(devres_for_each_res);
  165. /**
  166. * devres_free - Free device resource data
  167. * @res: Pointer to devres data to free
  168. *
  169. * Free devres created with devres_alloc().
  170. */
  171. void devres_free(void *res)
  172. {
  173. if (res) {
  174. struct devres *dr = container_of(res, struct devres, data);
  175. BUG_ON(!list_empty(&dr->node.entry));
  176. kfree(dr);
  177. }
  178. }
  179. EXPORT_SYMBOL_GPL(devres_free);
  180. /**
  181. * devres_add - Register device resource
  182. * @dev: Device to add resource to
  183. * @res: Resource to register
  184. *
  185. * Register devres @res to @dev. @res should have been allocated
  186. * using devres_alloc(). On driver detach, the associated release
  187. * function will be invoked and devres will be freed automatically.
  188. */
  189. void devres_add(struct device *dev, void *res)
  190. {
  191. struct devres *dr = container_of(res, struct devres, data);
  192. unsigned long flags;
  193. spin_lock_irqsave(&dev->devres_lock, flags);
  194. add_dr(dev, &dr->node);
  195. spin_unlock_irqrestore(&dev->devres_lock, flags);
  196. }
  197. EXPORT_SYMBOL_GPL(devres_add);
  198. static struct devres *find_dr(struct device *dev, dr_release_t release,
  199. dr_match_t match, void *match_data)
  200. {
  201. struct devres_node *node;
  202. list_for_each_entry_reverse(node, &dev->devres_head, entry) {
  203. struct devres *dr = container_of(node, struct devres, node);
  204. if (node->release != release)
  205. continue;
  206. if (match && !match(dev, dr->data, match_data))
  207. continue;
  208. return dr;
  209. }
  210. return NULL;
  211. }
  212. /**
  213. * devres_find - Find device resource
  214. * @dev: Device to lookup resource from
  215. * @release: Look for resources associated with this release function
  216. * @match: Match function (optional)
  217. * @match_data: Data for the match function
  218. *
  219. * Find the latest devres of @dev which is associated with @release
  220. * and for which @match returns 1. If @match is NULL, it's considered
  221. * to match all.
  222. *
  223. * RETURNS:
  224. * Pointer to found devres, NULL if not found.
  225. */
  226. void * devres_find(struct device *dev, dr_release_t release,
  227. dr_match_t match, void *match_data)
  228. {
  229. struct devres *dr;
  230. unsigned long flags;
  231. spin_lock_irqsave(&dev->devres_lock, flags);
  232. dr = find_dr(dev, release, match, match_data);
  233. spin_unlock_irqrestore(&dev->devres_lock, flags);
  234. if (dr)
  235. return dr->data;
  236. return NULL;
  237. }
  238. EXPORT_SYMBOL_GPL(devres_find);
  239. /**
  240. * devres_get - Find devres, if non-existent, add one atomically
  241. * @dev: Device to lookup or add devres for
  242. * @new_res: Pointer to new initialized devres to add if not found
  243. * @match: Match function (optional)
  244. * @match_data: Data for the match function
  245. *
  246. * Find the latest devres of @dev which has the same release function
  247. * as @new_res and for which @match return 1. If found, @new_res is
  248. * freed; otherwise, @new_res is added atomically.
  249. *
  250. * RETURNS:
  251. * Pointer to found or added devres.
  252. */
  253. void * devres_get(struct device *dev, void *new_res,
  254. dr_match_t match, void *match_data)
  255. {
  256. struct devres *new_dr = container_of(new_res, struct devres, data);
  257. struct devres *dr;
  258. unsigned long flags;
  259. spin_lock_irqsave(&dev->devres_lock, flags);
  260. dr = find_dr(dev, new_dr->node.release, match, match_data);
  261. if (!dr) {
  262. add_dr(dev, &new_dr->node);
  263. dr = new_dr;
  264. new_res = NULL;
  265. }
  266. spin_unlock_irqrestore(&dev->devres_lock, flags);
  267. devres_free(new_res);
  268. return dr->data;
  269. }
  270. EXPORT_SYMBOL_GPL(devres_get);
  271. /**
  272. * devres_remove - Find a device resource and remove it
  273. * @dev: Device to find resource from
  274. * @release: Look for resources associated with this release function
  275. * @match: Match function (optional)
  276. * @match_data: Data for the match function
  277. *
  278. * Find the latest devres of @dev associated with @release and for
  279. * which @match returns 1. If @match is NULL, it's considered to
  280. * match all. If found, the resource is removed atomically and
  281. * returned.
  282. *
  283. * RETURNS:
  284. * Pointer to removed devres on success, NULL if not found.
  285. */
  286. void * devres_remove(struct device *dev, dr_release_t release,
  287. dr_match_t match, void *match_data)
  288. {
  289. struct devres *dr;
  290. unsigned long flags;
  291. spin_lock_irqsave(&dev->devres_lock, flags);
  292. dr = find_dr(dev, release, match, match_data);
  293. if (dr) {
  294. list_del_init(&dr->node.entry);
  295. devres_log(dev, &dr->node, "REM");
  296. }
  297. spin_unlock_irqrestore(&dev->devres_lock, flags);
  298. if (dr)
  299. return dr->data;
  300. return NULL;
  301. }
  302. EXPORT_SYMBOL_GPL(devres_remove);
  303. /**
  304. * devres_destroy - Find a device resource and destroy it
  305. * @dev: Device to find resource from
  306. * @release: Look for resources associated with this release function
  307. * @match: Match function (optional)
  308. * @match_data: Data for the match function
  309. *
  310. * Find the latest devres of @dev associated with @release and for
  311. * which @match returns 1. If @match is NULL, it's considered to
  312. * match all. If found, the resource is removed atomically and freed.
  313. *
  314. * RETURNS:
  315. * 0 if devres is found and freed, -ENOENT if not found.
  316. */
  317. int devres_destroy(struct device *dev, dr_release_t release,
  318. dr_match_t match, void *match_data)
  319. {
  320. void *res;
  321. res = devres_remove(dev, release, match, match_data);
  322. if (unlikely(!res))
  323. return -ENOENT;
  324. devres_free(res);
  325. return 0;
  326. }
  327. EXPORT_SYMBOL_GPL(devres_destroy);
  328. /**
  329. * devres_release - Find a device resource and destroy it, calling release
  330. * @dev: Device to find resource from
  331. * @release: Look for resources associated with this release function
  332. * @match: Match function (optional)
  333. * @match_data: Data for the match function
  334. *
  335. * Find the latest devres of @dev associated with @release and for
  336. * which @match returns 1. If @match is NULL, it's considered to
  337. * match all. If found, the resource is removed atomically, the
  338. * release function called and the resource freed.
  339. *
  340. * RETURNS:
  341. * 0 if devres is found and freed, -ENOENT if not found.
  342. */
  343. int devres_release(struct device *dev, dr_release_t release,
  344. dr_match_t match, void *match_data)
  345. {
  346. void *res;
  347. res = devres_remove(dev, release, match, match_data);
  348. if (unlikely(!res))
  349. return -ENOENT;
  350. (*release)(dev, res);
  351. devres_free(res);
  352. return 0;
  353. }
  354. EXPORT_SYMBOL_GPL(devres_release);
  355. static int remove_nodes(struct device *dev,
  356. struct list_head *first, struct list_head *end,
  357. struct list_head *todo)
  358. {
  359. int cnt = 0, nr_groups = 0;
  360. struct list_head *cur;
  361. /* First pass - move normal devres entries to @todo and clear
  362. * devres_group colors.
  363. */
  364. cur = first;
  365. while (cur != end) {
  366. struct devres_node *node;
  367. struct devres_group *grp;
  368. node = list_entry(cur, struct devres_node, entry);
  369. cur = cur->next;
  370. grp = node_to_group(node);
  371. if (grp) {
  372. /* clear color of group markers in the first pass */
  373. grp->color = 0;
  374. nr_groups++;
  375. } else {
  376. /* regular devres entry */
  377. if (&node->entry == first)
  378. first = first->next;
  379. list_move_tail(&node->entry, todo);
  380. cnt++;
  381. }
  382. }
  383. if (!nr_groups)
  384. return cnt;
  385. /* Second pass - Scan groups and color them. A group gets
  386. * color value of two iff the group is wholly contained in
  387. * [cur, end). That is, for a closed group, both opening and
  388. * closing markers should be in the range, while just the
  389. * opening marker is enough for an open group.
  390. */
  391. cur = first;
  392. while (cur != end) {
  393. struct devres_node *node;
  394. struct devres_group *grp;
  395. node = list_entry(cur, struct devres_node, entry);
  396. cur = cur->next;
  397. grp = node_to_group(node);
  398. BUG_ON(!grp || list_empty(&grp->node[0].entry));
  399. grp->color++;
  400. if (list_empty(&grp->node[1].entry))
  401. grp->color++;
  402. BUG_ON(grp->color <= 0 || grp->color > 2);
  403. if (grp->color == 2) {
  404. /* No need to update cur or end. The removed
  405. * nodes are always before both.
  406. */
  407. list_move_tail(&grp->node[0].entry, todo);
  408. list_del_init(&grp->node[1].entry);
  409. }
  410. }
  411. return cnt;
  412. }
  413. static int release_nodes(struct device *dev, struct list_head *first,
  414. struct list_head *end, unsigned long flags)
  415. __releases(&dev->devres_lock)
  416. {
  417. LIST_HEAD(todo);
  418. int cnt;
  419. struct devres *dr, *tmp;
  420. cnt = remove_nodes(dev, first, end, &todo);
  421. spin_unlock_irqrestore(&dev->devres_lock, flags);
  422. /* Release. Note that both devres and devres_group are
  423. * handled as devres in the following loop. This is safe.
  424. */
  425. list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) {
  426. devres_log(dev, &dr->node, "REL");
  427. dr->node.release(dev, dr->data);
  428. kfree(dr);
  429. }
  430. return cnt;
  431. }
  432. /**
  433. * devres_release_all - Release all managed resources
  434. * @dev: Device to release resources for
  435. *
  436. * Release all resources associated with @dev. This function is
  437. * called on driver detach.
  438. */
  439. int devres_release_all(struct device *dev)
  440. {
  441. unsigned long flags;
  442. /* Looks like an uninitialized device structure */
  443. if (WARN_ON(dev->devres_head.next == NULL))
  444. return -ENODEV;
  445. spin_lock_irqsave(&dev->devres_lock, flags);
  446. return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
  447. flags);
  448. }
  449. /**
  450. * devres_open_group - Open a new devres group
  451. * @dev: Device to open devres group for
  452. * @id: Separator ID
  453. * @gfp: Allocation flags
  454. *
  455. * Open a new devres group for @dev with @id. For @id, using a
  456. * pointer to an object which won't be used for another group is
  457. * recommended. If @id is NULL, address-wise unique ID is created.
  458. *
  459. * RETURNS:
  460. * ID of the new group, NULL on failure.
  461. */
  462. void * devres_open_group(struct device *dev, void *id, gfp_t gfp)
  463. {
  464. struct devres_group *grp;
  465. unsigned long flags;
  466. grp = kmalloc(sizeof(*grp), gfp);
  467. if (unlikely(!grp))
  468. return NULL;
  469. grp->node[0].release = &group_open_release;
  470. grp->node[1].release = &group_close_release;
  471. INIT_LIST_HEAD(&grp->node[0].entry);
  472. INIT_LIST_HEAD(&grp->node[1].entry);
  473. set_node_dbginfo(&grp->node[0], "grp<", 0);
  474. set_node_dbginfo(&grp->node[1], "grp>", 0);
  475. grp->id = grp;
  476. if (id)
  477. grp->id = id;
  478. spin_lock_irqsave(&dev->devres_lock, flags);
  479. add_dr(dev, &grp->node[0]);
  480. spin_unlock_irqrestore(&dev->devres_lock, flags);
  481. return grp->id;
  482. }
  483. EXPORT_SYMBOL_GPL(devres_open_group);
  484. /* Find devres group with ID @id. If @id is NULL, look for the latest. */
  485. static struct devres_group * find_group(struct device *dev, void *id)
  486. {
  487. struct devres_node *node;
  488. list_for_each_entry_reverse(node, &dev->devres_head, entry) {
  489. struct devres_group *grp;
  490. if (node->release != &group_open_release)
  491. continue;
  492. grp = container_of(node, struct devres_group, node[0]);
  493. if (id) {
  494. if (grp->id == id)
  495. return grp;
  496. } else if (list_empty(&grp->node[1].entry))
  497. return grp;
  498. }
  499. return NULL;
  500. }
  501. /**
  502. * devres_close_group - Close a devres group
  503. * @dev: Device to close devres group for
  504. * @id: ID of target group, can be NULL
  505. *
  506. * Close the group identified by @id. If @id is NULL, the latest open
  507. * group is selected.
  508. */
  509. void devres_close_group(struct device *dev, void *id)
  510. {
  511. struct devres_group *grp;
  512. unsigned long flags;
  513. spin_lock_irqsave(&dev->devres_lock, flags);
  514. grp = find_group(dev, id);
  515. if (grp)
  516. add_dr(dev, &grp->node[1]);
  517. else
  518. WARN_ON(1);
  519. spin_unlock_irqrestore(&dev->devres_lock, flags);
  520. }
  521. EXPORT_SYMBOL_GPL(devres_close_group);
  522. /**
  523. * devres_remove_group - Remove a devres group
  524. * @dev: Device to remove group for
  525. * @id: ID of target group, can be NULL
  526. *
  527. * Remove the group identified by @id. If @id is NULL, the latest
  528. * open group is selected. Note that removing a group doesn't affect
  529. * any other resources.
  530. */
  531. void devres_remove_group(struct device *dev, void *id)
  532. {
  533. struct devres_group *grp;
  534. unsigned long flags;
  535. spin_lock_irqsave(&dev->devres_lock, flags);
  536. grp = find_group(dev, id);
  537. if (grp) {
  538. list_del_init(&grp->node[0].entry);
  539. list_del_init(&grp->node[1].entry);
  540. devres_log(dev, &grp->node[0], "REM");
  541. } else
  542. WARN_ON(1);
  543. spin_unlock_irqrestore(&dev->devres_lock, flags);
  544. kfree(grp);
  545. }
  546. EXPORT_SYMBOL_GPL(devres_remove_group);
  547. /**
  548. * devres_release_group - Release resources in a devres group
  549. * @dev: Device to release group for
  550. * @id: ID of target group, can be NULL
  551. *
  552. * Release all resources in the group identified by @id. If @id is
  553. * NULL, the latest open group is selected. The selected group and
  554. * groups properly nested inside the selected group are removed.
  555. *
  556. * RETURNS:
  557. * The number of released non-group resources.
  558. */
  559. int devres_release_group(struct device *dev, void *id)
  560. {
  561. struct devres_group *grp;
  562. unsigned long flags;
  563. int cnt = 0;
  564. spin_lock_irqsave(&dev->devres_lock, flags);
  565. grp = find_group(dev, id);
  566. if (grp) {
  567. struct list_head *first = &grp->node[0].entry;
  568. struct list_head *end = &dev->devres_head;
  569. if (!list_empty(&grp->node[1].entry))
  570. end = grp->node[1].entry.next;
  571. cnt = release_nodes(dev, first, end, flags);
  572. } else {
  573. WARN_ON(1);
  574. spin_unlock_irqrestore(&dev->devres_lock, flags);
  575. }
  576. return cnt;
  577. }
  578. EXPORT_SYMBOL_GPL(devres_release_group);
  579. /*
  580. * Managed kzalloc/kfree
  581. */
  582. static void devm_kzalloc_release(struct device *dev, void *res)
  583. {
  584. /* noop */
  585. }
  586. static int devm_kzalloc_match(struct device *dev, void *res, void *data)
  587. {
  588. return res == data;
  589. }
  590. /**
  591. * devm_kzalloc - Resource-managed kzalloc
  592. * @dev: Device to allocate memory for
  593. * @size: Allocation size
  594. * @gfp: Allocation gfp flags
  595. *
  596. * Managed kzalloc. Memory allocated with this function is
  597. * automatically freed on driver detach. Like all other devres
  598. * resources, guaranteed alignment is unsigned long long.
  599. *
  600. * RETURNS:
  601. * Pointer to allocated memory on success, NULL on failure.
  602. */
  603. void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
  604. {
  605. struct devres *dr;
  606. /* use raw alloc_dr for kmalloc caller tracing */
  607. dr = alloc_dr(devm_kzalloc_release, size, gfp);
  608. if (unlikely(!dr))
  609. return NULL;
  610. set_node_dbginfo(&dr->node, "devm_kzalloc_release", size);
  611. devres_add(dev, dr->data);
  612. return dr->data;
  613. }
  614. EXPORT_SYMBOL_GPL(devm_kzalloc);
  615. /**
  616. * devm_kfree - Resource-managed kfree
  617. * @dev: Device this memory belongs to
  618. * @p: Memory to free
  619. *
  620. * Free memory allocated with devm_kzalloc().
  621. */
  622. void devm_kfree(struct device *dev, void *p)
  623. {
  624. int rc;
  625. rc = devres_destroy(dev, devm_kzalloc_release, devm_kzalloc_match, p);
  626. WARN_ON(rc);
  627. }
  628. EXPORT_SYMBOL_GPL(devm_kfree);