Skip to content

Commit 18b8f4f

Browse files
committed
modify astyle
1 parent f414fff commit 18b8f4f

File tree

2 files changed

+45
-38
lines changed
  • storage/blockdevice/COMPONENT_SPINAND

2 files changed

+45
-38
lines changed

storage/blockdevice/COMPONENT_SPINAND/include/SPINAND/bch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2022 Macronix International Co., Ltd.
33
* SPDX-License-Identifier: Apache-2.0
44
*/

storage/blockdevice/COMPONENT_SPINAND/source/bch.c

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2022 Macronix International Co., Ltd.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
@@ -45,10 +45,11 @@ void bch_encode(struct bch_code *bch, unsigned char *data, unsigned int *ecc)
4545
unsigned int *p;
4646
unsigned int *c[16];
4747
unsigned int *t[16];
48-
48+
4949
t[0] = bch->mod_tab;
50-
for (i = 1; i < 16; i++)
50+
for (i = 1; i < 16; i++) {
5151
t[i] = t[i-1] + 4 * (bch->ecc_words);
52+
}
5253

5354
memset(bch->ecc, 0, bch->ecc_words * sizeof(*bch->ecc));
5455

@@ -79,7 +80,7 @@ void bch_encode(struct bch_code *bch, unsigned char *data, unsigned int *ecc)
7980
}
8081
}
8182
bch->ecc[i] = c[0][i];
82-
for (j = 1; j < 16; j++) {
83+
for (j = 1; j < 16; j++) {
8384
bch->ecc[i] ^= c[j][i];
8485
}
8586
}
@@ -88,7 +89,7 @@ void bch_encode(struct bch_code *bch, unsigned char *data, unsigned int *ecc)
8889
for (i = 0; i < bch->ecc_words; i++) {
8990
ecc[i] = bch->ecc[i];
9091
}
91-
}
92+
}
9293
}
9394

9495
static inline int mod(struct bch_code *bch, unsigned int v)
@@ -105,7 +106,7 @@ static void build_syndrome(struct bch_code *bch)
105106
unsigned int i, j;
106107
unsigned int ecc_bits;
107108
unsigned int *ecc;
108-
109+
109110
memset(bch->syn, 0, 2 * bch->t * sizeof(*bch->syn));
110111

111112
ecc_bits = bch->ecc_bits;
@@ -115,8 +116,9 @@ static void build_syndrome(struct bch_code *bch)
115116
ecc_bits = i;
116117
while (*ecc) {
117118
if (*ecc & (unsigned int)1) {
118-
for (j = 0; j < 2*bch->t; j++)
119-
bch->syn[j] ^= bch->a_pow[mod(bch, (j+1)*i)];
119+
for (j = 0; j < 2*bch->t; j++) {
120+
bch->syn[j] ^= bch->a_pow[mod(bch, (j+1)*i)];
121+
}
120122
}
121123
*ecc >>= 1;
122124
i++;
@@ -141,21 +143,21 @@ static int build_error_location_poly(struct bch_code *bch)
141143

142144
for (i = 0; (i < bch->t) && (deg <= bch->t); i++) {
143145
if (d) {
144-
k = 2 * i-pp;
146+
k = 2 * i - pp;
145147
if (buf_deg + k > deg) {
146148
tmp_deg = deg;
147149
for (j = 0; j <= deg; j++) {
148150
bch->buf2[j] = bch->elp[j];
149151
}
150152
}
151153
tmp = bch->n + bch->a_log[d] - bch->a_log[dp];
152-
154+
153155
for (j = 0; j <= buf_deg; j++) {
154156
if (bch->buf[j]) {
155-
bch->elp[j+k] ^= bch->a_pow[mod(bch, tmp + bch->a_log[bch->buf[j]])];
157+
bch->elp[j + k] ^= bch->a_pow[mod(bch, tmp + bch->a_log[bch->buf[j]])];
156158
}
157159
}
158-
if (buf_deg+k > deg) {
160+
if (buf_deg + k > deg) {
159161
deg = buf_deg + k;
160162
buf_deg = tmp_deg;
161163
for (j = 0; j <= tmp_deg; j++) {
@@ -183,8 +185,8 @@ static int chien_search(struct bch_code *bch, unsigned int deg)
183185
{
184186
unsigned int i, j, k, nroot = 0;
185187
unsigned int syn, syn0;
186-
int *rep = (int*) bch->buf;
187-
int *root = (int*) bch->buf2;
188+
int *rep = (int *)bch->buf;
189+
int *root = (int *)bch->buf2;
188190

189191
k = bch->n - bch->a_log[bch->elp[deg]];
190192
for (i = 0; i < deg; i++) {
@@ -205,31 +207,32 @@ static int chien_search(struct bch_code *bch, unsigned int deg)
205207
return nroot;
206208
}
207209
}
208-
}
209-
return 0;
210+
}
211+
return 0;
210212
}
211213

212214
int bch_decode(struct bch_code *bch, unsigned char *data, unsigned int *ecc)
213215
{
214216
unsigned int nbits;
215217
unsigned int i, err, nroot;
216-
int *root = (int*) bch->buf2;
218+
int *root = (int *)bch->buf2;
217219

218220
bch_encode(bch, data, NULL);
219221

220222
for (i = 0, err = 0; i < bch->ecc_words; i++) {
221223
bch->ecc[i] ^= ecc[i];
222224
err |= bch->ecc[i];
223225
}
224-
if (!err)
226+
if (!err) {
225227
return 0;
228+
}
226229

227230
build_syndrome(bch);
228231
err = build_error_location_poly(bch);
229232
if (err <= 0) {
230233
return -1;
231234
}
232-
235+
233236
nroot = chien_search(bch, err);
234237
if (err != nroot) {
235238
return -1;
@@ -238,7 +241,7 @@ int bch_decode(struct bch_code *bch, unsigned char *data, unsigned int *ecc)
238241
for (i = 0; i < err; i++) {
239242
root[i] = nbits - 1 - root[i];
240243
root[i] = (root[i] & ~7) | (7 - (root[i] & 7));
241-
data[root[i]/8] ^= 1 << root[i]%8;
244+
data[root[i] / 8] ^= 1 << root[i] % 8;
242245
}
243246

244247
return err;
@@ -251,7 +254,7 @@ static void build_gf_table(struct bch_code *bch)
251254
unsigned int prim_poly[5] = {0x11d, 0x211, 0x409, 0x805, 0x1053};
252255

253256
poly = prim_poly[bch->m - 8];
254-
msb = 1 << bch->m;
257+
msb = 1 << bch->m;
255258
bch->a_pow[0] = 1;
256259
bch->a_log[1] = 0;
257260
x = 2;
@@ -278,12 +281,12 @@ static void build_mod_tables(struct bch_code *bch, const unsigned int *g)
278281

279282
for (i = 0; i < 4; i++) {
280283
for (b = 0; b < 16; b++) {
281-
tab = bch->mod_tab + (b*4+i)*bch->ecc_words;
282-
data = i << (2*b);
284+
tab = bch->mod_tab + (b * 4 + i) * bch->ecc_words;
285+
data = i << (2 * b);
283286
while (data) {
284287
d = 0;
285288
poly = (data >> 1);
286-
while(poly) {
289+
while (poly) {
287290
poly >>= 1;
288291
d++;
289292
}
@@ -301,10 +304,12 @@ static void build_mod_tables(struct bch_code *bch, const unsigned int *g)
301304
static void *bch_alloc(size_t size, int *err)
302305
{
303306
void *ptr = NULL;
304-
if (*err == 0)
307+
if (*err == 0) {
305308
ptr = malloc(size);
306-
if (ptr == NULL)
309+
}
310+
if (ptr == NULL) {
307311
*err = 1;
312+
}
308313
return ptr;
309314
}
310315

@@ -324,36 +329,38 @@ static unsigned int *build_generator_poly(struct bch_code *bch)
324329
free(g);
325330
free(x);
326331
bch_free(bch);
327-
return NULL;
332+
return NULL;
328333
}
329-
334+
330335
bch->ecc_bits = 0;
331336
x[0] = 1;
332337
for (t = 0; t < bch->t; t++) {
333338
for (m = 0, i = 2 * t + 1; m < bch->m; m++) {
334339
x[bch->ecc_bits + 1] = 1;
335340
for (j = bch->ecc_bits; j > 0; j--) {
336-
if (x[j]) {
341+
if (x[j]) {
337342
x[j] = bch->a_pow[mod(bch, bch->a_log[x[j]] + i)] ^ x[j - 1];
338343
} else {
339-
x[j] = x[j-1];
344+
x[j] = x[j - 1];
340345
}
341346
}
342-
if (x[j])
347+
if (x[j]) {
343348
x[j] = bch->a_pow[mod(bch, bch->a_log[x[j]] + i)];
349+
}
344350
bch->ecc_bits++;
345351
i = mod(bch, 2 * i);
346352
}
347353
}
348354

349355
i = 0;
350356
memset(g, 0, (bch->ecc_words + 1) * sizeof(*g));
351-
357+
352358
for (k = bch->ecc_bits + 1; k > 0; k = k - n) {
353359
n = (k > 32) ? 32 : k;
354360
for (j = 0; j < n; j++) {
355-
if (x[k-1-j])
361+
if (x[k - 1 - j]) {
356362
g[i] |= (unsigned int)1 << (31 - j);
363+
}
357364
}
358365
i++;
359366
}
@@ -380,17 +387,17 @@ struct bch_code *bch_init(unsigned int m, unsigned int t)
380387

381388
bch = (struct bch_code *)malloc(sizeof(struct bch_code));
382389

383-
if (bch == NULL) {
390+
if (bch == NULL) {
384391
return NULL;
385392
}
386393

387394
bch->m = m;
388395
bch->t = t;
389-
bch->n = (1 << m)-1;
396+
bch->n = (1 << m) - 1;
390397
bch->ecc_words = (m * t + 31) / 32;
391398
bch->len = (bch->n + 1) / 8;
392-
bch->a_pow = bch_alloc((1 + bch->n)*sizeof(*bch->a_pow), &err);
393-
bch->a_log = bch_alloc((1 + bch->n)*sizeof(*bch->a_log), &err);
399+
bch->a_pow = bch_alloc((1 + bch->n) * sizeof(*bch->a_pow), &err);
400+
bch->a_log = bch_alloc((1 + bch->n) * sizeof(*bch->a_log), &err);
394401
bch->mod_tab = bch_alloc(bch->ecc_words * 16 * 4 * sizeof(*bch->mod_tab), &err);
395402
bch->ecc = bch_alloc(bch->ecc_words * sizeof(*bch->ecc), &err);
396403
bch->syn = bch_alloc(2 * t * sizeof(*bch->syn), &err);

0 commit comments

Comments
 (0)