Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756800AbcDJSiN (ORCPT ); Sun, 10 Apr 2016 14:38:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51700 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756586AbcDJSiF (ORCPT ); Sun, 10 Apr 2016 14:38:05 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ross Zwisler , Vishal Verma , Dan Williams Subject: [PATCH 4.5 048/238] libnvdimm, pmem: fix kmap_atomic() leak in error path Date: Sun, 10 Apr 2016 11:33:45 -0700 Message-Id: <20160410183458.983901824@linuxfoundation.org> X-Mailer: git-send-email 2.8.0 In-Reply-To: <20160410183456.398741366@linuxfoundation.org> References: <20160410183456.398741366@linuxfoundation.org> User-Agent: quilt/0.64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1442 Lines: 53 4.5-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit b5ebc8ec693281c3c1efff7459a069cbd8b9a149 upstream. When we enounter a bad block we need to kunmap_atomic() before returning. Cc: Ross Zwisler Reviewed-by: Vishal Verma Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/pmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -66,22 +66,25 @@ static int pmem_do_bvec(struct pmem_devi unsigned int len, unsigned int off, int rw, sector_t sector) { + int rc = 0; void *mem = kmap_atomic(page); phys_addr_t pmem_off = sector * 512 + pmem->data_offset; void __pmem *pmem_addr = pmem->virt_addr + pmem_off; if (rw == READ) { if (unlikely(is_bad_pmem(&pmem->bb, sector, len))) - return -EIO; - memcpy_from_pmem(mem + off, pmem_addr, len); - flush_dcache_page(page); + rc = -EIO; + else { + memcpy_from_pmem(mem + off, pmem_addr, len); + flush_dcache_page(page); + } } else { flush_dcache_page(page); memcpy_to_pmem(pmem_addr, mem + off, len); } kunmap_atomic(mem); - return 0; + return rc; } static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)