mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
mtd: get rid of the mtd_add_device_partitions()
This simplifies code a bit by: 1) Avoiding an extra (tiny) function 2) Checking for amount of parsed (found) partitions just once 3) Avoiding clearing/filling struct mtd_partitions manually With this commit proper functions are called directly from the mtd_device_parse_register(). It doesn't need to use minor tricks like memsetting struct to 0 to trigger an expected mtd_add_device_partitions() behavior. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
This commit is contained in:
parent
2c77c57d22
commit
0dbe4ea78d
@ -641,21 +641,6 @@ out_error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mtd_add_device_partitions(struct mtd_info *mtd,
|
|
||||||
struct mtd_partitions *parts)
|
|
||||||
{
|
|
||||||
const struct mtd_partition *real_parts = parts->parts;
|
|
||||||
int nbparts = parts->nr_parts;
|
|
||||||
|
|
||||||
if (!nbparts && !device_is_registered(&mtd->dev))
|
|
||||||
return add_mtd_device(mtd);
|
|
||||||
|
|
||||||
if (nbparts > 0)
|
|
||||||
return add_mtd_partitions(mtd, real_parts, nbparts);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a few defaults based on the parent devices, if not provided by the
|
* Set a few defaults based on the parent devices, if not provided by the
|
||||||
* driver
|
* driver
|
||||||
@ -706,7 +691,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
|
|||||||
const struct mtd_partition *parts,
|
const struct mtd_partition *parts,
|
||||||
int nr_parts)
|
int nr_parts)
|
||||||
{
|
{
|
||||||
struct mtd_partitions parsed;
|
struct mtd_partitions parsed = { };
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mtd_set_dev_defaults(mtd);
|
mtd_set_dev_defaults(mtd);
|
||||||
@ -717,24 +702,20 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&parsed, 0, sizeof(parsed));
|
/* Prefer parsed partitions over driver-provided fallback */
|
||||||
|
|
||||||
ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
|
ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
|
||||||
if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) {
|
if (!ret && parsed.nr_parts) {
|
||||||
/* Fall back to driver-provided partitions */
|
parts = parsed.parts;
|
||||||
parsed = (struct mtd_partitions){
|
nr_parts = parsed.nr_parts;
|
||||||
.parts = parts,
|
|
||||||
.nr_parts = nr_parts,
|
|
||||||
};
|
|
||||||
} else if (ret < 0) {
|
|
||||||
/* Didn't come up with parsed OR fallback partitions */
|
|
||||||
pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
|
|
||||||
ret);
|
|
||||||
/* Don't abort on errors; we can still use unpartitioned MTD */
|
|
||||||
memset(&parsed, 0, sizeof(parsed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mtd_add_device_partitions(mtd, &parsed);
|
if (nr_parts)
|
||||||
|
ret = add_mtd_partitions(mtd, parts, nr_parts);
|
||||||
|
else if (!device_is_registered(&mtd->dev))
|
||||||
|
ret = add_mtd_device(mtd);
|
||||||
|
else
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user