Skip to content

Commit

Permalink
block: missing bio_put following submit_bio_wait
Browse files Browse the repository at this point in the history
submit_bio_wait() gives the caller an opportunity to examine
struct bio and so expects the caller to issue the put_bio()

This fixes a memory leak reported by a few people in 4.7-rc2
kmemleak report after 9082e87 ("block: remove struct bio_batch")

Signed-off-by: Shaun Tancheff <[email protected]>
Tested-by: Catalin Marinas <[email protected]>
Tested-by: Larry [email protected]
Tested-by: David Drysdale <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
stancheff authored and axboe committed Jun 7, 2016
1 parent 87c279e commit 05bd92d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions block/blk-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
ret = submit_bio_wait(type, bio);
if (ret == -EOPNOTSUPP)
ret = 0;
bio_put(bio);
}
blk_finish_plug(&plug);

Expand Down Expand Up @@ -165,8 +166,10 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
}
}

if (bio)
if (bio) {
ret = submit_bio_wait(REQ_WRITE | REQ_WRITE_SAME, bio);
bio_put(bio);
}
return ret != -EOPNOTSUPP ? ret : 0;
}
EXPORT_SYMBOL(blkdev_issue_write_same);
Expand Down Expand Up @@ -206,8 +209,11 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
}
}

if (bio)
return submit_bio_wait(WRITE, bio);
if (bio) {
ret = submit_bio_wait(WRITE, bio);
bio_put(bio);
return ret;
}
return 0;
}

Expand Down

0 comments on commit 05bd92d

Please sign in to comment.