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>
This commit is contained in:
committed by
David Woodhouse
parent
456b565cc5
commit
a15b124fc4
@@ -81,9 +81,9 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
set_current_state(TASK_RUNNING);
|
set_current_state(TASK_RUNNING);
|
||||||
remove_wait_queue(&wait_q, &wait);
|
remove_wait_queue(&wait_q, &wait);
|
||||||
printk (KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] "
|
printk(KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n",
|
||||||
"on \"%s\" failed\n",
|
(unsigned long long)erase.addr,
|
||||||
(unsigned long long)erase.addr, (unsigned long long)erase.len, mtd->name);
|
(unsigned long long)erase.len, mtd->name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +109,9 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)
|
|||||||
|
|
||||||
ret = mtd->read(mtd, cxt->nextpage * OOPS_PAGE_SIZE, 4,
|
ret = mtd->read(mtd, cxt->nextpage * OOPS_PAGE_SIZE, 4,
|
||||||
&retlen, (u_char *) &count);
|
&retlen, (u_char *) &count);
|
||||||
if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) {
|
if (retlen != 4 || (ret < 0 && ret != -EUCLEAN)) {
|
||||||
printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)"
|
printk(KERN_ERR "mtdoops: read failure at %d (%td of 4 read), err %d\n",
|
||||||
", err %d.\n", cxt->nextpage * OOPS_PAGE_SIZE,
|
cxt->nextpage * OOPS_PAGE_SIZE, retlen, ret);
|
||||||
retlen, ret);
|
|
||||||
schedule_work(&cxt->work_erase);
|
schedule_work(&cxt->work_erase);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,8 +122,8 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_DEBUG "mtdoops: Ready %d, %d (no erase)\n",
|
printk(KERN_DEBUG "mtdoops: ready %d, %d (no erase)\n",
|
||||||
cxt->nextpage, cxt->nextcount);
|
cxt->nextpage, cxt->nextcount);
|
||||||
cxt->ready = 1;
|
cxt->ready = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,18 +151,18 @@ static void mtdoops_workfunc_erase(struct work_struct *work)
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
break;
|
break;
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printk(KERN_ERR "mtdoops: block_isbad failed, aborting.\n");
|
printk(KERN_ERR "mtdoops: block_isbad failed, aborting\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
badblock:
|
badblock:
|
||||||
printk(KERN_WARNING "mtdoops: Bad block at %08x\n",
|
printk(KERN_WARNING "mtdoops: bad block at %08x\n",
|
||||||
cxt->nextpage * OOPS_PAGE_SIZE);
|
cxt->nextpage * OOPS_PAGE_SIZE);
|
||||||
i++;
|
i++;
|
||||||
cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE);
|
cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE);
|
||||||
if (cxt->nextpage >= cxt->oops_pages)
|
if (cxt->nextpage >= cxt->oops_pages)
|
||||||
cxt->nextpage = 0;
|
cxt->nextpage = 0;
|
||||||
if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) {
|
if (i == cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE)) {
|
||||||
printk(KERN_ERR "mtdoops: All blocks bad!\n");
|
printk(KERN_ERR "mtdoops: all blocks bad!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,15 +171,16 @@ badblock:
|
|||||||
ret = mtdoops_erase_block(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
|
ret = mtdoops_erase_block(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
|
||||||
|
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
printk(KERN_DEBUG "mtdoops: Ready %d, %d \n", cxt->nextpage, cxt->nextcount);
|
printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
|
||||||
|
cxt->nextpage, cxt->nextcount);
|
||||||
cxt->ready = 1;
|
cxt->ready = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtd->block_markbad && (ret == -EIO)) {
|
if (mtd->block_markbad && ret == -EIO) {
|
||||||
ret = mtd->block_markbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
|
ret = mtd->block_markbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printk(KERN_ERR "mtdoops: block_markbad failed, aborting.\n");
|
printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,9 +206,9 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)
|
|||||||
|
|
||||||
cxt->writecount = 0;
|
cxt->writecount = 0;
|
||||||
|
|
||||||
if ((retlen != OOPS_PAGE_SIZE) || (ret < 0))
|
if (retlen != OOPS_PAGE_SIZE || ret < 0)
|
||||||
printk(KERN_ERR "mtdoops: Write failure at %d (%td of %d written), err %d.\n",
|
printk(KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n",
|
||||||
cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret);
|
cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret);
|
||||||
|
|
||||||
mtdoops_inc_counter(cxt);
|
mtdoops_inc_counter(cxt);
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ static void mtdoops_workfunc_write(struct work_struct *work)
|
|||||||
container_of(work, struct mtdoops_context, work_write);
|
container_of(work, struct mtdoops_context, work_write);
|
||||||
|
|
||||||
mtdoops_write(cxt, 0);
|
mtdoops_write(cxt, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void find_next_position(struct mtdoops_context *cxt)
|
static void find_next_position(struct mtdoops_context *cxt)
|
||||||
{
|
{
|
||||||
@@ -231,9 +231,9 @@ static void find_next_position(struct mtdoops_context *cxt)
|
|||||||
|
|
||||||
for (page = 0; page < cxt->oops_pages; page++) {
|
for (page = 0; page < cxt->oops_pages; page++) {
|
||||||
ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]);
|
ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]);
|
||||||
if ((retlen != 8) || ((ret < 0) && (ret != -EUCLEAN))) {
|
if (retlen != 8 || (ret < 0 && ret != -EUCLEAN)) {
|
||||||
printk(KERN_ERR "mtdoops: Read failure at %d (%td of 8 read)"
|
printk(KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n",
|
||||||
", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret);
|
page * OOPS_PAGE_SIZE, retlen, ret);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,14 +244,14 @@ static void find_next_position(struct mtdoops_context *cxt)
|
|||||||
if (maxcount == 0xffffffff) {
|
if (maxcount == 0xffffffff) {
|
||||||
maxcount = count[0];
|
maxcount = count[0];
|
||||||
maxpos = page;
|
maxpos = page;
|
||||||
} else if ((count[0] < 0x40000000) && (maxcount > 0xc0000000)) {
|
} else if (count[0] < 0x40000000 && maxcount > 0xc0000000) {
|
||||||
maxcount = count[0];
|
maxcount = count[0];
|
||||||
maxpos = page;
|
maxpos = page;
|
||||||
} else if ((count[0] > maxcount) && (count[0] < 0xc0000000)) {
|
} else if (count[0] > maxcount && count[0] < 0xc0000000) {
|
||||||
maxcount = count[0];
|
maxcount = count[0];
|
||||||
maxpos = page;
|
maxpos = page;
|
||||||
} else if ((count[0] > maxcount) && (count[0] > 0xc0000000)
|
} else if (count[0] > maxcount && count[0] > 0xc0000000
|
||||||
&& (maxcount > 0x80000000)) {
|
&& maxcount > 0x80000000) {
|
||||||
maxcount = count[0];
|
maxcount = count[0];
|
||||||
maxpos = page;
|
maxpos = page;
|
||||||
}
|
}
|
||||||
@@ -277,18 +277,18 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
|
|||||||
if (cxt->name && !strcmp(mtd->name, cxt->name))
|
if (cxt->name && !strcmp(mtd->name, cxt->name))
|
||||||
cxt->mtd_index = mtd->index;
|
cxt->mtd_index = mtd->index;
|
||||||
|
|
||||||
if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
|
if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mtd->size < (mtd->erasesize * 2)) {
|
if (mtd->size < mtd->erasesize * 2) {
|
||||||
printk(KERN_ERR "MTD partition %d not big enough for mtdoops\n",
|
printk(KERN_ERR "mtdoops: MTD partition %d not big enough for mtdoops\n",
|
||||||
mtd->index);
|
mtd->index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtd->erasesize < OOPS_PAGE_SIZE) {
|
if (mtd->erasesize < OOPS_PAGE_SIZE) {
|
||||||
printk(KERN_ERR "Eraseblock size of MTD partition %d too small\n",
|
printk(KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n",
|
||||||
mtd->index);
|
mtd->index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)
|
|||||||
{
|
{
|
||||||
struct mtdoops_context *cxt = &oops_cxt;
|
struct mtdoops_context *cxt = &oops_cxt;
|
||||||
|
|
||||||
if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
|
if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cxt->mtd = NULL;
|
cxt->mtd = NULL;
|
||||||
@@ -323,8 +323,8 @@ static void mtdoops_console_sync(void)
|
|||||||
if (!cxt->ready || !mtd || cxt->writecount == 0)
|
if (!cxt->ready || !mtd || cxt->writecount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Once ready is 0 and we've held the lock no further writes to the
|
* Once ready is 0 and we've held the lock no further writes to the
|
||||||
* buffer will happen
|
* buffer will happen
|
||||||
*/
|
*/
|
||||||
spin_lock_irqsave(&cxt->writecount_lock, flags);
|
spin_lock_irqsave(&cxt->writecount_lock, flags);
|
||||||
@@ -373,7 +373,7 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
|
|||||||
cxt->writecount = 8;
|
cxt->writecount = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((count + cxt->writecount) > OOPS_PAGE_SIZE)
|
if (count + cxt->writecount > OOPS_PAGE_SIZE)
|
||||||
count = OOPS_PAGE_SIZE - cxt->writecount;
|
count = OOPS_PAGE_SIZE - cxt->writecount;
|
||||||
|
|
||||||
memcpy(cxt->oops_buf + cxt->writecount, s, count);
|
memcpy(cxt->oops_buf + cxt->writecount, s, count);
|
||||||
@@ -422,13 +422,12 @@ static int __init mtdoops_console_init(void)
|
|||||||
|
|
||||||
cxt->mtd_index = -1;
|
cxt->mtd_index = -1;
|
||||||
cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
|
cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
|
||||||
spin_lock_init(&cxt->writecount_lock);
|
|
||||||
|
|
||||||
if (!cxt->oops_buf) {
|
if (!cxt->oops_buf) {
|
||||||
printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n");
|
printk(KERN_ERR "mtdoops: failed to allocate buffer workspace\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spin_lock_init(&cxt->writecount_lock);
|
||||||
INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase);
|
INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase);
|
||||||
INIT_WORK(&cxt->work_write, mtdoops_workfunc_write);
|
INIT_WORK(&cxt->work_write, mtdoops_workfunc_write);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user