Commit 43a05a0d authored by Dan Williams's avatar Dan Williams Committed by Greg Kroah-Hartman

libnvdimm, pmem: fix kmap_atomic() leak in error path

commit b5ebc8ec upstream.

When we enounter a bad block we need to kunmap_atomic() before
returning.

Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Reviewed-by: default avatarVishal Verma <vishal.l.verma@intel.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 58fc850f
...@@ -66,22 +66,25 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page, ...@@ -66,22 +66,25 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
unsigned int len, unsigned int off, int rw, unsigned int len, unsigned int off, int rw,
sector_t sector) sector_t sector)
{ {
int rc = 0;
void *mem = kmap_atomic(page); void *mem = kmap_atomic(page);
phys_addr_t pmem_off = sector * 512 + pmem->data_offset; phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
void __pmem *pmem_addr = pmem->virt_addr + pmem_off; void __pmem *pmem_addr = pmem->virt_addr + pmem_off;
if (rw == READ) { if (rw == READ) {
if (unlikely(is_bad_pmem(&pmem->bb, sector, len))) if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
return -EIO; rc = -EIO;
memcpy_from_pmem(mem + off, pmem_addr, len); else {
flush_dcache_page(page); memcpy_from_pmem(mem + off, pmem_addr, len);
flush_dcache_page(page);
}
} else { } else {
flush_dcache_page(page); flush_dcache_page(page);
memcpy_to_pmem(pmem_addr, mem + off, len); memcpy_to_pmem(pmem_addr, mem + off, len);
} }
kunmap_atomic(mem); kunmap_atomic(mem);
return 0; return rc;
} }
static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio) static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment