Blackfin: fix cache Kconfig typo
[safe/jmp/linux-2.6] / drivers / mtd / mtdoops.c
index 6f6b2f3..1060337 100644 (file)
@@ -44,6 +44,7 @@ static struct mtdoops_context {
        int oops_pages;
        int nextpage;
        int nextcount;
+       char *name;
 
        void *oops_buf;
 
@@ -80,9 +81,9 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)
        if (ret) {
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&wait_q, &wait);
-               printk (KERN_WARNING "mtdoops: erase of region [0x%x, 0x%x] "
+               printk (KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] "
                                     "on \"%s\" failed\n",
-                       erase.addr, erase.len, mtd->name);
+                       (unsigned long long)erase.addr, (unsigned long long)erase.len, mtd->name);
                return ret;
        }
 
@@ -258,9 +259,7 @@ static void find_next_position(struct mtdoops_context *cxt)
        if (maxcount == 0xffffffff) {
                cxt->nextpage = 0;
                cxt->nextcount = 1;
-               cxt->ready = 1;
-               printk(KERN_DEBUG "mtdoops: Ready %d, %d (first init)\n",
-                               cxt->nextpage, cxt->nextcount);
+               schedule_work(&cxt->work_erase);
                return;
        }
 
@@ -275,6 +274,9 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
 {
        struct mtdoops_context *cxt = &oops_cxt;
 
+       if (cxt->name && !strcmp(mtd->name, cxt->name))
+               cxt->mtd_index = mtd->index;
+
        if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
                return;
 
@@ -291,7 +293,10 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
        }
 
        cxt->mtd = mtd;
-       cxt->oops_pages = mtd->size / OOPS_PAGE_SIZE;
+       if (mtd->size > INT_MAX)
+               cxt->oops_pages = INT_MAX / OOPS_PAGE_SIZE;
+       else
+               cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE;
 
        find_next_position(cxt);
 
@@ -356,8 +361,10 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
        spin_lock_irqsave(&cxt->writecount_lock, flags);
 
        /* Check ready status didn't change whilst waiting for the lock */
-       if (!cxt->ready)
+       if (!cxt->ready) {
+               spin_unlock_irqrestore(&cxt->writecount_lock, flags);
                return;
+       }
 
        if (cxt->writecount == 0) {
                u32 *stamp = cxt->oops_buf;
@@ -382,8 +389,12 @@ static int __init mtdoops_console_setup(struct console *co, char *options)
 {
        struct mtdoops_context *cxt = co->data;
 
-       if (cxt->mtd_index != -1)
+       if (cxt->mtd_index != -1 || cxt->name)
                return -EBUSY;
+       if (options) {
+               cxt->name = kstrdup(options, GFP_KERNEL);
+               return 0;
+       }
        if (co->index == -1)
                return -EINVAL;
 
@@ -411,6 +422,7 @@ static int __init mtdoops_console_init(void)
 
        cxt->mtd_index = -1;
        cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
+       spin_lock_init(&cxt->writecount_lock);
 
        if (!cxt->oops_buf) {
                printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n");
@@ -431,6 +443,7 @@ static void __exit mtdoops_console_exit(void)
 
        unregister_mtd_user(&mtdoops_notifier);
        unregister_console(&mtdoops_console);
+       kfree(cxt->name);
        vfree(cxt->oops_buf);
 }