mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhang Boyang <zhangboyang.id@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ferdinand Blomqvist <ferdinand.blomqvist@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Zhang Boyang <zhangboyang.id@gmail.com>
Subject: [PATCH 3/5] rslib: Fix wrong result if gffunc(0) != 1
Date: Tue, 24 Sep 2024 20:31:39 +0800	[thread overview]
Message-ID: <20240924123141.16962-4-zhangboyang.id@gmail.com> (raw)
In-Reply-To: <20240924123141.16962-1-zhangboyang.id@gmail.com>

The rslib allows customizing the finite field by the `gffunc' parameter
of init_rs_non_canonical(). However, there are several places in rslib
use hard-coded 1, leading to errors if gffunc(0) != 1. This patch
replaces hard-coded 1 with alpha_to[0] to fix this problem. One of such
`gffunc' might be gffunc'(x) = swab16(gffunc(swab16(x))), as
gffunc'(0) = swab16(1). This special gffunc'(x) is useful when
implementing RS coder for 16 bit foreign-endian symbols.

Fixes: d7e5a5462f68 ("[RSLIB] Support non-canonical GF representations")
Signed-off-by: Zhang Boyang <zhangboyang.id@gmail.com>
---
 lib/reed_solomon/decode_rs.c    | 4 ++--
 lib/reed_solomon/reed_solomon.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c
index 805de84ae83d..6c1d53d1b702 100644
--- a/lib/reed_solomon/decode_rs.c
+++ b/lib/reed_solomon/decode_rs.c
@@ -104,7 +104,7 @@
 
  decode:
 	memset(&lambda[1], 0, nroots * sizeof(lambda[0]));
-	lambda[0] = 1;
+	lambda[0] = alpha_to[0];
 
 	if (no_eras > 0) {
 		/* Init lambda to be the erasure locator polynomial */
@@ -198,7 +198,7 @@
 	memcpy(&reg[1], &lambda[1], nroots * sizeof(reg[0]));
 	count = 0;		/* Number of roots of lambda(x) */
 	for (i = 1, k = iprim - 1; i <= nn; i++, k = rs_modnn(rs, k + iprim)) {
-		q = 1;		/* lambda[0] is always 0 */
+		q = alpha_to[0];	/* lambda[0] is always 0 */
 		for (j = deg_lambda; j > 0; j--) {
 			if (reg[j] != nn) {
 				reg[j] = rs_modnn(rs, reg[j] + j);
diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c
index bbc01bad3053..bb4f44c8edba 100644
--- a/lib/reed_solomon/reed_solomon.c
+++ b/lib/reed_solomon/reed_solomon.c
@@ -131,9 +131,9 @@ static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int),
 	rs->iprim = iprim / prim;
 
 	/* Form RS code generator polynomial from its roots */
-	rs->genpoly[0] = 1;
+	rs->genpoly[0] = rs->alpha_to[0];
 	for (i = 0, root = fcr * prim; i < nroots; i++, root += prim) {
-		rs->genpoly[i + 1] = 1;
+		rs->genpoly[i + 1] = rs->alpha_to[0];
 		/* Multiply rs->genpoly[] by  @**(root + x) */
 		for (j = i; j > 0; j--) {
 			if (rs->genpoly[j] != 0) {
-- 
2.30.2


  parent reply	other threads:[~2024-09-24 12:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24 12:31 [PATCH 0/5] rslib: Bug fixes and improvements for Reed-Solomon library Zhang Boyang
2024-09-24 12:31 ` [PATCH 1/5] rslib: Fix incorrect documentation of rs_modnn() Zhang Boyang
2024-09-24 12:31 ` [PATCH 2/5] rslib: Fix documentation of alpha_to[] and index_of[] Zhang Boyang
2024-09-24 12:31 ` Zhang Boyang [this message]
2024-09-24 12:31 ` [PATCH 4/5] rslib: Improve the performance of encode_rs.c Zhang Boyang
2024-09-24 12:31 ` [PATCH 5/5] rslib: Fix 16-bit symbol support Zhang Boyang
2024-09-26 17:03 ` [PATCH 0/5] rslib: Bug fixes and improvements for Reed-Solomon library Randy Dunlap
2024-09-26 17:12   ` Linus Torvalds
2024-09-26 23:54     ` Zhang Boyang
2024-09-28 21:11     ` Kees Cook
2024-09-29  3:22       ` Zhang Boyang
2024-09-26 23:53   ` Zhang Boyang

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=20240924123141.16962-4-zhangboyang.id@gmail.com \
    --to=zhangboyang.id@gmail.com \
    --cc=ferdinand.blomqvist@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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 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®