Skip to content

Commit 4d523b6

Browse files
Jason Liudedekind
authored andcommitted
mtd: check parts pointer before using it
The code has the check for parts but it called after kmemdup, kmemdup(parts, sizeof(*parts) * nr_parts,...) if (!parts) return -ENOMEM In fact, we need check parts before safely using it. and we also need check the real_parts to make sure kmemdup allocation sucessfully. Signed-off-by: Jason Liu <jason.hui@linaro.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
1 parent e2e24e8 commit 4d523b6

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char **types,
465465
struct mtd_partition *real_parts;
466466

467467
err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
468-
if (err <= 0 && nr_parts) {
468+
if (err <= 0 && nr_parts && parts) {
469469
real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
470470
GFP_KERNEL);
471-
err = nr_parts;
472-
if (!parts)
471+
if (!real_parts)
473472
err = -ENOMEM;
473+
else
474+
err = nr_parts;
474475
}
475476

476477
if (err > 0) {

0 commit comments

Comments
 (0)