forked from analogdevicesinc/linux
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'rslib-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/ker…
…nel/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
- Loading branch information
Showing
7 changed files
with
243 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* include/linux/rslib.h | ||
* | ||
* Overview: | ||
* Generic Reed Solomon encoder / decoder library | ||
* Generic Reed Solomon encoder / decoder library | ||
* | ||
* Copyright (C) 2004 Thomas Gleixner ([email protected]) | ||
* | ||
* RS code lifted from reed solomon library written by Phil Karn | ||
* Copyright 2002 Phil Karn, KA9Q | ||
* | ||
* $Id: rslib.h,v 1.4 2005/11/07 11:14:52 gleixner Exp $ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
*/ | ||
|
||
#ifndef _RSLIB_H_ | ||
#define _RSLIB_H_ | ||
|
||
#include <linux/list.h> | ||
#include <linux/types.h> /* for gfp_t */ | ||
#include <linux/gfp.h> /* for GFP_KERNEL */ | ||
|
||
/** | ||
* struct rs_control - rs control structure | ||
* struct rs_codec - rs codec data | ||
* | ||
* @mm: Bits per symbol | ||
* @nn: Symbols per block (= (1<<mm)-1) | ||
|
@@ -36,24 +29,34 @@ | |
* @gfpoly: The primitive generator polynominal | ||
* @gffunc: Function to generate the field, if non-canonical representation | ||
* @users: Users of this structure | ||
* @list: List entry for the rs control list | ||
* @list: List entry for the rs codec list | ||
*/ | ||
struct rs_control { | ||
int mm; | ||
int nn; | ||
struct rs_codec { | ||
int mm; | ||
int nn; | ||
uint16_t *alpha_to; | ||
uint16_t *index_of; | ||
uint16_t *genpoly; | ||
int nroots; | ||
int fcr; | ||
int prim; | ||
int iprim; | ||
int nroots; | ||
int fcr; | ||
int prim; | ||
int iprim; | ||
int gfpoly; | ||
int (*gffunc)(int); | ||
int users; | ||
struct list_head list; | ||
}; | ||
|
||
/** | ||
* struct rs_control - rs control structure per instance | ||
* @codec: The codec used for this instance | ||
* @buffers: Internal scratch buffers used in calls to decode_rs() | ||
*/ | ||
struct rs_control { | ||
struct rs_codec *codec; | ||
uint16_t buffers[0]; | ||
}; | ||
|
||
/* General purpose RS codec, 8-bit data width, symbol width 1-15 bit */ | ||
#ifdef CONFIG_REED_SOLOMON_ENC8 | ||
int encode_rs8(struct rs_control *rs, uint8_t *data, int len, uint16_t *par, | ||
|
@@ -76,18 +79,37 @@ int decode_rs16(struct rs_control *rs, uint16_t *data, uint16_t *par, int len, | |
uint16_t *corr); | ||
#endif | ||
|
||
/* Create or get a matching rs control structure */ | ||
struct rs_control *init_rs(int symsize, int gfpoly, int fcr, int prim, | ||
int nroots); | ||
struct rs_control *init_rs_gfp(int symsize, int gfpoly, int fcr, int prim, | ||
int nroots, gfp_t gfp); | ||
|
||
/** | ||
* init_rs - Create a RS control struct and initialize it | ||
* @symsize: the symbol size (number of bits) | ||
* @gfpoly: the extended Galois field generator polynomial coefficients, | ||
* with the 0th coefficient in the low order bit. The polynomial | ||
* must be primitive; | ||
* @fcr: the first consecutive root of the rs code generator polynomial | ||
* in index form | ||
* @prim: primitive element to generate polynomial roots | ||
* @nroots: RS code generator polynomial degree (number of roots) | ||
* | ||
* Allocations use GFP_KERNEL. | ||
*/ | ||
static inline struct rs_control *init_rs(int symsize, int gfpoly, int fcr, | ||
int prim, int nroots) | ||
{ | ||
return init_rs_gfp(symsize, gfpoly, fcr, prim, nroots, GFP_KERNEL); | ||
} | ||
|
||
struct rs_control *init_rs_non_canonical(int symsize, int (*func)(int), | ||
int fcr, int prim, int nroots); | ||
int fcr, int prim, int nroots); | ||
|
||
/* Release a rs control structure */ | ||
void free_rs(struct rs_control *rs); | ||
|
||
/** modulo replacement for galois field arithmetics | ||
* | ||
* @rs: the rs control structure | ||
* @rs: Pointer to the RS codec | ||
* @x: the value to reduce | ||
* | ||
* where | ||
|
@@ -97,7 +119,7 @@ void free_rs(struct rs_control *rs); | |
* Simple arithmetic modulo would return a wrong result for values | ||
* >= 3 * rs->nn | ||
*/ | ||
static inline int rs_modnn(struct rs_control *rs, int x) | ||
static inline int rs_modnn(struct rs_codec *rs, int x) | ||
{ | ||
while (x >= rs->nn) { | ||
x -= rs->nn; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* lib/reed_solomon/decode_rs.c | ||
* | ||
* Overview: | ||
* Generic Reed Solomon encoder / decoder library | ||
* Generic Reed Solomon encoder / decoder library | ||
* | ||
* Copyright 2002, Phil Karn, KA9Q | ||
* May be used under the terms of the GNU General Public License (GPL) | ||
* | ||
* Adaption to the kernel by Thomas Gleixner ([email protected]) | ||
* | ||
* $Id: decode_rs.c,v 1.7 2005/11/07 11:14:59 gleixner Exp $ | ||
* | ||
*/ | ||
|
||
/* Generic data width independent code which is included by the | ||
* wrappers. | ||
* Generic data width independent code which is included by the wrappers. | ||
*/ | ||
{ | ||
struct rs_codec *rs = rsc->codec; | ||
int deg_lambda, el, deg_omega; | ||
int i, j, r, k, pad; | ||
int nn = rs->nn; | ||
|
@@ -27,16 +21,22 @@ | |
uint16_t *alpha_to = rs->alpha_to; | ||
uint16_t *index_of = rs->index_of; | ||
uint16_t u, q, tmp, num1, num2, den, discr_r, syn_error; | ||
/* Err+Eras Locator poly and syndrome poly The maximum value | ||
* of nroots is 8. So the necessary stack size will be about | ||
* 220 bytes max. | ||
*/ | ||
uint16_t lambda[nroots + 1], syn[nroots]; | ||
uint16_t b[nroots + 1], t[nroots + 1], omega[nroots + 1]; | ||
uint16_t root[nroots], reg[nroots + 1], loc[nroots]; | ||
int count = 0; | ||
uint16_t msk = (uint16_t) rs->nn; | ||
|
||
/* | ||
* The decoder buffers are in the rs control struct. They are | ||
* arrays sized [nroots + 1] | ||
*/ | ||
uint16_t *lambda = rsc->buffers + RS_DECODE_LAMBDA * (nroots + 1); | ||
uint16_t *syn = rsc->buffers + RS_DECODE_SYN * (nroots + 1); | ||
uint16_t *b = rsc->buffers + RS_DECODE_B * (nroots + 1); | ||
uint16_t *t = rsc->buffers + RS_DECODE_T * (nroots + 1); | ||
uint16_t *omega = rsc->buffers + RS_DECODE_OMEGA * (nroots + 1); | ||
uint16_t *root = rsc->buffers + RS_DECODE_ROOT * (nroots + 1); | ||
uint16_t *reg = rsc->buffers + RS_DECODE_REG * (nroots + 1); | ||
uint16_t *loc = rsc->buffers + RS_DECODE_LOC * (nroots + 1); | ||
|
||
/* Check length parameter for validity */ | ||
pad = nn - nroots - len; | ||
BUG_ON(pad < 0 || pad >= nn); | ||
|
Oops, something went wrong.