|
79 | 79 | #define GF_T(_p) (CONFIG_BCH_CONST_T)
|
80 | 80 | #define GF_N(_p) ((1 << (CONFIG_BCH_CONST_M))-1)
|
81 | 81 | #define BCH_MAX_M (CONFIG_BCH_CONST_M)
|
| 82 | +#define BCH_MAX_T (CONFIG_BCH_CONST_T) |
82 | 83 | #else
|
83 | 84 | #define GF_M(_p) ((_p)->m)
|
84 | 85 | #define GF_T(_p) ((_p)->t)
|
85 | 86 | #define GF_N(_p) ((_p)->n)
|
86 |
| -#define BCH_MAX_M 15 |
| 87 | +#define BCH_MAX_M 15 /* 2KB */ |
| 88 | +#define BCH_MAX_T 64 /* 64 bit correction */ |
87 | 89 | #endif
|
88 | 90 |
|
89 |
| -#define BCH_MAX_T (((1 << BCH_MAX_M) - 1) / BCH_MAX_M) |
90 |
| - |
91 | 91 | #define BCH_ECC_WORDS(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 32)
|
92 | 92 | #define BCH_ECC_BYTES(_p) DIV_ROUND_UP(GF_M(_p)*GF_T(_p), 8)
|
93 | 93 |
|
94 | 94 | #define BCH_ECC_MAX_WORDS DIV_ROUND_UP(BCH_MAX_M * BCH_MAX_T, 32)
|
95 |
| -#define BCH_ECC_MAX_BYTES DIV_ROUND_UP(BCH_MAX_M * BCH_MAX_T, 8) |
96 | 95 |
|
97 | 96 | #ifndef dbg
|
98 | 97 | #define dbg(_fmt, args...) do {} while (0)
|
@@ -202,6 +201,9 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
|
202 | 201 | const uint32_t * const tab3 = tab2 + 256*(l+1);
|
203 | 202 | const uint32_t *pdata, *p0, *p1, *p2, *p3;
|
204 | 203 |
|
| 204 | + if (WARN_ON(r_bytes > sizeof(r))) |
| 205 | + return; |
| 206 | + |
205 | 207 | if (ecc) {
|
206 | 208 | /* load ecc parity bytes into internal 32-bit buffer */
|
207 | 209 | load_ecc8(bch, bch->ecc_buf, ecc);
|
@@ -1285,6 +1287,13 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
|
1285 | 1287 | */
|
1286 | 1288 | goto fail;
|
1287 | 1289 |
|
| 1290 | + if (t > BCH_MAX_T) |
| 1291 | + /* |
| 1292 | + * we can support larger than 64 bits if necessary, at the |
| 1293 | + * cost of higher stack usage. |
| 1294 | + */ |
| 1295 | + goto fail; |
| 1296 | + |
1288 | 1297 | /* sanity checks */
|
1289 | 1298 | if ((t < 1) || (m*t >= ((1 << m)-1)))
|
1290 | 1299 | /* invalid t value */
|
|
0 commit comments