Subject: [PATCH] mtd: parsers: trx: parse "firmware" MTD partitions only
From: Rafał Miłecki <[email-masked]>
Date: Tue, 13 Apr 2021 18:25:20 +0200

Parsing every partition with "compatible" set to "brcm,trx" results in
parsing both: firmware partition and failsafe partition on devices that
implement failsafe booting. This affects e.g. Linksys EA9500 which has:

partition@200000 {
	reg = <0x0200000 0x01d00000>;
	compatible = "linksys,ns-firmware", "brcm,trx";
};

partition@1f00000 {
	reg = <0x01f00000 0x01d00000>;
	compatible = "linksys,ns-firmware", "brcm,trx";
};

Check for MTD partition name "firmware" before parsing. Recently added
ofpart_linksys_ns.c creates "firmware" and "failsafe" depending on
bootloader setup.

Signed-off-by: Rafał Miłecki <[email-masked]>
---
 drivers/mtd/parsers/parser_trx.c | 4 ++++
 1 file changed, 4 insertions(+)

--- a/drivers/mtd/parsers/parser_trx.c
+++ b/drivers/mtd/parsers/parser_trx.c
@@ -92,6 +92,10 @@ static int parser_trx_parse(struct mtd_i
 	if (err != 0 && err != -EINVAL)
 		pr_err("failed to parse \"brcm,trx-magic\" DT attribute, using default: %d\n", err);
 
+	/* Don't parse any failsafe / backup partitions */
+	if (strcmp(mtd->name, "firmware"))
+		return -EINVAL;
+
 	parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition),
 			GFP_KERNEL);
 	if (!parts)