The patch titled Subject: idr: make idr_destroy() imply idr_remove_all() has been added to the -mm tree. Its filename is idr-make-idr_destroy-imply-idr_remove_all.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Tejun Heo <tj@xxxxxxxxxx> Subject: idr: make idr_destroy() imply idr_remove_all() idr is silly in quite a few ways, one of which is how it's supposed to be destroyed - idr_destroy() doesn't release IDs and doesn't even whine if the idr isn't empty. If the caller forgets idr_remove_all(), it simply leaks memory. Even ida gets this wrong and leaks memory on destruction. There is absoltely no reason not to call idr_remove_all() from idr_destroy(). Nobody is abusing idr_destroy() for shrinking free layer buffer and continues to use idr after idr_destroy(), so it's safe to do remove_all from destroy. In the whole kernel, there is only one place where idr_remove_all() is legitimiately used without following idr_destroy() while there are quite a few places where the caller forgets either idr_remove_all() or idr_destroy() leaking memory. This patch makes idr_destroy() call idr_destroy_all() and updates the function description accordingly. Signed-off-by: Tejun Heo <tj@xxxxxxxxxx> Cc: "J. Bruce Fields" <bfields@xxxxxxxxxxxx> Cc: Alasdair Kergon <agk@xxxxxxxxxx> Cc: Chas Williams <chas@xxxxxxxxxxxxxxxx> Cc: Christine Caulfield <ccaulfie@xxxxxxxxxx> Cc: David Airlie <airlied@xxxxxxxx> Cc: David Teigland <teigland@xxxxxxxxxx> Cc: Eric Paris <eparis@xxxxxxxxxxxxxx> Cc: Inki Dae <inki.dae@xxxxxxxxxxx> Cc: Jens Axboe <axboe@xxxxxxxxx> Cc: John McCutchan <john@xxxxxxxxxxxxxxxxx> Cc: Joonyoung Shim <jy0922.shim@xxxxxxxxxxx> Cc: Kyungmin Park <kyungmin.park@xxxxxxxxxxx> Cc: Li Zefan <lizefan@xxxxxxxxxx> Cc: Ohad Ben-Cohen <ohad@xxxxxxxxxx> Cc: Robert Love <rlove@xxxxxxxxx> Cc: Seung-Woo Kim <sw0312.kim@xxxxxxxxxxx> Cc: Stefan Richter <stefanr@xxxxxxxxxxxxxxxxx> Cc: Tejun Heo <tj@xxxxxxxxxx> Cc: Arnd Bergmann <arnd@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/idr.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff -puN lib/idr.c~idr-make-idr_destroy-imply-idr_remove_all lib/idr.c --- a/lib/idr.c~idr-make-idr_destroy-imply-idr_remove_all +++ a/lib/idr.c @@ -436,15 +436,6 @@ EXPORT_SYMBOL(idr_remove); /** * idr_remove_all - remove all ids from the given idr tree * @idp: idr handle - * - * idr_destroy() only frees up unused, cached idp_layers, but this - * function will remove all id mappings and leave all idp_layers - * unused. - * - * A typical clean-up sequence for objects stored in an idr tree will - * use idr_for_each() to free all objects, if necessay, then - * idr_remove_all() to remove all ids, and idr_destroy() to free - * up the cached idr_layers. */ void idr_remove_all(struct idr *idp) { @@ -484,9 +475,20 @@ EXPORT_SYMBOL(idr_remove_all); /** * idr_destroy - release all cached layers within an idr tree * @idp: idr handle + * + * Free all id mappings and all idp_layers. After this function, @idp is + * completely unused and can be freed / recycled. The caller is + * responsible for ensuring that no one else accesses @idp during or after + * idr_destroy(). + * + * A typical clean-up sequence for objects stored in an idr tree will use + * idr_for_each() to free all objects, if necessay, then idr_destroy() to + * free up the id mappings and cached idr_layers. */ void idr_destroy(struct idr *idp) { + idr_remove_all(idp); + while (idp->id_free_cnt) { struct idr_layer *p = get_from_free_list(idp); kmem_cache_free(idr_layer_cache, p); _ Patches currently in -mm which might be from tj@xxxxxxxxxx are linux-next.patch cfq-fix-lock-imbalance-with-failed-allocations.patch block-restore-proc-partitions-to-not-display-non-partitionable-removable-devices.patch memcg-do-not-create-memsw-files-if-swap-accounting-is-disabled.patch memcg-clean-up-swap-accounting-initialization-code.patch memcg-prevent-changes-to-move_charge_at_immigrate-during-task-attach.patch memcg-split-part-of-memcg-creation-to-css_online.patch memcg-fast-hierarchy-aware-child-test.patch memcg-fast-hierarchy-aware-child-test-fix.patch memcg-replace-cgroup_lock-with-memcg-specific-memcg_lock.patch memcg-increment-static-branch-right-after-limit-set.patch memcg-avoid-dangling-reference-count-in-creation-failure.patch idr-make-idr_destroy-imply-idr_remove_all.patch atm-nicstar-dont-use-idr_remove_all.patch block-loop-dont-use-idr_remove_all.patch firewire-dont-use-idr_remove_all.patch drm-dont-use-idr_remove_all.patch dm-dont-use-idr_remove_all.patch remoteproc-dont-use-idr_remove_all.patch rpmsg-dont-use-idr_remove_all.patch dlm-use-idr_for_each_entry-in-recover_idr_clear-error-path.patch dlm-dont-use-idr_remove_all.patch nfs-idr_destroy-no-longer-needs-idr_remove_all.patch inotify-dont-use-idr_remove_all.patch cgroup-dont-use-idr_remove_all.patch idr-deprecate-idr_remove_all.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html