Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c42c2710 authored by Brian Norris's avatar Brian Norris
Browse files

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: default avatarBrian Norris <computersforpeace@gmail.com>
Reviewed-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
parent 5531ae48
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -532,7 +532,7 @@ int del_mtd_device(struct mtd_info *mtd)
}

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,15 +589,11 @@ 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
		real_parts = parts;
		ret = nr_parts;
	}
	/* Didn't come up with either parsed OR fallback partitions */
@@ -628,6 +624,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
	}

out:
	/* Cleanup any parsed partitions */
	if (real_parts != parts)
		kfree(real_parts);
	return ret;
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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;