]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
mtd: partitions: remove kmemdup()
authorBrian Norris <computersforpeace@gmail.com>
Fri, 4 Dec 2015 23:25:16 +0000 (15:25 -0800)
committerBrian Norris <computersforpeace@gmail.com>
Wed, 9 Dec 2015 18:22:06 +0000 (10:22 -0800)
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>
drivers/mtd/mtdcore.c
drivers/mtd/mtdcore.h
drivers/mtd/mtdpart.c

index 62f83b05097843806dbe1965713882db07c360ec..868ee52d5063b1eee4245ae34058c721d43c5df1 100644 (file)
@@ -532,7 +532,7 @@ out_error:
 }
 
 static int mtd_add_device_partitions(struct mtd_info *mtd,
-                                    struct mtd_partition *real_parts,
+                                    const struct mtd_partition *real_parts,
                                     int nbparts)
 {
        int ret;
@@ -589,16 +589,12 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
                              int nr_parts)
 {
        int ret;
-       struct mtd_partition *real_parts = NULL;
+       const struct mtd_partition *real_parts = NULL;
 
        ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
        if (ret <= 0 && nr_parts && parts) {
-               real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
-                                    GFP_KERNEL);
-               if (!real_parts)
-                       ret = -ENOMEM;
-               else
-                       ret = nr_parts;
+               real_parts = parts;
+               ret = nr_parts;
        }
        /* Didn't come up with either parsed OR fallback partitions */
        if (ret < 0) {
@@ -628,7 +624,9 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
        }
 
 out:
-       kfree(real_parts);
+       /* Cleanup any parsed partitions */
+       if (real_parts != parts)
+               kfree(real_parts);
        return ret;
 }
 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
index 7b0353399a10642f44ca4d15994942066693e9b2..537ec66f9cfd8338b0149ec9215c07b47a31d82c 100644 (file)
@@ -11,7 +11,7 @@ int del_mtd_device(struct mtd_info *mtd);
 int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
 int del_mtd_partitions(struct mtd_info *);
 int parse_mtd_partitions(struct mtd_info *master, const char * const *types,
-                        struct mtd_partition **pparts,
+                        const struct mtd_partition **pparts,
                         struct mtd_part_parser_data *data);
 
 int __init init_mtdchar(void);
index 4a660ae27bb2e2f2c7abd3c08b6dfc143e354876..898999c5aea16987883c2641021c63b1fbde1f2d 100644 (file)
@@ -760,7 +760,7 @@ static const char * const default_mtd_part_types[] = {
  *   point to an array containing this number of &struct mtd_info objects.
  */
 int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
-                        struct mtd_partition **pparts,
+                        const struct mtd_partition **pparts,
                         struct mtd_part_parser_data *data)
 {
        struct mtd_part_parser *parser;