diff options
author | Brian Norris <computersforpeace@gmail.com> | 2015-12-04 18:25:16 -0500 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2015-12-09 13:22:06 -0500 |
commit | c42c2710d64381fd48d36b278e0744aa683d93fe (patch) | |
tree | ec4f9032ebeb7ff4b28bd064c2683bd359143da1 | |
parent | 5531ae4818fb04b9a30f87099f44595c1786f518 (diff) |
mtd: partitions: remove kmemdup()
The use of kmemdup() complicates the error handling a bit. We don't
actually need to allocate new memory, since this reference is treated as
const, and it is copied into new memory by the partition registration
code anyway. So remove it.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
-rw-r--r-- | drivers/mtd/mtdcore.c | 16 | ||||
-rw-r--r-- | drivers/mtd/mtdcore.h | 2 | ||||
-rw-r--r-- | drivers/mtd/mtdpart.c | 2 |
3 files changed, 9 insertions, 11 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 62f83b050978..868ee52d5063 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -532,7 +532,7 @@ out_error: | |||
532 | } | 532 | } |
533 | 533 | ||
534 | static int mtd_add_device_partitions(struct mtd_info *mtd, | 534 | static int mtd_add_device_partitions(struct mtd_info *mtd, |
535 | struct mtd_partition *real_parts, | 535 | const struct mtd_partition *real_parts, |
536 | int nbparts) | 536 | int nbparts) |
537 | { | 537 | { |
538 | int ret; | 538 | int ret; |
@@ -589,16 +589,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, | |||
589 | int nr_parts) | 589 | int nr_parts) |
590 | { | 590 | { |
591 | int ret; | 591 | int ret; |
592 | struct mtd_partition *real_parts = NULL; | 592 | const struct mtd_partition *real_parts = NULL; |
593 | 593 | ||
594 | ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); | 594 | ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); |
595 | if (ret <= 0 && nr_parts && parts) { | 595 | if (ret <= 0 && nr_parts && parts) { |
596 | real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, | 596 | real_parts = parts; |
597 | GFP_KERNEL); | 597 | ret = nr_parts; |
598 | if (!real_parts) | ||
599 | ret = -ENOMEM; | ||
600 | else | ||
601 | ret = nr_parts; | ||
602 | } | 598 | } |
603 | /* Didn't come up with either parsed OR fallback partitions */ | 599 | /* Didn't come up with either parsed OR fallback partitions */ |
604 | if (ret < 0) { | 600 | if (ret < 0) { |
@@ -628,7 +624,9 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, | |||
628 | } | 624 | } |
629 | 625 | ||
630 | out: | 626 | out: |
631 | kfree(real_parts); | 627 | /* Cleanup any parsed partitions */ |
628 | if (real_parts != parts) | ||
629 | kfree(real_parts); | ||
632 | return ret; | 630 | return ret; |
633 | } | 631 | } |
634 | EXPORT_SYMBOL_GPL(mtd_device_parse_register); | 632 | EXPORT_SYMBOL_GPL(mtd_device_parse_register); |
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h index 7b0353399a10..537ec66f9cfd 100644 --- a/drivers/mtd/mtdcore.h +++ b/drivers/mtd/mtdcore.h | |||
@@ -11,7 +11,7 @@ int del_mtd_device(struct mtd_info *mtd); | |||
11 | int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int); | 11 | int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int); |
12 | int del_mtd_partitions(struct mtd_info *); | 12 | int del_mtd_partitions(struct mtd_info *); |
13 | int parse_mtd_partitions(struct mtd_info *master, const char * const *types, | 13 | int parse_mtd_partitions(struct mtd_info *master, const char * const *types, |
14 | struct mtd_partition **pparts, | 14 | const struct mtd_partition **pparts, |
15 | struct mtd_part_parser_data *data); | 15 | struct mtd_part_parser_data *data); |
16 | 16 | ||
17 | int __init init_mtdchar(void); | 17 | int __init init_mtdchar(void); |
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 4a660ae27bb2..898999c5aea1 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c | |||
@@ -760,7 +760,7 @@ static const char * const default_mtd_part_types[] = { | |||
760 | * point to an array containing this number of &struct mtd_info objects. | 760 | * point to an array containing this number of &struct mtd_info objects. |
761 | */ | 761 | */ |
762 | int parse_mtd_partitions(struct mtd_info *master, const char *const *types, | 762 | int parse_mtd_partitions(struct mtd_info *master, const char *const *types, |
763 | struct mtd_partition **pparts, | 763 | const struct mtd_partition **pparts, |
764 | struct mtd_part_parser_data *data) | 764 | struct mtd_part_parser_data *data) |
765 | { | 765 | { |
766 | struct mtd_part_parser *parser; | 766 | struct mtd_part_parser *parser; |