From: Rosen Penev <rosenp@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2] lib/bch: use flexible array member for xi_tab
Date: Sat, 14 Nov 2026 15:33:54 -0800 [thread overview]
Message-ID: <20261114233354.84841-1-rosenp@gmail.com> (raw)
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>
---
v2: resend
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.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
WARNING: multiple messages have this Message-ID (diff)
From: Rosen Penev <rosenp@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2] lib/bch: use flexible array member for xi_tab
Date: Sat, 14 Nov 2026 15:33:54 -0800 [thread overview]
Message-ID: <20261114233354.84841-1-rosenp@gmail.com> (raw)
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>
---
v2: resend
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.1
next reply other threads:[~2026-11-14 23:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 23:33 Rosen Penev [this message]
2026-11-14 23:33 ` [PATCH v2] lib/bch: use flexible array member for xi_tab Rosen Penev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114233354.84841-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.