aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 13:48:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 13:48:05 -0400
commit25d80be86c5d7f53df41ec5ce96f6c6543cac245 (patch)
treea18fe8d5281d0ed44c049d5a59da499278bb6e3e /lib
parenta74e0c4c9cb02d44bc5ec1a70a6ba599366fb130 (diff)
parent45888b40d2a6221d46bb69959e2600ddba71cc1f (diff)
Merge tag 'rslib-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull reed-salomon library updates from Kees Cook: "Refactors rslib and callers to provide a per-instance allocation area instead of performing VLAs on the stack" * tag 'rslib-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: rslib: Allocate decoder buffers to avoid VLAs mtd: rawnand: diskonchip: Allocate rs control per instance rslib: Split rs control struct rslib: Simplify error path rslib: Remove GPL boilerplate rslib: Add SPDX identifiers rslib: Cleanup top level comments rslib: Cleanup whitespace damage dm/verity_fec: Use GFP aware reed solomon init rslib: Add GFP aware init function
Diffstat (limited to 'lib')
-rw-r--r--lib/reed_solomon/decode_rs.c34
-rw-r--r--lib/reed_solomon/encode_rs.c15
-rw-r--r--lib/reed_solomon/reed_solomon.c240
3 files changed, 159 insertions, 130 deletions
diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c
index 0ec3f257ffdf..1db74eb098d0 100644
--- a/lib/reed_solomon/decode_rs.c
+++ b/lib/reed_solomon/decode_rs.c
@@ -1,22 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * lib/reed_solomon/decode_rs.c 3 * Generic Reed Solomon encoder / decoder library
3 *
4 * Overview:
5 * Generic Reed Solomon encoder / decoder library
6 * 4 *
7 * Copyright 2002, Phil Karn, KA9Q 5 * Copyright 2002, Phil Karn, KA9Q
8 * May be used under the terms of the GNU General Public License (GPL) 6 * May be used under the terms of the GNU General Public License (GPL)
9 * 7 *
10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) 8 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
11 * 9 *
12 * $Id: decode_rs.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $ 10 * Generic data width independent code which is included by the wrappers.
13 *
14 */
15
16/* Generic data width independent code which is included by the
17 * wrappers.
18 */ 11 */
19{ 12{
13 struct rs_codec *rs = rsc->codec;
20 int deg_lambda, el, deg_omega; 14 int deg_lambda, el, deg_omega;
21 int i, j, r, k, pad; 15 int i, j, r, k, pad;
22 int nn = rs->nn; 16 int nn = rs->nn;
@@ -27,16 +21,22 @@
27 uint16_t *alpha_to = rs->alpha_to; 21 uint16_t *alpha_to = rs->alpha_to;
28 uint16_t *index_of = rs->index_of; 22 uint16_t *index_of = rs->index_of;
29 uint16_t u, q, tmp, num1, num2, den, discr_r, syn_error; 23 uint16_t u, q, tmp, num1, num2, den, discr_r, syn_error;
30 /* Err+Eras Locator poly and syndrome poly The maximum value
31 * of nroots is 8. So the necessary stack size will be about
32 * 220 bytes max.
33 */
34 uint16_t lambda[nroots + 1], syn[nroots];
35 uint16_t b[nroots + 1], t[nroots + 1], omega[nroots + 1];
36 uint16_t root[nroots], reg[nroots + 1], loc[nroots];
37 int count = 0; 24 int count = 0;
38 uint16_t msk = (uint16_t) rs->nn; 25 uint16_t msk = (uint16_t) rs->nn;
39 26
27 /*
28 * The decoder buffers are in the rs control struct. They are
29 * arrays sized [nroots + 1]
30 */
31 uint16_t *lambda = rsc->buffers + RS_DECODE_LAMBDA * (nroots + 1);
32 uint16_t *syn = rsc->buffers + RS_DECODE_SYN * (nroots + 1);
33 uint16_t *b = rsc->buffers + RS_DECODE_B * (nroots + 1);
34 uint16_t *t = rsc->buffers + RS_DECODE_T * (nroots + 1);
35 uint16_t *omega = rsc->buffers + RS_DECODE_OMEGA * (nroots + 1);
36 uint16_t *root = rsc->buffers + RS_DECODE_ROOT * (nroots + 1);
37 uint16_t *reg = rsc->buffers + RS_DECODE_REG * (nroots + 1);
38 uint16_t *loc = rsc->buffers + RS_DECODE_LOC * (nroots + 1);
39
40 /* Check length parameter for validity */ 40 /* Check length parameter for validity */
41 pad = nn - nroots - len; 41 pad = nn - nroots - len;
42 BUG_ON(pad < 0 || pad >= nn); 42 BUG_ON(pad < 0 || pad >= nn);
diff --git a/lib/reed_solomon/encode_rs.c b/lib/reed_solomon/encode_rs.c
index 0b5b1a6728ec..9112d46e869e 100644
--- a/lib/reed_solomon/encode_rs.c
+++ b/lib/reed_solomon/encode_rs.c
@@ -1,23 +1,16 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * lib/reed_solomon/encode_rs.c 3 * Generic Reed Solomon encoder / decoder library
3 *
4 * Overview:
5 * Generic Reed Solomon encoder / decoder library
6 * 4 *
7 * Copyright 2002, Phil Karn, KA9Q 5 * Copyright 2002, Phil Karn, KA9Q
8 * May be used under the terms of the GNU General Public License (GPL) 6 * May be used under the terms of the GNU General Public License (GPL)
9 * 7 *
10 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de) 8 * Adaption to the kernel by Thomas Gleixner (tglx@linutronix.de)
11 * 9 *
12 * $Id: encode_rs.c,v 1.5 2005/11/07 11:14:59 gleixner Exp $ 10 * Generic data width independent code which is included by the wrappers.
13 *
14 */
15
16/* Generic data width independent code which is included by the
17 * wrappers.
18 * int encode_rsX (struct rs_control *rs, uintX_t *data, int len, uintY_t *par)
19 */ 11 */
20{ 12{
13 struct rs_codec *rs = rsc->codec;
21 int i, j, pad; 14 int i, j, pad;
22 int nn = rs->nn; 15 int nn = rs->nn;
23 int nroots = rs->nroots; 16 int nroots = rs->nroots;
diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c
index 06d04cfa9339..dfcf54242fb9 100644
--- a/lib/reed_solomon/reed_solomon.c
+++ b/lib/reed_solomon/reed_solomon.c
@@ -1,43 +1,34 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * lib/reed_solomon/reed_solomon.c 3 * Generic Reed Solomon encoder / decoder library
3 *
4 * Overview:
5 * Generic Reed Solomon encoder / decoder library
6 * 4 *
7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 5 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de)
8 * 6 *
9 * Reed Solomon code lifted from reed solomon library written by Phil Karn 7 * Reed Solomon code lifted from reed solomon library written by Phil Karn
10 * Copyright 2002 Phil Karn, KA9Q 8 * Copyright 2002 Phil Karn, KA9Q
11 * 9 *
12 * $Id: rslib.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 *
18 * Description: 10 * Description:
19 * 11 *
20 * The generic Reed Solomon library provides runtime configurable 12 * The generic Reed Solomon library provides runtime configurable
21 * encoding / decoding of RS codes. 13 * encoding / decoding of RS codes.
22 * Each user must call init_rs to get a pointer to a rs_control
23 * structure for the given rs parameters. This structure is either
24 * generated or a already available matching control structure is used.
25 * If a structure is generated then the polynomial arrays for
26 * fast encoding / decoding are built. This can take some time so
27 * make sure not to call this function from a time critical path.
28 * Usually a module / driver should initialize the necessary
29 * rs_control structure on module / driver init and release it
30 * on exit.
31 * The encoding puts the calculated syndrome into a given syndrome
32 * buffer.
33 * The decoding is a two step process. The first step calculates
34 * the syndrome over the received (data + syndrome) and calls the
35 * second stage, which does the decoding / error correction itself.
36 * Many hw encoders provide a syndrome calculation over the received
37 * data + syndrome and can call the second stage directly.
38 * 14 *
15 * Each user must call init_rs to get a pointer to a rs_control structure
16 * for the given rs parameters. The control struct is unique per instance.
17 * It points to a codec which can be shared by multiple control structures.
18 * If a codec is newly allocated then the polynomial arrays for fast
19 * encoding / decoding are built. This can take some time so make sure not
20 * to call this function from a time critical path. Usually a module /
21 * driver should initialize the necessary rs_control structure on module /
22 * driver init and release it on exit.
23 *
24 * The encoding puts the calculated syndrome into a given syndrome buffer.
25 *
26 * The decoding is a two step process. The first step calculates the
27 * syndrome over the received (data + syndrome) and calls the second stage,
28 * which does the decoding / error correction itself. Many hw encoders
29 * provide a syndrome calculation over the received data + syndrome and can
30 * call the second stage directly.
39 */ 31 */
40
41#include <linux/errno.h> 32#include <linux/errno.h>
42#include <linux/kernel.h> 33#include <linux/kernel.h>
43#include <linux/init.h> 34#include <linux/init.h>
@@ -46,32 +37,44 @@
46#include <linux/slab.h> 37#include <linux/slab.h>
47#include <linux/mutex.h> 38#include <linux/mutex.h>
48 39
49/* This list holds all currently allocated rs control structures */ 40enum {
50static LIST_HEAD (rslist); 41 RS_DECODE_LAMBDA,
42 RS_DECODE_SYN,
43 RS_DECODE_B,
44 RS_DECODE_T,
45 RS_DECODE_OMEGA,
46 RS_DECODE_ROOT,
47 RS_DECODE_REG,
48 RS_DECODE_LOC,
49 RS_DECODE_NUM_BUFFERS
50};
51
52/* This list holds all currently allocated rs codec structures */
53static LIST_HEAD(codec_list);
51/* Protection for the list */ 54/* Protection for the list */
52static DEFINE_MUTEX(rslistlock); 55static DEFINE_MUTEX(rslistlock);
53 56
54/** 57/**
55 * rs_init - Initialize a Reed-Solomon codec 58 * codec_init - Initialize a Reed-Solomon codec
56 * @symsize: symbol size, bits (1-8) 59 * @symsize: symbol size, bits (1-8)
57 * @gfpoly: Field generator polynomial coefficients 60 * @gfpoly: Field generator polynomial coefficients
58 * @gffunc: Field generator function 61 * @gffunc: Field generator function
59 * @fcr: first root of RS code generator polynomial, index form 62 * @fcr: first root of RS code generator polynomial, index form
60 * @prim: primitive element to generate polynomial roots 63 * @prim: primitive element to generate polynomial roots
61 * @nroots: RS code generator polynomial degree (number of roots) 64 * @nroots: RS code generator polynomial degree (number of roots)
65 * @gfp: GFP_ flags for allocations
62 * 66 *
63 * Allocate a control structure and the polynom arrays for faster 67 * Allocate a codec structure and the polynom arrays for faster
64 * en/decoding. Fill the arrays according to the given parameters. 68 * en/decoding. Fill the arrays according to the given parameters.
65 */ 69 */
66static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int), 70static struct rs_codec *codec_init(int symsize, int gfpoly, int (*gffunc)(int),
67 int fcr, int prim, int nroots) 71 int fcr, int prim, int nroots, gfp_t gfp)
68{ 72{
69 struct rs_control *rs;
70 int i, j, sr, root, iprim; 73 int i, j, sr, root, iprim;
74 struct rs_codec *rs;
71 75
72 /* Allocate the control structure */ 76 rs = kzalloc(sizeof(*rs), gfp);
73 rs = kmalloc(sizeof (struct rs_control), GFP_KERNEL); 77 if (!rs)
74 if (rs == NULL)
75 return NULL; 78 return NULL;
76 79
77 INIT_LIST_HEAD(&rs->list); 80 INIT_LIST_HEAD(&rs->list);
@@ -85,17 +88,17 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
85 rs->gffunc = gffunc; 88 rs->gffunc = gffunc;
86 89
87 /* Allocate the arrays */ 90 /* Allocate the arrays */
88 rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), GFP_KERNEL); 91 rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
89 if (rs->alpha_to == NULL) 92 if (rs->alpha_to == NULL)
90 goto errrs; 93 goto err;
91 94
92 rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), GFP_KERNEL); 95 rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
93 if (rs->index_of == NULL) 96 if (rs->index_of == NULL)
94 goto erralp; 97 goto err;
95 98
96 rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), GFP_KERNEL); 99 rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), gfp);
97 if(rs->genpoly == NULL) 100 if(rs->genpoly == NULL)
98 goto erridx; 101 goto err;
99 102
100 /* Generate Galois field lookup tables */ 103 /* Generate Galois field lookup tables */
101 rs->index_of[0] = rs->nn; /* log(zero) = -inf */ 104 rs->index_of[0] = rs->nn; /* log(zero) = -inf */
@@ -120,7 +123,7 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
120 } 123 }
121 /* If it's not primitive, exit */ 124 /* If it's not primitive, exit */
122 if(sr != rs->alpha_to[0]) 125 if(sr != rs->alpha_to[0])
123 goto errpol; 126 goto err;
124 127
125 /* Find prim-th root of 1, used in decoding */ 128 /* Find prim-th root of 1, used in decoding */
126 for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn); 129 for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn);
@@ -148,42 +151,52 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
148 /* convert rs->genpoly[] to index form for quicker encoding */ 151 /* convert rs->genpoly[] to index form for quicker encoding */
149 for (i = 0; i <= nroots; i++) 152 for (i = 0; i <= nroots; i++)
150 rs->genpoly[i] = rs->index_of[rs->genpoly[i]]; 153 rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
154
155 rs->users = 1;
156 list_add(&rs->list, &codec_list);
151 return rs; 157 return rs;
152 158
153 /* Error exit */ 159err:
154errpol:
155 kfree(rs->genpoly); 160 kfree(rs->genpoly);
156erridx:
157 kfree(rs->index_of); 161 kfree(rs->index_of);
158erralp:
159 kfree(rs->alpha_to); 162 kfree(rs->alpha_to);
160errrs:
161 kfree(rs); 163 kfree(rs);
162 return NULL; 164 return NULL;
163} 165}
164 166
165 167
166/** 168/**
167 * free_rs - Free the rs control structure, if it is no longer used 169 * free_rs - Free the rs control structure
168 * @rs: the control structure which is not longer used by the 170 * @rs: The control structure which is not longer used by the
169 * caller 171 * caller
172 *
173 * Free the control structure. If @rs is the last user of the associated
174 * codec, free the codec as well.
170 */ 175 */
171void free_rs(struct rs_control *rs) 176void free_rs(struct rs_control *rs)
172{ 177{
178 struct rs_codec *cd;
179
180 if (!rs)
181 return;
182
183 cd = rs->codec;
173 mutex_lock(&rslistlock); 184 mutex_lock(&rslistlock);
174 rs->users--; 185 cd->users--;
175 if(!rs->users) { 186 if(!cd->users) {
176 list_del(&rs->list); 187 list_del(&cd->list);
177 kfree(rs->alpha_to); 188 kfree(cd->alpha_to);
178 kfree(rs->index_of); 189 kfree(cd->index_of);
179 kfree(rs->genpoly); 190 kfree(cd->genpoly);
180 kfree(rs); 191 kfree(cd);
181 } 192 }
182 mutex_unlock(&rslistlock); 193 mutex_unlock(&rslistlock);
194 kfree(rs);
183} 195}
196EXPORT_SYMBOL_GPL(free_rs);
184 197
185/** 198/**
186 * init_rs_internal - Find a matching or allocate a new rs control structure 199 * init_rs_internal - Allocate rs control, find a matching codec or allocate a new one
187 * @symsize: the symbol size (number of bits) 200 * @symsize: the symbol size (number of bits)
188 * @gfpoly: the extended Galois field generator polynomial coefficients, 201 * @gfpoly: the extended Galois field generator polynomial coefficients,
189 * with the 0th coefficient in the low order bit. The polynomial 202 * with the 0th coefficient in the low order bit. The polynomial
@@ -191,55 +204,69 @@ void free_rs(struct rs_control *rs)
191 * @gffunc: pointer to function to generate the next field element, 204 * @gffunc: pointer to function to generate the next field element,
192 * or the multiplicative identity element if given 0. Used 205 * or the multiplicative identity element if given 0. Used
193 * instead of gfpoly if gfpoly is 0 206 * instead of gfpoly if gfpoly is 0
194 * @fcr: the first consecutive root of the rs code generator polynomial 207 * @fcr: the first consecutive root of the rs code generator polynomial
195 * in index form 208 * in index form
196 * @prim: primitive element to generate polynomial roots 209 * @prim: primitive element to generate polynomial roots
197 * @nroots: RS code generator polynomial degree (number of roots) 210 * @nroots: RS code generator polynomial degree (number of roots)
211 * @gfp: GFP_ flags for allocations
198 */ 212 */
199static struct rs_control *init_rs_internal(int symsize, int gfpoly, 213static struct rs_control *init_rs_internal(int symsize, int gfpoly,
200 int (*gffunc)(int), int fcr, 214 int (*gffunc)(int), int fcr,
201 int prim, int nroots) 215 int prim, int nroots, gfp_t gfp)
202{ 216{
203 struct list_head *tmp; 217 struct list_head *tmp;
204 struct rs_control *rs; 218 struct rs_control *rs;
219 unsigned int bsize;
205 220
206 /* Sanity checks */ 221 /* Sanity checks */
207 if (symsize < 1) 222 if (symsize < 1)
208 return NULL; 223 return NULL;
209 if (fcr < 0 || fcr >= (1<<symsize)) 224 if (fcr < 0 || fcr >= (1<<symsize))
210 return NULL; 225 return NULL;
211 if (prim <= 0 || prim >= (1<<symsize)) 226 if (prim <= 0 || prim >= (1<<symsize))
212 return NULL; 227 return NULL;
213 if (nroots < 0 || nroots >= (1<<symsize)) 228 if (nroots < 0 || nroots >= (1<<symsize))
214 return NULL; 229 return NULL;
215 230
231 /*
232 * The decoder needs buffers in each control struct instance to
233 * avoid variable size or large fixed size allocations on
234 * stack. Size the buffers to arrays of [nroots + 1].
235 */
236 bsize = sizeof(uint16_t) * RS_DECODE_NUM_BUFFERS * (nroots + 1);
237 rs = kzalloc(sizeof(*rs) + bsize, gfp);
238 if (!rs)
239 return NULL;
240
216 mutex_lock(&rslistlock); 241 mutex_lock(&rslistlock);
217 242
218 /* Walk through the list and look for a matching entry */ 243 /* Walk through the list and look for a matching entry */
219 list_for_each(tmp, &rslist) { 244 list_for_each(tmp, &codec_list) {
220 rs = list_entry(tmp, struct rs_control, list); 245 struct rs_codec *cd = list_entry(tmp, struct rs_codec, list);
221 if (symsize != rs->mm) 246
247 if (symsize != cd->mm)
222 continue; 248 continue;
223 if (gfpoly != rs->gfpoly) 249 if (gfpoly != cd->gfpoly)
224 continue; 250 continue;
225 if (gffunc != rs->gffunc) 251 if (gffunc != cd->gffunc)
226 continue; 252 continue;
227 if (fcr != rs->fcr) 253 if (fcr != cd->fcr)
228 continue; 254 continue;
229 if (prim != rs->prim) 255 if (prim != cd->prim)
230 continue; 256 continue;
231 if (nroots != rs->nroots) 257 if (nroots != cd->nroots)
232 continue; 258 continue;
233 /* We have a matching one already */ 259 /* We have a matching one already */
234 rs->users++; 260 cd->users++;
261 rs->codec = cd;
235 goto out; 262 goto out;
236 } 263 }
237 264
238 /* Create a new one */ 265 /* Create a new one */
239 rs = rs_init(symsize, gfpoly, gffunc, fcr, prim, nroots); 266 rs->codec = codec_init(symsize, gfpoly, gffunc, fcr, prim, nroots, gfp);
240 if (rs) { 267 if (!rs->codec) {
241 rs->users = 1; 268 kfree(rs);
242 list_add(&rs->list, &rslist); 269 rs = NULL;
243 } 270 }
244out: 271out:
245 mutex_unlock(&rslistlock); 272 mutex_unlock(&rslistlock);
@@ -247,45 +274,48 @@ out:
247} 274}
248 275
249/** 276/**
250 * init_rs - Find a matching or allocate a new rs control structure 277 * init_rs_gfp - Create a RS control struct and initialize it
251 * @symsize: the symbol size (number of bits) 278 * @symsize: the symbol size (number of bits)
252 * @gfpoly: the extended Galois field generator polynomial coefficients, 279 * @gfpoly: the extended Galois field generator polynomial coefficients,
253 * with the 0th coefficient in the low order bit. The polynomial 280 * with the 0th coefficient in the low order bit. The polynomial
254 * must be primitive; 281 * must be primitive;
255 * @fcr: the first consecutive root of the rs code generator polynomial 282 * @fcr: the first consecutive root of the rs code generator polynomial
256 * in index form 283 * in index form
257 * @prim: primitive element to generate polynomial roots 284 * @prim: primitive element to generate polynomial roots
258 * @nroots: RS code generator polynomial degree (number of roots) 285 * @nroots: RS code generator polynomial degree (number of roots)
286 * @gfp: GFP_ flags for allocations
259 */ 287 */
260struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, 288struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim,
261 int nroots) 289 int nroots, gfp_t gfp)
262{ 290{
263 return init_rs_internal(symsize, gfpoly, NULL, fcr, prim, nroots); 291 return init_rs_internal(symsize, gfpoly, NULL, fcr, prim, nroots, gfp);
264} 292}
293EXPORT_SYMBOL_GPL(init_rs_gfp);
265 294
266/** 295/**
267 * init_rs_non_canonical - Find a matching or allocate a new rs control 296 * init_rs_non_canonical - Allocate rs control struct for fields with
268 * structure, for fields with non-canonical 297 * non-canonical representation
269 * representation
270 * @symsize: the symbol size (number of bits) 298 * @symsize: the symbol size (number of bits)
271 * @gffunc: pointer to function to generate the next field element, 299 * @gffunc: pointer to function to generate the next field element,
272 * or the multiplicative identity element if given 0. Used 300 * or the multiplicative identity element if given 0. Used
273 * instead of gfpoly if gfpoly is 0 301 * instead of gfpoly if gfpoly is 0
274 * @fcr: the first consecutive root of the rs code generator polynomial 302 * @fcr: the first consecutive root of the rs code generator polynomial
275 * in index form 303 * in index form
276 * @prim: primitive element to generate polynomial roots 304 * @prim: primitive element to generate polynomial roots
277 * @nroots: RS code generator polynomial degree (number of roots) 305 * @nroots: RS code generator polynomial degree (number of roots)
278 */ 306 */
279struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int), 307struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int),
280 int fcr, int prim, int nroots) 308 int fcr, int prim, int nroots)
281{ 309{
282 return init_rs_internal(symsize, 0, gffunc, fcr, prim, nroots); 310 return init_rs_internal(symsize, 0, gffunc, fcr, prim, nroots,
311 GFP_KERNEL);
283} 312}
313EXPORT_SYMBOL_GPL(init_rs_non_canonical);
284 314
285#ifdef CONFIG_REED_SOLOMON_ENC8 315#ifdef CONFIG_REED_SOLOMON_ENC8
286/** 316/**
287 * encode_rs8 - Calculate the parity for data values (8bit data width) 317 * encode_rs8 - Calculate the parity for data values (8bit data width)
288 * @rs: the rs control structure 318 * @rsc: the rs control structure
289 * @data: data field of a given type 319 * @data: data field of a given type
290 * @len: data length 320 * @len: data length
291 * @par: parity data, must be initialized by caller (usually all 0) 321 * @par: parity data, must be initialized by caller (usually all 0)
@@ -295,7 +325,7 @@ struct rs_control *init_rs_non_canonical(int symsize, int (*gffunc)(int),
295 * symbol size > 8. The calling code must take care of encoding of the 325 * symbol size > 8. The calling code must take care of encoding of the
296 * syndrome result for storage itself. 326 * syndrome result for storage itself.
297 */ 327 */
298int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, 328int encode_rs8(struct rs_control *rsc, uint8_t *data, int len, uint16_t *par,
299 uint16_t invmsk) 329 uint16_t invmsk)
300{ 330{
301#include "encode_rs.c" 331#include "encode_rs.c"
@@ -306,7 +336,7 @@ EXPORT_SYMBOL_GPL(encode_rs8);
306#ifdef CONFIG_REED_SOLOMON_DEC8 336#ifdef CONFIG_REED_SOLOMON_DEC8
307/** 337/**
308 * decode_rs8 - Decode codeword (8bit data width) 338 * decode_rs8 - Decode codeword (8bit data width)
309 * @rs: the rs control structure 339 * @rsc: the rs control structure
310 * @data: data field of a given type 340 * @data: data field of a given type
311 * @par: received parity data field 341 * @par: received parity data field
312 * @len: data length 342 * @len: data length
@@ -319,9 +349,14 @@ EXPORT_SYMBOL_GPL(encode_rs8);
319 * The syndrome and parity uses a uint16_t data type to enable 349 * The syndrome and parity uses a uint16_t data type to enable
320 * symbol size > 8. The calling code must take care of decoding of the 350 * symbol size > 8. The calling code must take care of decoding of the
321 * syndrome result and the received parity before calling this code. 351 * syndrome result and the received parity before calling this code.
352 *
353 * Note: The rs_control struct @rsc contains buffers which are used for
354 * decoding, so the caller has to ensure that decoder invocations are
355 * serialized.
356 *
322 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. 357 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors.
323 */ 358 */
324int decode_rs8(struct rs_control *rs, uint8_t *data, uint16_t *par, int len, 359int decode_rs8(struct rs_control *rsc, uint8_t *data, uint16_t *par, int len,
325 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 360 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
326 uint16_t *corr) 361 uint16_t *corr)
327{ 362{
@@ -333,7 +368,7 @@ EXPORT_SYMBOL_GPL(decode_rs8);
333#ifdef CONFIG_REED_SOLOMON_ENC16 368#ifdef CONFIG_REED_SOLOMON_ENC16
334/** 369/**
335 * encode_rs16 - Calculate the parity for data values (16bit data width) 370 * encode_rs16 - Calculate the parity for data values (16bit data width)
336 * @rs: the rs control structure 371 * @rsc: the rs control structure
337 * @data: data field of a given type 372 * @data: data field of a given type
338 * @len: data length 373 * @len: data length
339 * @par: parity data, must be initialized by caller (usually all 0) 374 * @par: parity data, must be initialized by caller (usually all 0)
@@ -341,7 +376,7 @@ EXPORT_SYMBOL_GPL(decode_rs8);
341 * 376 *
342 * Each field in the data array contains up to symbol size bits of valid data. 377 * Each field in the data array contains up to symbol size bits of valid data.
343 */ 378 */
344int encode_rs16(struct rs_control *rs, uint16_t *data, int len, uint16_t *par, 379int encode_rs16(struct rs_control *rsc, uint16_t *data, int len, uint16_t *par,
345 uint16_t invmsk) 380 uint16_t invmsk)
346{ 381{
347#include "encode_rs.c" 382#include "encode_rs.c"
@@ -352,7 +387,7 @@ EXPORT_SYMBOL_GPL(encode_rs16);
352#ifdef CONFIG_REED_SOLOMON_DEC16 387#ifdef CONFIG_REED_SOLOMON_DEC16
353/** 388/**
354 * decode_rs16 - Decode codeword (16bit data width) 389 * decode_rs16 - Decode codeword (16bit data width)
355 * @rs: the rs control structure 390 * @rsc: the rs control structure
356 * @data: data field of a given type 391 * @data: data field of a given type
357 * @par: received parity data field 392 * @par: received parity data field
358 * @len: data length 393 * @len: data length
@@ -363,9 +398,14 @@ EXPORT_SYMBOL_GPL(encode_rs16);
363 * @corr: buffer to store correction bitmask on eras_pos 398 * @corr: buffer to store correction bitmask on eras_pos
364 * 399 *
365 * Each field in the data array contains up to symbol size bits of valid data. 400 * Each field in the data array contains up to symbol size bits of valid data.
401 *
402 * Note: The rc_control struct @rsc contains buffers which are used for
403 * decoding, so the caller has to ensure that decoder invocations are
404 * serialized.
405 *
366 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors. 406 * Returns the number of corrected bits or -EBADMSG for uncorrectable errors.
367 */ 407 */
368int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, 408int decode_rs16(struct rs_control *rsc, uint16_t *data, uint16_t *par, int len,
369 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk, 409 uint16_t *s, int no_eras, int *eras_pos, uint16_t invmsk,
370 uint16_t *corr) 410 uint16_t *corr)
371{ 411{
@@ -374,10 +414,6 @@ int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len,
374EXPORT_SYMBOL_GPL(decode_rs16); 414EXPORT_SYMBOL_GPL(decode_rs16);
375#endif 415#endif
376 416
377EXPORT_SYMBOL_GPL(init_rs);
378EXPORT_SYMBOL_GPL(init_rs_non_canonical);
379EXPORT_SYMBOL_GPL(free_rs);
380
381MODULE_LICENSE("GPL"); 417MODULE_LICENSE("GPL");
382MODULE_DESCRIPTION("Reed Solomon encoder/decoder"); 418MODULE_DESCRIPTION("Reed Solomon encoder/decoder");
383MODULE_AUTHOR("Phil Karn, Thomas Gleixner"); 419MODULE_AUTHOR("Phil Karn, Thomas Gleixner");