[PATCH] mtd: concat: use container_of_const() in CONCAT()

Harshit Mogalapalli harshit.m.mogalapalli at oracle.com
Thu Sep 24 14:14:11 PDT 2026


CONCAT() currently recovers the enclosing struct mtd_concat by casting
its embedded struct mtd_info pointer. This assumes mtd remains the first
member of the structure.

Use container_of_const() with the named member to make the relationship
explicit and preserve any const qualifier.

Suggested-by: Luca Ceresoli <luca.ceresoli at bootlin.com>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli at oracle.com>
---
 drivers/mtd/mtdconcat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index d54d309c30a0..354cc71cd722 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -31,7 +31,7 @@
  * Given a pointer to the MTD object in the mtd_concat structure,
  * we can retrieve the pointer to that structure with this macro.
  */
-#define CONCAT(x)  ((struct mtd_concat *)(x))
+#define CONCAT(x)  container_of_const(x, struct mtd_concat, mtd)
 
 /*
  * MTD methods which look up the relevant subdevice, translate the
-- 
2.52.0




More information about the linux-mtd mailing list