Pull acpi_device_handle_cleanup into release branch
[pandora-kernel.git] / drivers / mtd / mtdcore.c
index dade02a..168d3ba 100644 (file)
@@ -6,7 +6,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/ioctl.h>
 #include <linux/init.h>
 #include <linux/mtd/compatmac.h>
-#ifdef CONFIG_PROC_FS
 #include <linux/proc_fs.h>
-#endif
 
 #include <linux/mtd/mtd.h>
 
 /* These are exported solely for the purpose of mtd_blkdevs.c. You
    should not use them for _anything_ else */
-DECLARE_MUTEX(mtd_table_mutex);
+DEFINE_MUTEX(mtd_table_mutex);
 struct mtd_info *mtd_table[MAX_MTD_DEVICES];
 
 EXPORT_SYMBOL_GPL(mtd_table_mutex);
@@ -49,7 +46,8 @@ int add_mtd_device(struct mtd_info *mtd)
 {
        int i;
 
-       down(&mtd_table_mutex);
+       BUG_ON(mtd->writesize == 0);
+       mutex_lock(&mtd_table_mutex);
 
        for (i=0; i < MAX_MTD_DEVICES; i++)
                if (!mtd_table[i]) {
@@ -67,7 +65,7 @@ int add_mtd_device(struct mtd_info *mtd)
                                not->add(mtd);
                        }
 
-                       up(&mtd_table_mutex);
+                       mutex_unlock(&mtd_table_mutex);
                        /* We _know_ we aren't being removed, because
                           our caller is still holding us here. So none
                           of this try_ nonsense, and no bitching about it
@@ -76,7 +74,7 @@ int add_mtd_device(struct mtd_info *mtd)
                        return 0;
                }
 
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
        return 1;
 }
 
@@ -94,7 +92,7 @@ int del_mtd_device (struct mtd_info *mtd)
 {
        int ret;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
 
        if (mtd_table[mtd->index] != mtd) {
                ret = -ENODEV;
@@ -118,7 +116,7 @@ int del_mtd_device (struct mtd_info *mtd)
                ret = 0;
        }
 
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
        return ret;
 }
 
@@ -135,7 +133,7 @@ void register_mtd_user (struct mtd_notifier *new)
 {
        int i;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
 
        list_add(&new->list, &mtd_notifiers);
 
@@ -145,7 +143,7 @@ void register_mtd_user (struct mtd_notifier *new)
                if (mtd_table[i])
                        new->add(mtd_table[i]);
 
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
 }
 
 /**
@@ -162,7 +160,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
 {
        int i;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
 
        module_put(THIS_MODULE);
 
@@ -171,7 +169,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
                        old->remove(mtd_table[i]);
 
        list_del(&old->list);
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
        return 0;
 }
 
@@ -193,7 +191,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
        struct mtd_info *ret = NULL;
        int i;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
 
        if (num == -1) {
                for (i=0; i< MAX_MTD_DEVICES; i++)
@@ -211,7 +209,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
        if (ret)
                ret->usecount++;
 
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
        return ret;
 }
 
@@ -219,9 +217,9 @@ void put_mtd_device(struct mtd_info *mtd)
 {
        int c;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
        c = --mtd->usecount;
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
        BUG_ON(c < 0);
 
        module_put(mtd->owner);
@@ -256,37 +254,6 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
        return ret;
 }
 
-
-/* default_mtd_readv - default mtd readv method for MTD devices that dont
- *                    implement their own
- */
-
-int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
-                     unsigned long count, loff_t from, size_t *retlen)
-{
-       unsigned long i;
-       size_t totlen = 0, thislen;
-       int ret = 0;
-
-       if(!mtd->read) {
-               ret = -EIO;
-       } else {
-               for (i=0; i<count; i++) {
-                       if (!vecs[i].iov_len)
-                               continue;
-                       ret = mtd->read(mtd, from, vecs[i].iov_len, &thislen, vecs[i].iov_base);
-                       totlen += thislen;
-                       if (ret || thislen != vecs[i].iov_len)
-                               break;
-                       from += vecs[i].iov_len;
-               }
-       }
-       if (retlen)
-               *retlen = totlen;
-       return ret;
-}
-
-
 EXPORT_SYMBOL(add_mtd_device);
 EXPORT_SYMBOL(del_mtd_device);
 EXPORT_SYMBOL(get_mtd_device);
@@ -294,12 +261,12 @@ EXPORT_SYMBOL(put_mtd_device);
 EXPORT_SYMBOL(register_mtd_user);
 EXPORT_SYMBOL(unregister_mtd_user);
 EXPORT_SYMBOL(default_mtd_writev);
-EXPORT_SYMBOL(default_mtd_readv);
+
+#ifdef CONFIG_PROC_FS
 
 /*====================================================================*/
 /* Support for /proc/mtd */
 
-#ifdef CONFIG_PROC_FS
 static struct proc_dir_entry *proc_mtd;
 
 static inline int mtd_proc_info (char *buf, int i)
@@ -319,7 +286,7 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
        int len, l, i;
         off_t   begin = 0;
 
-       down(&mtd_table_mutex);
+       mutex_lock(&mtd_table_mutex);
 
        len = sprintf(page, "dev:    size   erasesize  name\n");
         for (i=0; i< MAX_MTD_DEVICES; i++) {
@@ -337,38 +304,34 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
         *eof = 1;
 
 done:
-       up(&mtd_table_mutex);
+       mutex_unlock(&mtd_table_mutex);
         if (off >= len+begin)
                 return 0;
         *start = page + (off-begin);
         return ((count < begin+len-off) ? count : begin+len-off);
 }
 
-#endif /* CONFIG_PROC_FS */
-
 /*====================================================================*/
 /* Init code */
 
 static int __init init_mtd(void)
 {
-#ifdef CONFIG_PROC_FS
        if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
                proc_mtd->read_proc = mtd_read_proc;
-#endif
        return 0;
 }
 
 static void __exit cleanup_mtd(void)
 {
-#ifdef CONFIG_PROC_FS
         if (proc_mtd)
                remove_proc_entry( "mtd", NULL);
-#endif
 }
 
 module_init(init_mtd);
 module_exit(cleanup_mtd);
 
+#endif /* CONFIG_PROC_FS */
+
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");