mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/bch: use flexible array member for xi_tab
@ 2026-11-11  2:34 Rosen Penev
  0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-11-11  2:34 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

Convert xi_tab in struct bch_control from a separately allocated
pointer to a flexible array member trailing the struct. This co-locates
the xi_tab data with the struct allocation, reducing the number of
individual heap allocations and simplifying cleanup.

The xi_tab member is moved to the end of the struct and changed from
'unsigned int *' to 'unsigned int []'. The allocation in bch_init()
switches from kzalloc_obj + bch_alloc to kzalloc_flex, and the
corresponding kfree in bch_free() is removed.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 include/linux/bch.h | 2 +-
 lib/bch.c           | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/linux/bch.h b/include/linux/bch.h
index 85fdce83d4e2..e736b3a46e96 100644
--- a/include/linux/bch.h
+++ b/include/linux/bch.h
@@ -47,12 +47,12 @@ struct bch_control {
 	uint32_t       *mod8_tab;
 	uint32_t       *ecc_buf;
 	uint32_t       *ecc_buf2;
-	unsigned int   *xi_tab;
 	unsigned int   *syn;
 	int            *cache;
 	struct gf_poly *elp;
 	struct gf_poly *poly_2t[4];
 	bool		swap_bits;
+	unsigned int    xi_tab[];
 };
 
 struct bch_control *bch_init(int m, int t, unsigned int prim_poly,
diff --git a/lib/bch.c b/lib/bch.c
index c991c71c4cbd..f003965a21b9 100644
--- a/lib/bch.c
+++ b/lib/bch.c
@@ -1320,7 +1320,7 @@ struct bch_control *bch_init(int m, int t, unsigned int prim_poly,
 	if (prim_poly == 0)
 		prim_poly = prim_poly_tab[m-min_m];
 
-	bch = kzalloc_obj(*bch);
+	bch = kzalloc_flex(*bch, xi_tab, m);
 	if (bch == NULL)
 		goto fail;
 
@@ -1334,7 +1334,6 @@ struct bch_control *bch_init(int m, int t, unsigned int prim_poly,
 	bch->mod8_tab  = bch_alloc(words*1024*sizeof(*bch->mod8_tab), &err);
 	bch->ecc_buf   = bch_alloc(words*sizeof(*bch->ecc_buf), &err);
 	bch->ecc_buf2  = bch_alloc(words*sizeof(*bch->ecc_buf2), &err);
-	bch->xi_tab    = bch_alloc(m*sizeof(*bch->xi_tab), &err);
 	bch->syn       = bch_alloc(2*t*sizeof(*bch->syn), &err);
 	bch->cache     = bch_alloc(2*t*sizeof(*bch->cache), &err);
 	bch->elp       = bch_alloc((t+1)*sizeof(struct gf_poly_deg1), &err);
@@ -1384,7 +1383,6 @@ void bch_free(struct bch_control *bch)
 		kfree(bch->mod8_tab);
 		kfree(bch->ecc_buf);
 		kfree(bch->ecc_buf2);
-		kfree(bch->xi_tab);
 		kfree(bch->syn);
 		kfree(bch->cache);
 		kfree(bch->elp);
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-11  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11  2:34 [PATCH] lib/bch: use flexible array member for xi_tab Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®