devres.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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_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_dr = NULL;
  265. }
  266. spin_unlock_irqrestore(&dev->devres_lock, flags);
  267. devres_free(new_dr);
  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. * Note that the release function for the resource will not be called,
  315. * only the devres-allocated data will be freed. The caller becomes
  316. * responsible for freeing any other data.
  317. *
  318. * RETURNS:
  319. * 0 if devres is found and freed, -ENOENT if not found.
  320. */
  321. int devres_destroy(struct device *dev, dr_release_t release,
  322. dr_match_t match, void *match_data)
  323. {
  324. void *res;
  325. res = devres_remove(dev, release, match, match_data);
  326. if (unlikely(!res))
  327. return -ENOENT;
  328. devres_free(res);
  329. return 0;
  330. }
  331. EXPORT_SYMBOL_GPL(devres_destroy);
  332. /**
  333. * devres_release - Find a device resource and destroy it, calling release
  334. * @dev: Device to find resource from
  335. * @release: Look for resources associated with this release function
  336. * @match: Match function (optional)
  337. * @match_data: Data for the match function
  338. *
  339. * Find the latest devres of @dev associated with @release and for
  340. * which @match returns 1. If @match is NULL, it's considered to
  341. * match all. If found, the resource is removed atomically, the
  342. * release function called and the resource freed.
  343. *
  344. * RETURNS:
  345. * 0 if devres is found and freed, -ENOENT if not found.
  346. */
  347. int devres_release(struct device *dev, dr_release_t release,
  348. dr_match_t match, void *match_data)
  349. {
  350. void *res;
  351. res = devres_remove(dev, release, match, match_data);
  352. if (unlikely(!res))
  353. return -ENOENT;
  354. (*release)(dev, res);
  355. devres_free(res);
  356. return 0;
  357. }
  358. EXPORT_SYMBOL_GPL(devres_release);
  359. static int remove_nodes(struct device *dev,
  360. struct list_head *first, struct list_head *end,
  361. struct list_head *todo)
  362. {
  363. int cnt = 0, nr_groups = 0;
  364. struct list_head *cur;
  365. /* First pass - move normal devres entries to @todo and clear
  366. * devres_group colors.
  367. */
  368. cur = first;
  369. while (cur != end) {
  370. struct devres_node *node;
  371. struct devres_group *grp;
  372. node = list_entry(cur, struct devres_node, entry);
  373. cur = cur->next;
  374. grp = node_to_group(node);
  375. if (grp) {
  376. /* clear color of group markers in the first pass */
  377. grp->color = 0;
  378. nr_groups++;
  379. } else {
  380. /* regular devres entry */
  381. if (&node->entry == first)
  382. first = first->next;
  383. list_move_tail(&node->entry, todo);
  384. cnt++;
  385. }
  386. }
  387. if (!nr_groups)
  388. return cnt;
  389. /* Second pass - Scan groups and color them. A group gets
  390. * color value of two iff the group is wholly contained in
  391. * [cur, end). That is, for a closed group, both opening and
  392. * closing markers should be in the range, while just the
  393. * opening marker is enough for an open group.
  394. */
  395. cur = first;
  396. while (cur != end) {
  397. struct devres_node *node;
  398. struct devres_group *grp;
  399. node = list_entry(cur, struct devres_node, entry);
  400. cur = cur->next;
  401. grp = node_to_group(node);
  402. BUG_ON(!grp || list_empty(&grp->node[0].entry));
  403. grp->color++;
  404. if (list_empty(&grp->node[1].entry))
  405. grp->color++;
  406. BUG_ON(grp->color <= 0 || grp->color > 2);
  407. if (grp->color == 2) {
  408. /* No need to update cur or end. The removed
  409. * nodes are always before both.
  410. */
  411. list_move_tail(&grp->node[0].entry, todo);
  412. list_del_init(&grp->node[1].entry);
  413. }
  414. }
  415. return cnt;
  416. }
  417. static int release_nodes(struct device *dev, struct list_head *first,
  418. struct list_head *end, unsigned long flags)
  419. __releases(&dev->devres_lock)
  420. {
  421. LIST_HEAD(todo);
  422. int cnt;
  423. struct devres *dr, *tmp;
  424. cnt = remove_nodes(dev, first, end, &todo);
  425. spin_unlock_irqrestore(&dev->devres_lock, flags);
  426. /* Release. Note that both devres and devres_group are
  427. * handled as devres in the following loop. This is safe.
  428. */
  429. list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) {
  430. devres_log(dev, &dr->node, "REL");
  431. dr->node.release(dev, dr->data);
  432. kfree(dr);
  433. }
  434. return cnt;
  435. }
  436. /**
  437. * devres_release_all - Release all managed resources
  438. * @dev: Device to release resources for
  439. *
  440. * Release all resources associated with @dev. This function is
  441. * called on driver detach.
  442. */
  443. int devres_release_all(struct device *dev)
  444. {
  445. unsigned long flags;
  446. /* Looks like an uninitialized device structure */
  447. if (WARN_ON(dev->devres_head.next == NULL))
  448. return -ENODEV;
  449. spin_lock_irqsave(&dev->devres_lock, flags);
  450. return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
  451. flags);
  452. }
  453. /**
  454. * devres_open_group - Open a new devres group
  455. * @dev: Device to open devres group for
  456. * @id: Separator ID
  457. * @gfp: Allocation flags
  458. *
  459. * Open a new devres group for @dev with @id. For @id, using a
  460. * pointer to an object which won't be used for another group is
  461. * recommended. If @id is NULL, address-wise unique ID is created.
  462. *
  463. * RETURNS:
  464. * ID of the new group, NULL on failure.
  465. */
  466. void * devres_open_group(struct device *dev, void *id, gfp_t gfp)
  467. {
  468. struct devres_group *grp;
  469. unsigned long flags;
  470. grp = kmalloc(sizeof(*grp), gfp);
  471. if (unlikely(!grp))
  472. return NULL;
  473. grp->node[0].release = &group_open_release;
  474. grp->node[1].release = &group_close_release;
  475. INIT_LIST_HEAD(&grp->node[0].entry);
  476. INIT_LIST_HEAD(&grp->node[1].entry);
  477. set_node_dbginfo(&grp->node[0], "grp<", 0);
  478. set_node_dbginfo(&grp->node[1], "grp>", 0);
  479. grp->id = grp;
  480. if (id)
  481. grp->id = id;
  482. spin_lock_irqsave(&dev->devres_lock, flags);
  483. add_dr(dev, &grp->node[0]);
  484. spin_unlock_irqrestore(&dev->devres_lock, flags);
  485. return grp->id;
  486. }
  487. EXPORT_SYMBOL_GPL(devres_open_group);
  488. /* Find devres group with ID @id. If @id is NULL, look for the latest. */
  489. static struct devres_group * find_group(struct device *dev, void *id)
  490. {
  491. struct devres_node *node;
  492. list_for_each_entry_reverse(node, &dev->devres_head, entry) {
  493. struct devres_group *grp;
  494. if (node->release != &group_open_release)
  495. continue;
  496. grp = container_of(node, struct devres_group, node[0]);
  497. if (id) {
  498. if (grp->id == id)
  499. return grp;
  500. } else if (list_empty(&grp->node[1].entry))
  501. return grp;
  502. }
  503. return NULL;
  504. }
  505. /**
  506. * devres_close_group - Close a devres group
  507. * @dev: Device to close devres group for
  508. * @id: ID of target group, can be NULL
  509. *
  510. * Close the group identified by @id. If @id is NULL, the latest open
  511. * group is selected.
  512. */
  513. void devres_close_group(struct device *dev, void *id)
  514. {
  515. struct devres_group *grp;
  516. unsigned long flags;
  517. spin_lock_irqsave(&dev->devres_lock, flags);
  518. grp = find_group(dev, id);
  519. if (grp)
  520. add_dr(dev, &grp->node[1]);
  521. else
  522. WARN_ON(1);
  523. spin_unlock_irqrestore(&dev->devres_lock, flags);
  524. }
  525. EXPORT_SYMBOL_GPL(devres_close_group);
  526. /**
  527. * devres_remove_group - Remove a devres group
  528. * @dev: Device to remove group for
  529. * @id: ID of target group, can be NULL
  530. *
  531. * Remove the group identified by @id. If @id is NULL, the latest
  532. * open group is selected. Note that removing a group doesn't affect
  533. * any other resources.
  534. */
  535. void devres_remove_group(struct device *dev, void *id)
  536. {
  537. struct devres_group *grp;
  538. unsigned long flags;
  539. spin_lock_irqsave(&dev->devres_lock, flags);
  540. grp = find_group(dev, id);
  541. if (grp) {
  542. list_del_init(&grp->node[0].entry);
  543. list_del_init(&grp->node[1].entry);
  544. devres_log(dev, &grp->node[0], "REM");
  545. } else
  546. WARN_ON(1);
  547. spin_unlock_irqrestore(&dev->devres_lock, flags);
  548. kfree(grp);
  549. }
  550. EXPORT_SYMBOL_GPL(devres_remove_group);
  551. /**
  552. * devres_release_group - Release resources in a devres group
  553. * @dev: Device to release group for
  554. * @id: ID of target group, can be NULL
  555. *
  556. * Release all resources in the group identified by @id. If @id is
  557. * NULL, the latest open group is selected. The selected group and
  558. * groups properly nested inside the selected group are removed.
  559. *
  560. * RETURNS:
  561. * The number of released non-group resources.
  562. */
  563. int devres_release_group(struct device *dev, void *id)
  564. {
  565. struct devres_group *grp;
  566. unsigned long flags;
  567. int cnt = 0;
  568. spin_lock_irqsave(&dev->devres_lock, flags);
  569. grp = find_group(dev, id);
  570. if (grp) {
  571. struct list_head *first = &grp->node[0].entry;
  572. struct list_head *end = &dev->devres_head;
  573. if (!list_empty(&grp->node[1].entry))
  574. end = grp->node[1].entry.next;
  575. cnt = release_nodes(dev, first, end, flags);
  576. } else {
  577. WARN_ON(1);
  578. spin_unlock_irqrestore(&dev->devres_lock, flags);
  579. }
  580. return cnt;
  581. }
  582. EXPORT_SYMBOL_GPL(devres_release_group);
  583. /*
  584. * Managed kzalloc/kfree
  585. */
  586. static void devm_kzalloc_release(struct device *dev, void *res)
  587. {
  588. /* noop */
  589. }
  590. static int devm_kzalloc_match(struct device *dev, void *res, void *data)
  591. {
  592. return res == data;
  593. }
  594. /**
  595. * devm_kzalloc - Resource-managed kzalloc
  596. * @dev: Device to allocate memory for
  597. * @size: Allocation size
  598. * @gfp: Allocation gfp flags
  599. *
  600. * Managed kzalloc. Memory allocated with this function is
  601. * automatically freed on driver detach. Like all other devres
  602. * resources, guaranteed alignment is unsigned long long.
  603. *
  604. * RETURNS:
  605. * Pointer to allocated memory on success, NULL on failure.
  606. */
  607. void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
  608. {
  609. struct devres *dr;
  610. /* use raw alloc_dr for kmalloc caller tracing */
  611. dr = alloc_dr(devm_kzalloc_release, size, gfp);
  612. if (unlikely(!dr))
  613. return NULL;
  614. set_node_dbginfo(&dr->node, "devm_kzalloc_release", size);
  615. devres_add(dev, dr->data);
  616. return dr->data;
  617. }
  618. EXPORT_SYMBOL_GPL(devm_kzalloc);
  619. /**
  620. * devm_kfree - Resource-managed kfree
  621. * @dev: Device this memory belongs to
  622. * @p: Memory to free
  623. *
  624. * Free memory allocated with devm_kzalloc().
  625. */
  626. void devm_kfree(struct device *dev, void *p)
  627. {
  628. int rc;
  629. rc = devres_destroy(dev, devm_kzalloc_release, devm_kzalloc_match, p);
  630. WARN_ON(rc);
  631. }
  632. EXPORT_SYMBOL_GPL(devm_kfree);