Skip to content

Commit 6dde1d6

Browse files
MatiasBjorlingaxboe
authored andcommitted
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: ca5927e "lightnvm: introduce mlc lower page table mappings" Signed-off-by: Matias Bjørling <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 3704e09 commit 6dde1d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/nvme/host/lightnvm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ struct nvme_nvm_command {
146146
};
147147
};
148148

149+
#define NVME_NVM_LP_MLC_PAIRS 886
149150
struct nvme_nvm_lp_mlc {
150151
__u16 num_pairs;
151-
__u8 pairs[886];
152+
__u8 pairs[NVME_NVM_LP_MLC_PAIRS];
152153
};
153154

154155
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)
282283
memcpy(dst->lptbl.id, src->lptbl.id, 8);
283284
dst->lptbl.mlc.num_pairs =
284285
le16_to_cpu(src->lptbl.mlc.num_pairs);
285-
/* 4 bits per pair */
286+
287+
if (dst->lptbl.mlc.num_pairs > NVME_NVM_LP_MLC_PAIRS) {
288+
pr_err("nvm: number of MLC pairs not supported\n");
289+
return -EINVAL;
290+
}
291+
286292
memcpy(dst->lptbl.mlc.pairs, src->lptbl.mlc.pairs,
287-
dst->lptbl.mlc.num_pairs >> 1);
293+
dst->lptbl.mlc.num_pairs);
288294
}
289295
}
290296

0 commit comments

Comments
 (0)