Skip to content

Commit a15b124

Browse files
Artem BityutskiyDavid Woodhouse
authored andcommitted
mtd: mtdoops: several minor cleanups
While looking into the mtdoops module, I've spotted several minor imperfections. This patch addresses them. Namely: 1. Remove several trailing white-spaces and tabs 2. Check 'vmalloc()' return code straight away, not several lines below in the 'mtdoops_console_init()' function. 3. Clean up printks - make them more consistent and use the same code formatting style for them. 4. Remove silly style of putting brackets around everything in "if" operators. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Cc: Simon Kagstrom <simon.kagstrom@netinsight.net> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 456b565 commit a15b124

1 file changed

Lines changed: 40 additions & 41 deletions

File tree

‎drivers/mtd/mtdoops.c‎

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)
8181
if (ret) {
8282
set_current_state(TASK_RUNNING);
8383
remove_wait_queue(&wait_q, &wait);
84-
printk (KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] "
85-
"on \"%s\" failed\n",
86-
(unsigned long long)erase.addr, (unsigned long long)erase.len, mtd->name);
84+
printk(KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n",
85+
(unsigned long long)erase.addr,
86+
(unsigned long long)erase.len, mtd->name);
8787
return ret;
8888
}
8989

@@ -109,10 +109,9 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)
109109

110110
ret = mtd->read(mtd, cxt->nextpage * OOPS_PAGE_SIZE, 4,
111111
&retlen, (u_char *) &count);
112-
if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) {
113-
printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)"
114-
", err %d.\n", cxt->nextpage * OOPS_PAGE_SIZE,
115-
retlen, ret);
112+
if (retlen != 4 || (ret < 0 && ret != -EUCLEAN)) {
113+
printk(KERN_ERR "mtdoops: read failure at %d (%td of 4 read), err %d\n",
114+
cxt->nextpage * OOPS_PAGE_SIZE, retlen, ret);
116115
schedule_work(&cxt->work_erase);
117116
return;
118117
}
@@ -123,8 +122,8 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)
123122
return;
124123
}
125124

126-
printk(KERN_DEBUG "mtdoops: Ready %d, %d (no erase)\n",
127-
cxt->nextpage, cxt->nextcount);
125+
printk(KERN_DEBUG "mtdoops: ready %d, %d (no erase)\n",
126+
cxt->nextpage, cxt->nextcount);
128127
cxt->ready = 1;
129128
}
130129

@@ -152,18 +151,18 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
152151
if (!ret)
153152
break;
154153
if (ret < 0) {
155-
printk(KERN_ERR "mtdoops: block_isbad failed, aborting.\n");
154+
printk(KERN_ERR "mtdoops: block_isbad failed, aborting\n");
156155
return;
157156
}
158157
badblock:
159-
printk(KERN_WARNING "mtdoops: Bad block at %08x\n",
160-
cxt->nextpage * OOPS_PAGE_SIZE);
158+
printk(KERN_WARNING "mtdoops: bad block at %08x\n",
159+
cxt->nextpage * OOPS_PAGE_SIZE);
161160
i++;
162161
cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE);
163162
if (cxt->nextpage >= cxt->oops_pages)
164163
cxt->nextpage = 0;
165-
if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) {
166-
printk(KERN_ERR "mtdoops: All blocks bad!\n");
164+
if (i == cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE)) {
165+
printk(KERN_ERR "mtdoops: all blocks bad!\n");
167166
return;
168167
}
169168
}
@@ -172,15 +171,16 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
172171
ret = mtdoops_erase_block(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
173172

174173
if (ret >= 0) {
175-
printk(KERN_DEBUG "mtdoops: Ready %d, %d \n", cxt->nextpage, cxt->nextcount);
174+
printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
175+
cxt->nextpage, cxt->nextcount);
176176
cxt->ready = 1;
177177
return;
178178
}
179179

180-
if (mtd->block_markbad && (ret == -EIO)) {
180+
if (mtd->block_markbad && ret == -EIO) {
181181
ret = mtd->block_markbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
182182
if (ret < 0) {
183-
printk(KERN_ERR "mtdoops: block_markbad failed, aborting.\n");
183+
printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n");
184184
return;
185185
}
186186
}
@@ -206,9 +206,9 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)
206206

207207
cxt->writecount = 0;
208208

209-
if ((retlen != OOPS_PAGE_SIZE) || (ret < 0))
210-
printk(KERN_ERR "mtdoops: Write failure at %d (%td of %d written), err %d.\n",
211-
cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret);
209+
if (retlen != OOPS_PAGE_SIZE || ret < 0)
210+
printk(KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n",
211+
cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret);
212212

213213
mtdoops_inc_counter(cxt);
214214
}
@@ -220,7 +220,7 @@ static void mtdoops_workfunc_write(struct work_struct *work)
220220
container_of(work, struct mtdoops_context, work_write);
221221

222222
mtdoops_write(cxt, 0);
223-
}
223+
}
224224

225225
static void find_next_position(struct mtdoops_context *cxt)
226226
{
@@ -231,9 +231,9 @@ static void find_next_position(struct mtdoops_context *cxt)
231231

232232
for (page = 0; page < cxt->oops_pages; page++) {
233233
ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]);
234-
if ((retlen != 8) || ((ret < 0) && (ret != -EUCLEAN))) {
235-
printk(KERN_ERR "mtdoops: Read failure at %d (%td of 8 read)"
236-
", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret);
234+
if (retlen != 8 || (ret < 0 && ret != -EUCLEAN)) {
235+
printk(KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n",
236+
page * OOPS_PAGE_SIZE, retlen, ret);
237237
continue;
238238
}
239239

@@ -244,14 +244,14 @@ static void find_next_position(struct mtdoops_context *cxt)
244244
if (maxcount == 0xffffffff) {
245245
maxcount = count[0];
246246
maxpos = page;
247-
} else if ((count[0] < 0x40000000) && (maxcount > 0xc0000000)) {
247+
} else if (count[0] < 0x40000000 && maxcount > 0xc0000000) {
248248
maxcount = count[0];
249249
maxpos = page;
250-
} else if ((count[0] > maxcount) && (count[0] < 0xc0000000)) {
250+
} else if (count[0] > maxcount && count[0] < 0xc0000000) {
251251
maxcount = count[0];
252252
maxpos = page;
253-
} else if ((count[0] > maxcount) && (count[0] > 0xc0000000)
254-
&& (maxcount > 0x80000000)) {
253+
} else if (count[0] > maxcount && count[0] > 0xc0000000
254+
&& maxcount > 0x80000000) {
255255
maxcount = count[0];
256256
maxpos = page;
257257
}
@@ -277,18 +277,18 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
277277
if (cxt->name && !strcmp(mtd->name, cxt->name))
278278
cxt->mtd_index = mtd->index;
279279

280-
if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
280+
if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0)
281281
return;
282282

283-
if (mtd->size < (mtd->erasesize * 2)) {
284-
printk(KERN_ERR "MTD partition %d not big enough for mtdoops\n",
285-
mtd->index);
283+
if (mtd->size < mtd->erasesize * 2) {
284+
printk(KERN_ERR "mtdoops: MTD partition %d not big enough for mtdoops\n",
285+
mtd->index);
286286
return;
287287
}
288288

289289
if (mtd->erasesize < OOPS_PAGE_SIZE) {
290-
printk(KERN_ERR "Eraseblock size of MTD partition %d too small\n",
291-
mtd->index);
290+
printk(KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n",
291+
mtd->index);
292292
return;
293293
}
294294

@@ -307,7 +307,7 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)
307307
{
308308
struct mtdoops_context *cxt = &oops_cxt;
309309

310-
if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
310+
if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0)
311311
return;
312312

313313
cxt->mtd = NULL;
@@ -323,8 +323,8 @@ static void mtdoops_console_sync(void)
323323
if (!cxt->ready || !mtd || cxt->writecount == 0)
324324
return;
325325

326-
/*
327-
* Once ready is 0 and we've held the lock no further writes to the
326+
/*
327+
* Once ready is 0 and we've held the lock no further writes to the
328328
* buffer will happen
329329
*/
330330
spin_lock_irqsave(&cxt->writecount_lock, flags);
@@ -373,7 +373,7 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
373373
cxt->writecount = 8;
374374
}
375375

376-
if ((count + cxt->writecount) > OOPS_PAGE_SIZE)
376+
if (count + cxt->writecount > OOPS_PAGE_SIZE)
377377
count = OOPS_PAGE_SIZE - cxt->writecount;
378378

379379
memcpy(cxt->oops_buf + cxt->writecount, s, count);
@@ -422,13 +422,12 @@ static int __init mtdoops_console_init(void)
422422

423423
cxt->mtd_index = -1;
424424
cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
425-
spin_lock_init(&cxt->writecount_lock);
426-
427425
if (!cxt->oops_buf) {
428-
printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n");
426+
printk(KERN_ERR "mtdoops: failed to allocate buffer workspace\n");
429427
return -ENOMEM;
430428
}
431429

430+
spin_lock_init(&cxt->writecount_lock);
432431
INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase);
433432
INIT_WORK(&cxt->work_write, mtdoops_workfunc_write);
434433

0 commit comments

Comments
 (0)