]> Pileus Git - ~andy/linux/blobdiff - block/blk-ioc.c
block: fix ioc leak in put_io_context
[~andy/linux] / block / blk-ioc.c
index 92bf55540d87b25f6a73e5d115e7e76431831103..fb95dd2f889a6071d85e334d7d5d9342ca56ab75 100644 (file)
@@ -130,6 +130,7 @@ static void ioc_release_fn(struct work_struct *work)
 void put_io_context(struct io_context *ioc)
 {
        unsigned long flags;
+       bool free_ioc = false;
 
        if (ioc == NULL)
                return;
@@ -144,8 +145,13 @@ void put_io_context(struct io_context *ioc)
                spin_lock_irqsave(&ioc->lock, flags);
                if (!hlist_empty(&ioc->icq_list))
                        schedule_work(&ioc->release_work);
+               else
+                       free_ioc = true;
                spin_unlock_irqrestore(&ioc->lock, flags);
        }
+
+       if (free_ioc)
+               kmem_cache_free(iocontext_cachep, ioc);
 }
 EXPORT_SYMBOL(put_io_context);