V4L/DVB (9011): S2API: A number of cleanusp from the last 24 months.
[safe/jmp/linux-2.6] / drivers / mtd / mtdoops.c
index 1687521..5a680e1 100644 (file)
 #include <linux/workqueue.h>
 #include <linux/sched.h>
 #include <linux/wait.h>
+#include <linux/delay.h>
 #include <linux/spinlock.h>
+#include <linux/interrupt.h>
 #include <linux/mtd/mtd.h>
 
 #define OOPS_PAGE_SIZE 4096
 
-struct mtdoops_context {
+static struct mtdoops_context {
        int mtd_index;
        struct work_struct work_erase;
        struct work_struct work_write;
@@ -67,10 +69,7 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)
        erase.mtd = mtd;
        erase.callback = mtdoops_erase_callback;
        erase.addr = offset;
-       if (mtd->erasesize < OOPS_PAGE_SIZE)
-               erase.len = OOPS_PAGE_SIZE;
-       else
-               erase.len = mtd->erasesize;
+       erase.len = mtd->erasesize;
        erase.priv = (u_long)&wait_q;
 
        set_current_state(TASK_INTERRUPTIBLE);
@@ -186,10 +185,8 @@ badblock:
        goto badblock;
 }
 
-static void mtdoops_workfunc_write(struct work_struct *work)
+static void mtdoops_write(struct mtdoops_context *cxt, int panic)
 {
-       struct mtdoops_context *cxt =
-                       container_of(work, struct mtdoops_context, work_write);
        struct mtd_info *mtd = cxt->mtd;
        size_t retlen;
        int ret;
@@ -198,7 +195,11 @@ static void mtdoops_workfunc_write(struct work_struct *work)
                memset(cxt->oops_buf + cxt->writecount, 0xff,
                                        OOPS_PAGE_SIZE - cxt->writecount);
 
-       ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE,
+       if (panic)
+               ret = mtd->panic_write(mtd, cxt->nextpage * OOPS_PAGE_SIZE,
+                                       OOPS_PAGE_SIZE, &retlen, cxt->oops_buf);
+       else
+               ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE,
                                        OOPS_PAGE_SIZE, &retlen, cxt->oops_buf);
 
        cxt->writecount = 0;
@@ -208,6 +209,15 @@ static void mtdoops_workfunc_write(struct work_struct *work)
                        cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret);
 
        mtdoops_inc_counter(cxt);
+}
+
+
+static void mtdoops_workfunc_write(struct work_struct *work)
+{
+       struct mtdoops_context *cxt =
+                       container_of(work, struct mtdoops_context, work_write);
+
+       mtdoops_write(cxt, 0);
 }                                      
 
 static void find_next_position(struct mtdoops_context *cxt)
@@ -271,12 +281,18 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
                return;
        }
 
+       if (mtd->erasesize < OOPS_PAGE_SIZE) {
+               printk(KERN_ERR "Eraseblock size of MTD partition %d too small\n",
+                               mtd->index);
+               return;
+       }
+
        cxt->mtd = mtd;
        cxt->oops_pages = mtd->size / OOPS_PAGE_SIZE;
 
        find_next_position(cxt);
 
-       printk(KERN_DEBUG "mtdoops: Attached to MTD device %d\n", mtd->index);
+       printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index);
 }
 
 static void mtdoops_notify_remove(struct mtd_info *mtd)
@@ -311,7 +327,11 @@ static void mtdoops_console_sync(void)
        cxt->ready = 0;
        spin_unlock_irqrestore(&cxt->writecount_lock, flags);
 
-       schedule_work(&cxt->work_write);
+       if (mtd->panic_write && in_interrupt())
+               /* Interrupt context, we're going to panic so try and log */
+               mtdoops_write(cxt, 1);
+       else
+               schedule_work(&cxt->work_write);
 }
 
 static void
@@ -377,7 +397,6 @@ static struct console mtdoops_console = {
        .write          = mtdoops_console_write,
        .setup          = mtdoops_console_setup,
        .unblank        = mtdoops_console_sync,
-       .flags          = CON_PRINTBUFFER,
        .index          = -1,
        .data           = &oops_cxt,
 };
@@ -390,7 +409,7 @@ static int __init mtdoops_console_init(void)
        cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
 
        if (!cxt->oops_buf) {
-               printk(KERN_ERR "Failed to allocate oops buffer workspace\n");
+               printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n");
                return -ENOMEM;
        }