summaryrefslogtreecommitdiffstats
path: root/drivers/nvme/host/lightnvm.c
diff options
context:
space:
mode:
authorMatias Bjørling2016-02-04 15:13:26 +0100
committerJens Axboe2016-02-04 17:19:45 +0100
commit6dde1d6c9094a7c20a680aa2196ad6d032ec7ded (patch)
treefca58d9144d6b47691e40f4f05051be5e24682c9 /drivers/nvme/host/lightnvm.c
parentlightnvm: fix request intersection locking in rrpc (diff)
downloadkernel-qcow2-linux-6dde1d6c9094a7c20a680aa2196ad6d032ec7ded.tar.gz
kernel-qcow2-linux-6dde1d6c9094a7c20a680aa2196ad6d032ec7ded.tar.xz
kernel-qcow2-linux-6dde1d6c9094a7c20a680aa2196ad6d032ec7ded.zip
lightnvm: check overflow and correct mlc pairs
The specification currently limits the number of MLC pairs to 886. Make sure that a device is unable to be instantiate if more is configured. Also, previously the patch had the wrong math for copying MLC pairs, as it only copied half of the actual entries. Fixes: ca5927e7ab53 "lightnvm: introduce mlc lower page table mappings" Signed-off-by: Matias Bjørling <m@bjorling.me> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/nvme/host/lightnvm.c')
-rw-r--r--drivers/nvme/host/lightnvm.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index 5cd3725e2fa4..6bb15e4926dc 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -146,9 +146,10 @@ struct nvme_nvm_command {
};
};
+#define NVME_NVM_LP_MLC_PAIRS 886
struct nvme_nvm_lp_mlc {
__u16 num_pairs;
- __u8 pairs[886];
+ __u8 pairs[NVME_NVM_LP_MLC_PAIRS];
};
struct nvme_nvm_lp_tbl {
@@ -282,9 +283,14 @@ static int init_grps(struct nvm_id *nvm_id, struct nvme_nvm_id *nvme_nvm_id)
memcpy(dst->lptbl.id, src->lptbl.id, 8);
dst->lptbl.mlc.num_pairs =
le16_to_cpu(src->lptbl.mlc.num_pairs);
- /* 4 bits per pair */
+
+ if (dst->lptbl.mlc.num_pairs > NVME_NVM_LP_MLC_PAIRS) {
+ pr_err("nvm: number of MLC pairs not supported\n");
+ return -EINVAL;
+ }
+
memcpy(dst->lptbl.mlc.pairs, src->lptbl.mlc.pairs,
- dst->lptbl.mlc.num_pairs >> 1);
+ dst->lptbl.mlc.num_pairs);
}
}