Skip to content

Commit

Permalink
dm cache: handle kmalloc failure allocating background_tracker struct
Browse files Browse the repository at this point in the history
Currently there is no kmalloc failure check on the allocation of
the background_tracker struct in btracker_create(), and so a NULL return
will lead to a NULL pointer dereference.  Add a NULL check.

Detected by CoverityScan, CID#1416587 ("Dereference null return value")

Fixes: b29d498 ("dm cache: significant rework to leverage dm-bio-prison-v2")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Colin Ian King authored and snitm committed May 17, 2017
1 parent 13840d3 commit 7e1b952
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/md/dm-cache-background-tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct background_tracker *btracker_create(unsigned max_work)
{
struct background_tracker *b = kmalloc(sizeof(*b), GFP_KERNEL);

if (!b) {
DMERR("couldn't create background_tracker");
return NULL;
}

b->max_work = max_work;
atomic_set(&b->pending_promotes, 0);
atomic_set(&b->pending_writebacks, 0);
Expand Down

0 comments on commit 7e1b952

Please sign in to comment.