From: Nicholas Swenson <nks@daterainc.com>
Date: Fri, 1 Nov 2013 02:25:18 +0000 (-0700)
Subject: bcache: fix for gc crashing when no sectors are used
X-Git-Tag: firefly_0821_release~176^2~4719^2~8^2~4
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bee63f40cb5f5e8ab2abfbc85acde99cc0acd4b5;p=firefly-linux-kernel-4.4.55.git

bcache: fix for gc crashing when no sectors are used

Signed-off-by: Nicholas Swenson <nks@daterainc.com>
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
---

diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c
index 7c1275e66025..46c952379fab 100644
--- a/drivers/md/bcache/movinggc.c
+++ b/drivers/md/bcache/movinggc.c
@@ -184,7 +184,8 @@ static bool bucket_cmp(struct bucket *l, struct bucket *r)
 
 static unsigned bucket_heap_top(struct cache *ca)
 {
-	return GC_SECTORS_USED(heap_peek(&ca->heap));
+	struct bucket *b;
+	return (b = heap_peek(&ca->heap)) ? GC_SECTORS_USED(b) : 0;
 }
 
 void bch_moving_gc(struct cache_set *c)