summaryrefslogtreecommitdiff
path: root/drivers/nvdimm/claim.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2016-12-16 19:10:31 +0300
committerDan Williams <dan.j.williams@intel.com>2016-12-16 19:10:31 +0300
commit868f036fee4b1f934117197fb93461d2c968ffec (patch)
tree2ccd2f941f1a6321d15d0c6c948fd527ebeae469 /drivers/nvdimm/claim.c
parent9cf8bd529c6ba81402ebf6b7a56307b0787e4f93 (diff)
downloadlinux-868f036fee4b1f934117197fb93461d2c968ffec.tar.xz
libnvdimm: fix mishandled nvdimm_clear_poison() return value
Colin, via static analysis, reports that the length could be negative from nvdimm_clear_poison() in the error case. There was a similar problem with commit 0a3f27b9a6a8 "libnvdimm, namespace: avoid multiple sector calculations" that I noticed when merging the for-4.10/libnvdimm topic branch into libnvdimm-for-next, but I missed this one. Fix both of them to the following procedure: * if we clear a block's worth of media, clear that many blocks in badblocks * if we clear less than the requested size of the transfer return an error * always invalidate cache after any non-error / non-zero nvdimm_clear_poison result Fixes: 82bf1037f2ca ("libnvdimm: check and clear poison before writing to pmem") Fixes: 0a3f27b9a6a8 ("libnvdimm, namespace: avoid multiple sector calculations") Cc: Fabian Frederick <fabf@skynet.be> Cc: Dave Jiang <dave.jiang@intel.com> Reported-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/nvdimm/claim.c')
-rw-r--r--drivers/nvdimm/claim.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
index 97d1772774a8..b3323c0697f6 100644
--- a/drivers/nvdimm/claim.c
+++ b/drivers/nvdimm/claim.c
@@ -247,12 +247,13 @@ static int nsio_rw_bytes(struct nd_namespace_common *ndns,
long cleared;
cleared = nvdimm_clear_poison(&ndns->dev, offset, size);
- if (cleared != size) {
- size = cleared;
+ if (cleared < size)
rc = -EIO;
+ if (cleared > 0 && cleared / 512) {
+ cleared /= 512;
+ badblocks_clear(&nsio->bb, sector, cleared);
}
-
- badblocks_clear(&nsio->bb, sector, cleared >> 9);
+ invalidate_pmem(nsio->addr + offset, size);
} else
rc = -EIO;
}