* [PATCH v2] mtd: Make mtd_erase fail gracefully if CONFIG_MTD_WRITE is off
@ 2025-09-03 14:31 Christian Thießen via B4 Relay
2025-09-04 5:39 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Christian Thießen via B4 Relay @ 2025-09-03 14:31 UTC (permalink / raw)
To: BAREBOX; +Cc: Ahmad Fatoum, Christian Thießen
From: Christian Thießen <christian.thiessen@airbus.com>
When CONFIG_MTD_WRITE is unset, the mtd->_erase member of partition
devices does not get initialized, so it remains NULL.
However when running ubiattach on an UBI partition, mtd_erase() still
gets called, tries to call mtd->_erase and crashes. Make it fail
gracefully by returning ENOSYS ("Function not implemented") instead.
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Christian Thießen <christian.thiessen@airbus.com>
---
As discussed in https://github.com/barebox/barebox/issues/39 this patch
enables ubiattach-ing a NAND partition even if CONFIG_MTD_WRITE is
turned off, by making mtd_erase fail gracefully.
---
Hi,
thank you for the warm welcome and the constructive feedback!
Changes in v2: Addressed review comments.
- Changed from ifdef to IS_ENABLED
- Moved the sign-off tag to the commit message (why does b4 add it to
the cover letter?)
- Link to v1: https://lore.kernel.org/r/20250903-mtd-erase-enosys-v1-1-967a95172c4e@airbus.com
---
drivers/mtd/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 6162ec450fc1c3a0fa6339042c4d627e0f9567d0..bb579a8f5249981ec1623060ddb1b7056a06c1a0 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -436,6 +436,8 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
{
if (instr->addr >= mtd->size || instr->len > mtd->size - instr->addr)
return -EINVAL;
+ if (!IS_ENABLED(CONFIG_MTD_WRITE))
+ return -ENOSYS;
if (!(mtd->flags & MTD_WRITEABLE))
return -EROFS;
instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
---
base-commit: b5561f3bdd4845b478e5b35aab04f1d8e71ea93b
change-id: 20250902-mtd-erase-enosys-2d80e4bc77c8
Best regards,
--
Christian Thießen <christian.thiessen@airbus.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mtd: Make mtd_erase fail gracefully if CONFIG_MTD_WRITE is off
2025-09-03 14:31 [PATCH v2] mtd: Make mtd_erase fail gracefully if CONFIG_MTD_WRITE is off Christian Thießen via B4 Relay
@ 2025-09-04 5:39 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-09-04 5:39 UTC (permalink / raw)
To: BAREBOX, Christian Thießen via B4 Relay
Cc: Ahmad Fatoum, Christian Thießen
On Wed, 03 Sep 2025 16:31:21 +0200, Christian Thießen via B4 Relay wrote:
> When CONFIG_MTD_WRITE is unset, the mtd->_erase member of partition
> devices does not get initialized, so it remains NULL.
> However when running ubiattach on an UBI partition, mtd_erase() still
> gets called, tries to call mtd->_erase and crashes. Make it fail
> gracefully by returning ENOSYS ("Function not implemented") instead.
>
>
> [...]
Applied, thanks!
[1/1] mtd: Make mtd_erase fail gracefully if CONFIG_MTD_WRITE is off
https://git.pengutronix.de/cgit/barebox/commit/?id=b530b3d7ebf8 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-04 5:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-03 14:31 [PATCH v2] mtd: Make mtd_erase fail gracefully if CONFIG_MTD_WRITE is off Christian Thießen via B4 Relay
2025-09-04 5:39 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox