Commit 8d3b3591 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] inotify/idr leak fix

Fix a bug which was reported and diagnosed by
Stefan Jones <>

IDR trees include a cache of idr_layer objects.  There's no way to destroy
this cache, so when we discard an overall idr tree we end up leaking some

Add and use idr_destroy() for this.  v9fs and infiniband also need to use
idr_destroy() to avoid leaks.

Or, we make the cache global, like radix_tree_preload().  Which is probably
better.  Later.

Cc: Eric Van Hensbergen <>
Cc: Roland Dreier <>
Cc: Robert Love <>
Cc: John McCutchan <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent c0fef676
......@@ -176,6 +176,7 @@ static inline void put_inotify_dev(struct inotify_device *dev)
if (atomic_dec_and_test(&dev->count)) {
......@@ -75,4 +75,5 @@ int idr_pre_get(struct idr *idp, unsigned gfp_mask);
int idr_get_new(struct idr *idp, void *ptr, int *id);
int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id);
void idr_remove(struct idr *idp, int id);
void idr_destroy(struct idr *idp);
void idr_init(struct idr *idp);
......@@ -345,6 +345,19 @@ void idr_remove(struct idr *idp, int id)
* idr_destroy - release all cached layers within an idr tree
* idp: idr handle
void idr_destroy(struct idr *idp)
while (idp->id_free_cnt) {
struct idr_layer *p = alloc_layer(idp);
kmem_cache_free(idr_layer_cache, p);
* idr_find - return pointer for given id
* @idp: idr handle
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment