History

lib/bch: Rework a little bit the exported function names

There are four exported functions, all suffixed by _bch, which is clearly not the norm. Let's rename them by prefixing them with bch_ instead. This is a mechanical change: init_bch -> bch_init free_bch -> bch_free encode_bch -> bch_encode decode_bch -> bch_decode

Miquel Raynal committed 6 years ago

Commit c8ae3f71 parent f0689804 files · +46 −46Browse files

Unified · Split

4 files
  1. drivers/mtd/devices/docg3.c +5 −5
  2. drivers/mtd/nand/raw/nand_bch.c +5 −5
  3. include/linux/bch.h +4 −4
  4. lib/bch.c +32 −32
drivers/mtd/devices/docg3.c+5−5
@@ -647,7 +647,7 @@ static int doc_ecc_bch_fix_data(struct docg3 *docg3, void *buf, u8 *hwecc) · 646 unmodified lines
647 647
648 for (i = 0; i < DOC_ECC_BCH_SIZE; i++)648 for (i = 0; i < DOC_ECC_BCH_SIZE; i++)
649 ecc[i] = bitrev8(hwecc[i]);649 ecc[i] = bitrev8(hwecc[i]);
650 numerrs = decode_bch(docg3->cascade->bch, NULL,650 numerrs = bch_decode(docg3->cascade->bch, NULL,
651 DOC_ECC_BCH_COVERED_BYTES,651 DOC_ECC_BCH_COVERED_BYTES,
652 NULL, ecc, NULL, errorpos);652 NULL, ecc, NULL, errorpos);
653 BUG_ON(numerrs == -EINVAL);653 BUG_ON(numerrs == -EINVAL);
@@ -1984,8 +1984,8 @@ static int __init docg3_probe(struct platform_device *pdev) · 1330 unmodified lines
1984 return ret;1984 return ret;
1985 cascade->base = base;1985 cascade->base = base;
1986 mutex_init(&cascade->lock);1986 mutex_init(&cascade->lock);
1987 cascade->bch = init_bch(DOC_ECC_BCH_M, DOC_ECC_BCH_T,1987 cascade->bch = bch_init(DOC_ECC_BCH_M, DOC_ECC_BCH_T,
1988 DOC_ECC_BCH_PRIMPOLY);1988 DOC_ECC_BCH_PRIMPOLY);
1989 if (!cascade->bch)1989 if (!cascade->bch)
1990 return ret;1990 return ret;
1991 1991
@@ -2021,7 +2021,7 @@ notfound: · 29 unmodified lines
2021 ret = -ENODEV;2021 ret = -ENODEV;
2022 dev_info(dev, "No supported DiskOnChip found\n");2022 dev_info(dev, "No supported DiskOnChip found\n");
2023err_probe:2023err_probe:
2024 free_bch(cascade->bch);2024 bch_free(cascade->bch);
2025 for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++)2025 for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++)
2026 if (cascade->floors[floor])2026 if (cascade->floors[floor])
2027 doc_release_device(cascade->floors[floor]);2027 doc_release_device(cascade->floors[floor]);
@@ -2045,7 +2045,7 @@ static int docg3_release(struct platform_device *pdev) · 17 unmodified lines
2045 if (cascade->floors[floor])2045 if (cascade->floors[floor])
2046 doc_release_device(cascade->floors[floor]);2046 doc_release_device(cascade->floors[floor]);
2047 2047
2048 free_bch(docg3->cascade->bch);2048 bch_free(docg3->cascade->bch);
2049 return 0;2049 return 0;
2050}2050}
2051 2051
drivers/mtd/nand/raw/nand_bch.c+5−5
@@ -41,7 +41,7 @@ int nand_bch_calculate_ecc(struct nand_chip *chip, const unsigned char *buf, · 40 unmodified lines
41 unsigned int i;41 unsigned int i;
42 42
43 memset(code, 0, chip->ecc.bytes);43 memset(code, 0, chip->ecc.bytes);
44 encode_bch(nbc->bch, buf, chip->ecc.size, code);44 bch_encode(nbc->bch, buf, chip->ecc.size, code);
45 45
46 /* apply mask so that an erased page is a valid codeword */46 /* apply mask so that an erased page is a valid codeword */
47 for (i = 0; i < chip->ecc.bytes; i++)47 for (i = 0; i < chip->ecc.bytes; i++)
@@ -67,7 +67,7 @@ int nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf, · 19 unmodified lines
67 unsigned int *errloc = nbc->errloc;67 unsigned int *errloc = nbc->errloc;
68 int i, count;68 int i, count;
69 69
70 count = decode_bch(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,70 count = bch_decode(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
71 NULL, errloc);71 NULL, errloc);
72 if (count > 0) {72 if (count > 0) {
73 for (i = 0; i < count; i++) {73 for (i = 0; i < count; i++) {
@@ -130,7 +130,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) · 56 unmodified lines
130 if (!nbc)130 if (!nbc)
131 goto fail;131 goto fail;
132 132
133 nbc->bch = init_bch(m, t, 0);133 nbc->bch = bch_init(m, t, 0);
134 if (!nbc->bch)134 if (!nbc->bch)
135 goto fail;135 goto fail;
136 136
@@ -182,7 +182,7 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd) · 45 unmodified lines
182 goto fail;182 goto fail;
183 183
184 memset(erased_page, 0xff, eccsize);184 memset(erased_page, 0xff, eccsize);
185 encode_bch(nbc->bch, erased_page, eccsize, nbc->eccmask);185 bch_encode(nbc->bch, erased_page, eccsize, nbc->eccmask);
186 kfree(erased_page);186 kfree(erased_page);
187 187
188 for (i = 0; i < eccbytes; i++)188 for (i = 0; i < eccbytes; i++)
@@ -205,7 +205,7 @@ EXPORT_SYMBOL(nand_bch_init); · 16 unmodified lines
205void nand_bch_free(struct nand_bch_control *nbc)205void nand_bch_free(struct nand_bch_control *nbc)
206{206{
207 if (nbc) {207 if (nbc) {
208 free_bch(nbc->bch);208 bch_free(nbc->bch);
209 kfree(nbc->errloc);209 kfree(nbc->errloc);
210 kfree(nbc->eccmask);210 kfree(nbc->eccmask);
211 kfree(nbc);211 kfree(nbc);
include/linux/bch.h+4−4
@@ -53,14 +53,14 @@ struct bch_control { · 52 unmodified lines
53 struct gf_poly *poly_2t[4];53 struct gf_poly *poly_2t[4];
54};54};
55 55
56struct bch_control *init_bch(int m, int t, unsigned int prim_poly);56struct bch_control *bch_init(int m, int t, unsigned int prim_poly);
57 57
58void free_bch(struct bch_control *bch);58void bch_free(struct bch_control *bch);
59 59
60void encode_bch(struct bch_control *bch, const uint8_t *data,60void bch_encode(struct bch_control *bch, const uint8_t *data,
61 unsigned int len, uint8_t *ecc);61 unsigned int len, uint8_t *ecc);
62 62
63int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,63int bch_decode(struct bch_control *bch, const uint8_t *data, unsigned int len,
64 const uint8_t *recv_ecc, const uint8_t *calc_ecc,64 const uint8_t *recv_ecc, const uint8_t *calc_ecc,
65 const unsigned int *syn, unsigned int *errloc);65 const unsigned int *syn, unsigned int *errloc);
66 66
lib/bch.c+32−32
@@ -23,15 +23,15 @@ · 22 unmodified lines
23 * This library provides runtime configurable encoding/decoding of binary23 * This library provides runtime configurable encoding/decoding of binary
24 * Bose-Chaudhuri-Hocquenghem (BCH) codes.24 * Bose-Chaudhuri-Hocquenghem (BCH) codes.
25 *25 *
26 * Call init_bch to get a pointer to a newly allocated bch_control structure for26 * Call bch_init to get a pointer to a newly allocated bch_control structure for
27 * the given m (Galois field order), t (error correction capability) and27 * the given m (Galois field order), t (error correction capability) and
28 * (optional) primitive polynomial parameters.28 * (optional) primitive polynomial parameters.
29 *29 *
30 * Call encode_bch to compute and store ecc parity bytes to a given buffer.30 * Call bch_encode to compute and store ecc parity bytes to a given buffer.
31 * Call decode_bch to detect and locate errors in received data.31 * Call bch_decode to detect and locate errors in received data.
32 *32 *
33 * On systems supporting hw BCH features, intermediate results may be provided33 * On systems supporting hw BCH features, intermediate results may be provided
34 * to decode_bch in order to skip certain steps. See decode_bch() documentation34 * to bch_decode in order to skip certain steps. See bch_decode() documentation
35 * for details.35 * for details.
36 *36 *
37 * Option CONFIG_BCH_CONST_PARAMS can be used to force fixed values of37 * Option CONFIG_BCH_CONST_PARAMS can be used to force fixed values of
@@ -115,9 +115,9 @@ struct gf_poly_deg1 { · 77 unmodified lines
115};115};
116 116
117/*117/*
118 * same as encode_bch(), but process input data one byte at a time118 * same as bch_encode(), but process input data one byte at a time
119 */119 */
120static void encode_bch_unaligned(struct bch_control *bch,120static void bch_encode_unaligned(struct bch_control *bch,
121 const unsigned char *data, unsigned int len,121 const unsigned char *data, unsigned int len,
122 uint32_t *ecc)122 uint32_t *ecc)
123{123{
@@ -174,7 +174,7 @@ static void store_ecc8(struct bch_control *bch, uint8_t *dst, · 50 unmodified lines
174}174}
175 175
176/**176/**
177 * encode_bch - calculate BCH ecc parity of data177 * bch_encode - calculate BCH ecc parity of data
178 * @bch: BCH control structure178 * @bch: BCH control structure
179 * @data: data to encode179 * @data: data to encode
180 * @len: data length in bytes180 * @len: data length in bytes
@@ -187,7 +187,7 @@ static void store_ecc8(struct bch_control *bch, uint8_t *dst, · 6 unmodified lines
187 * The exact number of computed ecc parity bits is given by member @ecc_bits of187 * The exact number of computed ecc parity bits is given by member @ecc_bits of
188 * @bch; it may be less than m*t for large values of t.188 * @bch; it may be less than m*t for large values of t.
189 */189 */
190void encode_bch(struct bch_control *bch, const uint8_t *data,190void bch_encode(struct bch_control *bch, const uint8_t *data,
191 unsigned int len, uint8_t *ecc)191 unsigned int len, uint8_t *ecc)
192{192{
193 const unsigned int l = BCH_ECC_WORDS(bch)-1;193 const unsigned int l = BCH_ECC_WORDS(bch)-1;
@@ -215,7 +215,7 @@ void encode_bch(struct bch_control *bch, const uint8_t *data, · 21 unmodified lines
215 m = ((unsigned long)data) & 3;215 m = ((unsigned long)data) & 3;
216 if (m) {216 if (m) {
217 mlen = (len < (4-m)) ? len : 4-m;217 mlen = (len < (4-m)) ? len : 4-m;
218 encode_bch_unaligned(bch, data, mlen, bch->ecc_buf);218 bch_encode_unaligned(bch, data, mlen, bch->ecc_buf);
219 data += mlen;219 data += mlen;
220 len -= mlen;220 len -= mlen;
221 }221 }
@@ -255,13 +255,13 @@ void encode_bch(struct bch_control *bch, const uint8_t *data, · 33 unmodified lines
255 255
256 /* process last unaligned bytes */256 /* process last unaligned bytes */
257 if (len)257 if (len)
258 encode_bch_unaligned(bch, data, len, bch->ecc_buf);258 bch_encode_unaligned(bch, data, len, bch->ecc_buf);
259 259
260 /* store ecc parity bytes into original parity buffer */260 /* store ecc parity bytes into original parity buffer */
261 if (ecc)261 if (ecc)
262 store_ecc8(bch, ecc, bch->ecc_buf);262 store_ecc8(bch, ecc, bch->ecc_buf);
263}263}
264EXPORT_SYMBOL_GPL(encode_bch);264EXPORT_SYMBOL_GPL(bch_encode);
265 265
266static inline int modulo(struct bch_control *bch, unsigned int v)266static inline int modulo(struct bch_control *bch, unsigned int v)
267{267{
@@ -952,7 +952,7 @@ static int chien_search(struct bch_control *bch, unsigned int len, · 684 unmodified lines
952#endif /* USE_CHIEN_SEARCH */952#endif /* USE_CHIEN_SEARCH */
953 953
954/**954/**
955 * decode_bch - decode received codeword and find bit error locations955 * bch_decode - decode received codeword and find bit error locations
956 * @bch: BCH control structure956 * @bch: BCH control structure
957 * @data: received data, ignored if @calc_ecc is provided957 * @data: received data, ignored if @calc_ecc is provided
958 * @len: data length in bytes, must always be provided958 * @len: data length in bytes, must always be provided
@@ -966,22 +966,22 @@ static int chien_search(struct bch_control *bch, unsigned int len, · 7 unmodified lines
966 * invalid parameters were provided966 * invalid parameters were provided
967 *967 *
968 * Depending on the available hw BCH support and the need to compute @calc_ecc968 * Depending on the available hw BCH support and the need to compute @calc_ecc
969 * separately (using encode_bch()), this function should be called with one of969 * separately (using bch_encode()), this function should be called with one of
970 * the following parameter configurations -970 * the following parameter configurations -
971 *971 *
972 * by providing @data and @recv_ecc only:972 * by providing @data and @recv_ecc only:
973 * decode_bch(@bch, @data, @len, @recv_ecc, NULL, NULL, @errloc)973 * bch_decode(@bch, @data, @len, @recv_ecc, NULL, NULL, @errloc)
974 *974 *
975 * by providing @recv_ecc and @calc_ecc:975 * by providing @recv_ecc and @calc_ecc:
976 * decode_bch(@bch, NULL, @len, @recv_ecc, @calc_ecc, NULL, @errloc)976 * bch_decode(@bch, NULL, @len, @recv_ecc, @calc_ecc, NULL, @errloc)
977 *977 *
978 * by providing ecc = recv_ecc XOR calc_ecc:978 * by providing ecc = recv_ecc XOR calc_ecc:
979 * decode_bch(@bch, NULL, @len, NULL, ecc, NULL, @errloc)979 * bch_decode(@bch, NULL, @len, NULL, ecc, NULL, @errloc)
980 *980 *
981 * by providing syndrome results @syn:981 * by providing syndrome results @syn:
982 * decode_bch(@bch, NULL, @len, NULL, NULL, @syn, @errloc)982 * bch_decode(@bch, NULL, @len, NULL, NULL, @syn, @errloc)
983 *983 *
984 * Once decode_bch() has successfully returned with a positive value, error984 * Once bch_decode() has successfully returned with a positive value, error
985 * locations returned in array @errloc should be interpreted as follows -985 * locations returned in array @errloc should be interpreted as follows -
986 *986 *
987 * if (errloc[n] >= 8*len), then n-th error is located in ecc (no need for987 * if (errloc[n] >= 8*len), then n-th error is located in ecc (no need for
@@ -993,7 +993,7 @@ static int chien_search(struct bch_control *bch, unsigned int len, · 5 unmodified lines
993 * Note that this function does not perform any data correction by itself, it993 * Note that this function does not perform any data correction by itself, it
994 * merely indicates error locations.994 * merely indicates error locations.
995 */995 */
996int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,996int bch_decode(struct bch_control *bch, const uint8_t *data, unsigned int len,
997 const uint8_t *recv_ecc, const uint8_t *calc_ecc,997 const uint8_t *recv_ecc, const uint8_t *calc_ecc,
998 const unsigned int *syn, unsigned int *errloc)998 const unsigned int *syn, unsigned int *errloc)
999{999{
@@ -1012,7 +1012,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len, · 12 unmodified lines
1012 /* compute received data ecc into an internal buffer */1012 /* compute received data ecc into an internal buffer */
1013 if (!data || !recv_ecc)1013 if (!data || !recv_ecc)
1014 return -EINVAL;1014 return -EINVAL;
1015 encode_bch(bch, data, len, NULL);1015 bch_encode(bch, data, len, NULL);
1016 } else {1016 } else {
1017 /* load provided calculated ecc */1017 /* load provided calculated ecc */
1018 load_ecc8(bch, bch->ecc_buf, calc_ecc);1018 load_ecc8(bch, bch->ecc_buf, calc_ecc);
@@ -1053,7 +1053,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len, · 34 unmodified lines
1053 }1053 }
1054 return (err >= 0) ? err : -EBADMSG;1054 return (err >= 0) ? err : -EBADMSG;
1055}1055}
1056EXPORT_SYMBOL_GPL(decode_bch);1056EXPORT_SYMBOL_GPL(bch_decode);
1057 1057
1058/*1058/*
1059 * generate Galois field lookup tables1059 * generate Galois field lookup tables
@@ -1236,7 +1236,7 @@ finish: · 176 unmodified lines
1236}1236}
1237 1237
1238/**1238/**
1239 * init_bch - initialize a BCH encoder/decoder1239 * bch_init - initialize a BCH encoder/decoder
1240 * @m: Galois field order, should be in the range 5-151240 * @m: Galois field order, should be in the range 5-15
1241 * @t: maximum error correction capability, in bits1241 * @t: maximum error correction capability, in bits
1242 * @prim_poly: user-provided primitive polynomial (or 0 to use default)1242 * @prim_poly: user-provided primitive polynomial (or 0 to use default)
@@ -1246,17 +1246,17 @@ finish: · 3 unmodified lines
1246 *1246 *
1247 * This initialization can take some time, as lookup tables are built for fast1247 * This initialization can take some time, as lookup tables are built for fast
1248 * encoding/decoding; make sure not to call this function from a time critical1248 * encoding/decoding; make sure not to call this function from a time critical
1249 * path. Usually, init_bch() should be called on module/driver init and1249 * path. Usually, bch_init() should be called on module/driver init and
1250 * free_bch() should be called to release memory on exit.1250 * bch_free() should be called to release memory on exit.
1251 *1251 *
1252 * You may provide your own primitive polynomial of degree @m in argument1252 * You may provide your own primitive polynomial of degree @m in argument
1253 * @prim_poly, or let init_bch() use its default polynomial.1253 * @prim_poly, or let bch_init() use its default polynomial.
1254 *1254 *
1255 * Once init_bch() has successfully returned a pointer to a newly allocated1255 * Once bch_init() has successfully returned a pointer to a newly allocated
1256 * BCH control structure, ecc length in bytes is given by member @ecc_bytes of1256 * BCH control structure, ecc length in bytes is given by member @ecc_bytes of
1257 * the structure.1257 * the structure.
1258 */1258 */
1259struct bch_control *init_bch(int m, int t, unsigned int prim_poly)1259struct bch_control *bch_init(int m, int t, unsigned int prim_poly)
1260{1260{
1261 int err = 0;1261 int err = 0;
1262 unsigned int i, words;1262 unsigned int i, words;
@@ -1347,16 +1347,16 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly) · 84 unmodified lines
1347 return bch;1347 return bch;
1348 1348
1349fail:1349fail:
1350 free_bch(bch);1350 bch_free(bch);
1351 return NULL;1351 return NULL;
1352}1352}
1353EXPORT_SYMBOL_GPL(init_bch);1353EXPORT_SYMBOL_GPL(bch_init);
1354 1354
1355/**1355/**
1356 * free_bch - free the BCH control structure1356 * bch_free - free the BCH control structure
1357 * @bch: BCH control structure to release1357 * @bch: BCH control structure to release
1358 */1358 */
1359void free_bch(struct bch_control *bch)1359void bch_free(struct bch_control *bch)
1360{1360{
1361 unsigned int i;1361 unsigned int i;
1362 1362
@@ -1377,7 +1377,7 @@ void free_bch(struct bch_control *bch) · 14 unmodified lines
1377 kfree(bch);1377 kfree(bch);
1378 }1378 }
1379}1379}
1380EXPORT_SYMBOL_GPL(free_bch);1380EXPORT_SYMBOL_GPL(bch_free);
1381 1381
1382MODULE_LICENSE("GPL");1382MODULE_LICENSE("GPL");
1383MODULE_AUTHOR("Ivan Djelic <ivan.djelic@parrot.com>");1383MODULE_AUTHOR("Ivan Djelic <ivan.djelic@parrot.com>");