Skip to contentSkip to conversation

arm: mvebu: turris_omnia: fix leaked mtd device

PATCH In review Marek Behún 3 participants 5 messages Sep 25, 2021 – Sep 27, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: mvebu: turris_omnia: fix leaked mtd device

From: Marek Behún <[email protected]>

After getting MTD device via get_mtd_device_nm(), we need to put it with put_mtd_device(), otherwise we get

Removing MTD device #0 (mx25l6405d) with use count 1

before booting kernel.

---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++
 1 file changed, 3 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +3 -0
index bac78af04e..a48e1f5c30 100644
@@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	if (!fixup_mtd_partitions(blob, node, mtd))
 		goto fail;
 
+	put_mtd_device(mtd);
 	return 0;
 
 fail:
 	printf("Failed fixing SPI NOR partitions!\n");
+	if (!IS_ERR_OR_NULL(mtd))
+		put_mtd_device(mtd);
 	return 0;
 }
 #endif
Signature · 1 line
2.32.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · On Saturday 25 September 2021 02:49:18 Marek Behún wrote:

From: Marek Behún <[email protected]>

After getting MTD device via get_mtd_device_nm(), we need to put it with put_mtd_device(), otherwise we get

Removing MTD device #0 (mx25l6405d) with use count 1

before booting kernel.

Fixes 92f36c8e74c1 ("arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB")

Above commit was introduced in v2021.10-rc1, so I think this fixup should go into v2021.10.

Stefan, what do you think?

Quoted 25 lines
---
 board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++
 1 file changed, 3 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +3 -0
index bac78af04e..a48e1f5c30 100644
@@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 	if (!fixup_mtd_partitions(blob, node, mtd))
 		goto fail;
 
+	put_mtd_device(mtd);
 	return 0;
 
 fail:
 	printf("Failed fixing SPI NOR partitions!\n");
+	if (!IS_ERR_OR_NULL(mtd))
+		put_mtd_device(mtd);
 	return 0;
 }
 #endif
Signature · 1 line
2.32.0
#2 lore raw
Quoted 12 lines · Pali Rohár
Quoted 10 lines · On Saturday 25 September 2021 02:49:18 Marek Behún wrote:

From: Marek Behún <[email protected]>

After getting MTD device via get_mtd_device_nm(), we need to put it with put_mtd_device(), otherwise we get

Removing MTD device #0 (mx25l6405d) with use count 1

before booting kernel.

Quoted 8 lines
Fixes 92f36c8e74c1 ("arm: mvebu: turris_omnia: fixup MTD partitions in Linux' DTB")

Above commit was introduced in v2021.10-rc1, so I think this fixup should go into v2021.10.

Stefan, what do you think?

Makes sense. I'll push this out today.

Thanks,
Stefan

Quoted 15 lines
Quoted 15 lines
---
  board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++
  1 file changed, 3 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +1 -0
index bac78af04e..a48e1f5c30 100644
@@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd)
  	if (!fixup_mtd_partitions(blob, node, mtd))
  		goto fail;
 
+	put_mtd_device(mtd);
  	return 0;
 
Quoted 10 lines
Quoted 10 lines
board/CZ.NIC/turris_omnia/turris_omnia.c +2 -0
  fail:
  	printf("Failed fixing SPI NOR partitions!\n");
+	if (!IS_ERR_OR_NULL(mtd))
+		put_mtd_device(mtd);
  	return 0;
  }
  #endif
Signature · 1 line
2.32.0

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 1/1
#3 lore raw
In reply to Marek Behún
Quoted 10 lines · Marek Behún

From: Marek Behún <[email protected]>

After getting MTD device via get_mtd_device_nm(), we need to put it with put_mtd_device(), otherwise we get

Removing MTD device #0 (mx25l6405d) with use count 1

before booting kernel.

Thanks,
Stefan

Quoted 13 lines
---
  board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++
  1 file changed, 3 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +0 -0
index bac78af04e..a48e1f5c30 100644
@@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd)
  	if (!fixup_mtd_partitions(blob, node, mtd))
  		goto fail;
 

board/CZ.NIC/turris_omnia/turris_omnia.c int ft_board_setup(void *blob, struct bd_info *bd) · line 659

Quoted 10 lines
board/CZ.NIC/turris_omnia/turris_omnia.c +3 -0
+	put_mtd_device(mtd);
  	return 0;
 
  fail:
  	printf("Failed fixing SPI NOR partitions!\n");
+	if (!IS_ERR_OR_NULL(mtd))
+		put_mtd_device(mtd);
  	return 0;
  }
  #endif

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#4 lore raw
In reply to Marek Behún
Quoted 10 lines · Marek Behún

From: Marek Behún <[email protected]>

After getting MTD device via get_mtd_device_nm(), we need to put it with put_mtd_device(), otherwise we get

Removing MTD device #0 (mx25l6405d) with use count 1

before booting kernel.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 13 lines
---
  board/CZ.NIC/turris_omnia/turris_omnia.c | 3 +++
  1 file changed, 3 insertions(+)
board/CZ.NIC/turris_omnia/turris_omnia.c +0 -0
index bac78af04e..a48e1f5c30 100644
@@ -647,10 +647,13 @@ int ft_board_setup(void *blob, struct bd_info *bd)
  	if (!fixup_mtd_partitions(blob, node, mtd))
  		goto fail;
 

board/CZ.NIC/turris_omnia/turris_omnia.c int ft_board_setup(void *blob, struct bd_info *bd) · line 659

Quoted 10 lines
board/CZ.NIC/turris_omnia/turris_omnia.c +3 -0
+	put_mtd_device(mtd);
  	return 0;
 
  fail:
  	printf("Failed fixing SPI NOR partitions!\n");
+	if (!IS_ERR_OR_NULL(mtd))
+		put_mtd_device(mtd);
  	return 0;
  }
  #endif

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]