lib/bch: use flexible array member for xi_tab
Subsystems (2)
PATCH v2 1/1 lib/bch: use flexible array member for xi_tab
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 <[email protected]>
---
v2: resend
include/linux/bch.h | 2 +- lib/bch.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
include/linux/bch.h +1 -1
@@ -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,
lib/bch.c +1 -3
@@ -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);
Signature · 1 line
2.56.1