From 19647d1cd44d029a8aa2f7e74dbdbd1f114a8c08 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 2 Feb 2018 14:34:45 +0000 Subject: [PATCH] [device/bcache] fix bug in _alloc_block --- lib/device/bcache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/device/bcache.c b/lib/device/bcache.c index 4283ce5cf..e5d0e1bae 100644 --- a/lib/device/bcache.c +++ b/lib/device/bcache.c @@ -449,8 +449,10 @@ static void _exit_free_list(struct bcache *cache) static struct block *_alloc_block(struct bcache *cache) { - struct block *b = dm_list_struct_base(_list_pop(&cache->free), struct block, list); - return b; + if (dm_list_empty(&cache->free)) + return NULL; + + return dm_list_struct_base(_list_pop(&cache->free), struct block, list); } /*----------------------------------------------------------------