* [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct
@ 2026-04-30 22:07 Rosen Penev
2026-05-04 13:52 ` Miquel Raynal
2026-05-04 14:00 ` Miquel Raynal
0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-04-30 22:07 UTC (permalink / raw)
To: linux-mtd
Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, open list
Use a flexible array member and kzalloc_flex() to do so. Simplifies
memory allocation slightly.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/mtd/sm_ftl.c | 30 +++++++++++-------------------
drivers/mtd/sm_ftl.h | 2 +-
2 files changed, 12 insertions(+), 20 deletions(-)
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index c8032755f9a4..fb0f97fb94f0 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -1133,7 +1133,7 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
struct sm_ftl *ftl;
/* Allocate & initialize our private structure */
- ftl = kzalloc_obj(struct sm_ftl);
+ ftl = kzalloc_flex(*ftl, cis_buffer, SM_SECTOR_SIZE);
if (!ftl)
goto error1;
@@ -1145,25 +1145,20 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
/* Read media information */
if (sm_get_media_info(ftl, mtd)) {
dbg("found unsupported mtd device, aborting");
- goto error2;
+ goto error1;
}
- /* Allocate temporary CIS buffer for read retry support */
- ftl->cis_buffer = kzalloc(SM_SECTOR_SIZE, GFP_KERNEL);
- if (!ftl->cis_buffer)
- goto error2;
-
/* Allocate zone array, it will be initialized on demand */
ftl->zones = kzalloc_objs(struct ftl_zone, ftl->zone_count);
if (!ftl->zones)
- goto error3;
+ goto error2;
/* Allocate the cache*/
ftl->cache_data = kzalloc(ftl->block_size, GFP_KERNEL);
if (!ftl->cache_data)
- goto error4;
+ goto error3;
sm_cache_init(ftl);
@@ -1171,7 +1166,7 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
/* Allocate upper layer structure and initialize it */
trans = kzalloc_obj(struct mtd_blktrans_dev);
if (!trans)
- goto error5;
+ goto error4;
ftl->trans = trans;
trans->priv = ftl;
@@ -1184,12 +1179,12 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
if (sm_find_cis(ftl)) {
dbg("CIS not found on mtd device, aborting");
- goto error6;
+ goto error5;
}
ftl->disk_attributes = sm_create_sysfs_attributes(ftl);
if (!ftl->disk_attributes)
- goto error6;
+ goto error5;
trans->disk_attributes = ftl->disk_attributes;
sm_printk("Found %d MiB xD/SmartMedia FTL on mtd%d",
@@ -1206,17 +1201,15 @@ static void sm_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
/* Register device*/
if (add_mtd_blktrans_dev(trans)) {
dbg("error in mtdblktrans layer");
- goto error6;
+ goto error5;
}
return;
-error6:
- kfree(trans);
error5:
- kfree(ftl->cache_data);
+ kfree(trans);
error4:
- kfree(ftl->zones);
+ kfree(ftl->cache_data);
error3:
- kfree(ftl->cis_buffer);
+ kfree(ftl->zones);
error2:
kfree(ftl);
error1:
@@ -1242,7 +1235,6 @@ static void sm_remove_dev(struct mtd_blktrans_dev *dev)
}
sm_delete_sysfs_attributes(ftl);
- kfree(ftl->cis_buffer);
kfree(ftl->zones);
kfree(ftl->cache_data);
kfree(ftl);
diff --git a/drivers/mtd/sm_ftl.h b/drivers/mtd/sm_ftl.h
index 6aed8b60de16..1a1a54ce836a 100644
--- a/drivers/mtd/sm_ftl.h
+++ b/drivers/mtd/sm_ftl.h
@@ -39,7 +39,6 @@ struct sm_ftl {
int cis_block; /* CIS block location */
int cis_boffset; /* CIS offset in the block */
int cis_page_offset; /* CIS offset in the page */
- void *cis_buffer; /* tmp buffer for cis reads */
/* Cache */
int cache_block; /* block number of cached block */
@@ -56,6 +55,7 @@ struct sm_ftl {
int cylinders;
struct attribute_group *disk_attributes;
+ u8 cis_buffer[]; /* tmp buffer for cis reads */
};
struct chs_entry {
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct
2026-04-30 22:07 [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct Rosen Penev
@ 2026-05-04 13:52 ` Miquel Raynal
2026-05-04 14:00 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2026-05-04 13:52 UTC (permalink / raw)
To: linux-mtd, Rosen Penev
Cc: Richard Weinberger, Vignesh Raghavendra, linux-kernel
On Thu, 30 Apr 2026 15:07:19 -0700, Rosen Penev wrote:
> Use a flexible array member and kzalloc_flex() to do so. Simplifies
> memory allocation slightly.
>
>
Applied to mtd/next, thanks!
[1/1] mtd: sm_ftl: allocate cis_buffer with main struct
commit: 87eee18f2974c0b1d854b6228408b93c6bc91744
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct
2026-04-30 22:07 [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct Rosen Penev
2026-05-04 13:52 ` Miquel Raynal
@ 2026-05-04 14:00 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2026-05-04 14:00 UTC (permalink / raw)
To: Rosen Penev; +Cc: linux-mtd, Richard Weinberger, Vignesh Raghavendra, open list
Hi Rosen,
On 30/04/2026 at 15:07:19 -07, Rosen Penev <rosenp@gmail.com> wrote:
> Use a flexible array member and kzalloc_flex() to do so. Simplifies
> memory allocation slightly.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Applied to mtd/next.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-04 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 22:07 [PATCH] mtd: sm_ftl: allocate cis_buffer with main struct Rosen Penev
2026-05-04 13:52 ` Miquel Raynal
2026-05-04 14:00 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox