lib/reed_solomon/reed_solomon.c
Source file repositories/reference/linux-study-clean/lib/reed_solomon/reed_solomon.c
File Facts
- System
- Linux kernel
- Corpus path
lib/reed_solomon/reed_solomon.c- Extension
.c- Size
- 12834 bytes
- Lines
- 425
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/kernel.hlinux/init.hlinux/module.hlinux/rslib.hlinux/slab.hlinux/mutex.hencode_rs.cdecode_rs.c
Detected Declarations
function free_rsfunction intfunction encode_rs8function decode_rs8function encode_rs16function decode_rs16export free_rsexport init_rs_gfpexport init_rs_non_canonicalexport encode_rs8export decode_rs8export encode_rs16export decode_rs16
Annotated Snippet
if (rs->genpoly[j] != 0) {
rs->genpoly[j] = rs->genpoly[j -1] ^
rs->alpha_to[rs_modnn(rs,
rs->index_of[rs->genpoly[j]] + root)];
} else
rs->genpoly[j] = rs->genpoly[j - 1];
}
/* rs->genpoly[0] can never be zero */
rs->genpoly[0] =
rs->alpha_to[rs_modnn(rs,
rs->index_of[rs->genpoly[0]] + root)];
}
/* convert rs->genpoly[] to index form for quicker encoding */
for (i = 0; i <= nroots; i++)
rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
rs->users = 1;
list_add(&rs->list, &codec_list);
return rs;
err:
kfree(rs->genpoly);
kfree(rs->index_of);
kfree(rs->alpha_to);
kfree(rs);
return NULL;
}
/**
* free_rs - Free the rs control structure
* @rs: The control structure which is not longer used by the
* caller
*
* Free the control structure. If @rs is the last user of the associated
* codec, free the codec as well.
*/
void free_rs(struct rs_control *rs)
{
struct rs_codec *cd;
if (!rs)
return;
cd = rs->codec;
mutex_lock(&rslistlock);
cd->users--;
if(!cd->users) {
list_del(&cd->list);
kfree(cd->alpha_to);
kfree(cd->index_of);
kfree(cd->genpoly);
kfree(cd);
}
mutex_unlock(&rslistlock);
kfree(rs);
}
EXPORT_SYMBOL_GPL(free_rs);
/**
* init_rs_internal - Allocate rs control, find a matching codec or allocate a new one
* @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;
* @gffunc: pointer to function to generate the next field element,
* or the multiplicative identity element if given 0. Used
* instead of gfpoly if gfpoly is 0
* @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)
* @gfp: GFP_ flags for allocations
*/
static struct rs_control *init_rs_internal(int symsize, int gfpoly,
int (*gffunc)(int), int fcr,
int prim, int nroots, gfp_t gfp)
{
struct list_head *tmp;
struct rs_control *rs;
unsigned int bsize;
/* Sanity checks */
if (symsize < 1)
return NULL;
if (fcr < 0 || fcr >= (1<<symsize))
return NULL;
if (prim <= 0 || prim >= (1<<symsize))
return NULL;
if (nroots < 0 || nroots >= (1<<symsize))
Annotation
- Immediate include surface: `linux/errno.h`, `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/rslib.h`, `linux/slab.h`, `linux/mutex.h`, `encode_rs.c`.
- Detected declarations: `function free_rs`, `function int`, `function encode_rs8`, `function decode_rs8`, `function encode_rs16`, `function decode_rs16`, `export free_rs`, `export init_rs_gfp`, `export init_rs_non_canonical`, `export encode_rs8`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.