bch_decode(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 if calc_ecc is provided
  • len β€” data length in bytes. no cap, this one must always be provided
  • recv_ecc β€” the received ecc. if it's NULL then assume it was already XORed into calc_ecc
  • calc_ecc β€” the calculated ecc. if it's NULL then calc_ecc gets computed from data
  • syn β€” hw computed syndrome data (if NULL, 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 data and recv_ecc only: bch_decode(bch, data, len, recv_ecc, NULL, NULL, errloc)
  • by providing recv_ecc and calc_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