bch_decode(9)
π bch_decode(9) β bestie's guide to finding bit errors
okay so this one's from the Kernel API Manual, section 9, and it's literally the glow-up you need when your BCH codeword arrives looking a mess. Let's get into it π
β¨ NAME β¨
bch_decode β decode a received codeword and find out where the bit errors are hiding. it's giving detective energy π
π¦ SYNOPSIS π¦
int bch_decode (struct bch_control *bch , const uint8_t *data , unsigned
int len , const uint8_t *recv_ecc , const uint8_t *calc_ecc , const
unsigned int *syn , unsigned int *errloc );
πΈ ARGUMENTS πΈ
bchβ the BCH control structure. your main character struct π«Άdataβ the received data. lowkey ignored ifcalc_eccis providedlenβ data length in bytes. no cap, this one must always be providedrecv_eccβ the received ecc. if it'sNULLthen assume it was already XORed intocalc_ecccalc_eccβ the calculated ecc. if it'sNULLthencalc_eccgets computed fromdatasynβ hw computed syndrome data (ifNULL, the syndrome gets calculated for you)errlocβ output array of error locations. this is where the receipts land π
π₯ RETURN π₯
Returns the number of errors found β¨ or -EBADMSG if decoding failed π or -EINVAL if invalid parameters were provided π
π DESCRIPTION π
Depending on how much hw BCH support you've got, and whether you need to compute calc_ecc separately (with bch_encode), you should call this function with one of the following parameter configurations β pick your fighter π§
- by providing
dataandrecv_ecconly:bch_decode(bch, data, len, recv_ecc, NULL, NULL, errloc) - by providing
recv_eccandcalc_ecc:bch_decode(bch, NULL, len, recv_ecc, calc_ecc, NULL, errloc) - by providing
ecc = recv_ecc XOR calc_ecc:bch_decode(bch, NULL, len, NULL, ecc, NULL, errloc) - by providing syndrome results
syn:bch_decode(bch, NULL, len, NULL, NULL, syn, errloc)
Once bch_decode has successfully returned with a positive value, the error locations returned in the array errloc should be interpreted as follows β this is the part you screenshot and keep πΈ
- if
(errloc[n] >= 8*len), then the n-th error is located in ecc (no need for data correction, we stan) - if
(errloc[n] < 8*len), then the n-th error is located in data and can be corrected with the statement:data[errloc[n]/8] ^= 1 << (errloc[n] % 8);
β οΈ Note that this function does not perform any data correction by itself. it merely indicates error locations. so like, it points at the problem, it does not fix the problem. that's on you bestie ππ«Ά
π SEE ALSO π
Kernel file ./lib/bch.c β also go check out bch_encode(9), bch_init(9), and bch_free(9) β¨ the whole friend group fr fr
and that's the tea π this page lives in ./lib, dated October 2026 β periodt, go decode something iconic π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms