summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2015-12-04 15:25:16 -0800
committerBrian Norris <computersforpeace@gmail.com>2015-12-09 10:22:06 -0800
commitc42c2710d64381fd48d36b278e0744aa683d93fe (patch)
treeec4f9032ebeb7ff4b28bd064c2683bd359143da1 /drivers/mtd/mtdcore.c
parent5531ae4818fb04b9a30f87099f44595c1786f518 (diff)
downloadlinux-stable-c42c2710d64381fd48d36b278e0744aa683d93fe.tar.gz
linux-stable-c42c2710d64381fd48d36b278e0744aa683d93fe.tar.bz2
linux-stable-c42c2710d64381fd48d36b278e0744aa683d93fe.zip
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>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c16
1 files changed, 7 insertions, 9 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:
}
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);