[PATCH] mtd: mtdpart: check for subpartitions parsing result
John Thomson
lists at johnthomson.fastmail.com.au
Sat Jul 22 16:28:56 PDT 2023
Hi Rafał,
On Tue, 18 Jul 2023, at 13:49, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal at milecki.pl>
>
> parse_mtd_partitions() may return an error so it should be checked and
> optionally passed up
>
> Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
> ---
> drivers/mtd/mtdpart.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
> index 23483db8f30c..f43b5342992a 100644
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -426,7 +426,11 @@ int add_mtd_partitions(struct mtd_info *parent,
> mtd_add_partition_attrs(child);
>
> /* Look for subpartitions */
> - parse_mtd_partitions(child, parts[i].types, NULL);
> + ret = parse_mtd_partitions(child, parts[i].types, NULL);
> + if (ret) {
Thanks for finding this. I believe we need to check that the return value is negative.
+ if (ret < 0) {
/**
* parse_mtd_partitions - parse and register MTD partitions
…
* This function may return:
* o a negative error code in case of failure
* o number of found partitions otherwise
*/
> + pr_err("Failed to parse subpartitions: %d\n", ret);
> + goto err_del_partitions;
> + }
>
> cur_offset = child->part.offset + child->part.size;
> }
> --
> 2.35.3
Cheers,
--
John Thomson
More information about the linux-mtd
mailing list