2 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <linux/device.h>
23 #include <linux/err.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/sched.h>
29 #include <linux/smp_lock.h>
30 #include <linux/backing-dev.h>
31 #include <linux/compat.h>
32 #include <linux/mount.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/map.h>
37 #include <asm/uaccess.h>
39 #define MTD_INODE_FS_MAGIC 0x11307854
40 static struct vfsmount
*mtd_inode_mnt __read_mostly
;
43 * Data structure to hold the pointer to the mtd device as well
44 * as mode information ofr various use cases.
46 struct mtd_file_info
{
49 enum mtd_file_modes mode
;
52 static loff_t
mtd_lseek (struct file
*file
, loff_t offset
, int orig
)
54 struct mtd_file_info
*mfi
= file
->private_data
;
55 struct mtd_info
*mtd
= mfi
->mtd
;
61 offset
+= file
->f_pos
;
70 if (offset
>= 0 && offset
<= mtd
->size
)
71 return file
->f_pos
= offset
;
78 static int mtd_open(struct inode
*inode
, struct file
*file
)
80 int minor
= iminor(inode
);
81 int devnum
= minor
>> 1;
84 struct mtd_file_info
*mfi
;
85 struct inode
*mtd_ino
;
87 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_open\n");
89 /* You can't open the RO devices RW */
90 if ((file
->f_mode
& FMODE_WRITE
) && (minor
& 1))
94 mtd
= get_mtd_device(NULL
, devnum
);
101 if (mtd
->type
== MTD_ABSENT
) {
107 mtd_ino
= iget_locked(mtd_inode_mnt
->mnt_sb
, devnum
);
113 if (mtd_ino
->i_state
& I_NEW
) {
114 mtd_ino
->i_private
= mtd
;
115 mtd_ino
->i_mode
= S_IFCHR
;
116 mtd_ino
->i_data
.backing_dev_info
= mtd
->backing_dev_info
;
117 unlock_new_inode(mtd_ino
);
119 file
->f_mapping
= mtd_ino
->i_mapping
;
121 /* You can't open it RW if it's not a writeable device */
122 if ((file
->f_mode
& FMODE_WRITE
) && !(mtd
->flags
& MTD_WRITEABLE
)) {
129 mfi
= kzalloc(sizeof(*mfi
), GFP_KERNEL
);
138 file
->private_data
= mfi
;
145 /*====================================================================*/
147 static int mtd_close(struct inode
*inode
, struct file
*file
)
149 struct mtd_file_info
*mfi
= file
->private_data
;
150 struct mtd_info
*mtd
= mfi
->mtd
;
152 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_close\n");
154 /* Only sync if opened RW */
155 if ((file
->f_mode
& FMODE_WRITE
) && mtd
->sync
)
161 file
->private_data
= NULL
;
167 #define MAX_KMALLOC_SIZE 0x20000
169 static ssize_t
mtd_read(struct file
*file
, char __user
*buf
, size_t count
,loff_t
*ppos
)
171 struct mtd_file_info
*mfi
= file
->private_data
;
172 struct mtd_info
*mtd
= mfi
->mtd
;
174 size_t total_retlen
=0;
179 DEBUG(MTD_DEBUG_LEVEL0
,"MTD_read\n");
181 if (*ppos
+ count
> mtd
->size
)
182 count
= mtd
->size
- *ppos
;
188 if (count
> MAX_KMALLOC_SIZE
)
189 kbuf
=kmalloc(MAX_KMALLOC_SIZE
, GFP_KERNEL
);
191 kbuf
=kmalloc(count
, GFP_KERNEL
);
198 if (count
> MAX_KMALLOC_SIZE
)
199 len
= MAX_KMALLOC_SIZE
;
204 case MTD_MODE_OTP_FACTORY
:
205 ret
= mtd
->read_fact_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
207 case MTD_MODE_OTP_USER
:
208 ret
= mtd
->read_user_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
212 struct mtd_oob_ops ops
;
214 ops
.mode
= MTD_OOB_RAW
;
219 ret
= mtd
->read_oob(mtd
, *ppos
, &ops
);
224 ret
= mtd
->read(mtd
, *ppos
, len
, &retlen
, kbuf
);
226 /* Nand returns -EBADMSG on ecc errors, but it returns
227 * the data. For our userspace tools it is important
228 * to dump areas with ecc errors !
229 * For kernel internal usage it also might return -EUCLEAN
230 * to signal the caller that a bitflip has occured and has
231 * been corrected by the ECC algorithm.
232 * Userspace software which accesses NAND this way
233 * must be aware of the fact that it deals with NAND
235 if (!ret
|| (ret
== -EUCLEAN
) || (ret
== -EBADMSG
)) {
237 if (copy_to_user(buf
, kbuf
, retlen
)) {
242 total_retlen
+= retlen
;
260 static ssize_t
mtd_write(struct file
*file
, const char __user
*buf
, size_t count
,loff_t
*ppos
)
262 struct mtd_file_info
*mfi
= file
->private_data
;
263 struct mtd_info
*mtd
= mfi
->mtd
;
266 size_t total_retlen
=0;
270 DEBUG(MTD_DEBUG_LEVEL0
,"MTD_write\n");
272 if (*ppos
== mtd
->size
)
275 if (*ppos
+ count
> mtd
->size
)
276 count
= mtd
->size
- *ppos
;
281 if (count
> MAX_KMALLOC_SIZE
)
282 kbuf
=kmalloc(MAX_KMALLOC_SIZE
, GFP_KERNEL
);
284 kbuf
=kmalloc(count
, GFP_KERNEL
);
291 if (count
> MAX_KMALLOC_SIZE
)
292 len
= MAX_KMALLOC_SIZE
;
296 if (copy_from_user(kbuf
, buf
, len
)) {
302 case MTD_MODE_OTP_FACTORY
:
305 case MTD_MODE_OTP_USER
:
306 if (!mtd
->write_user_prot_reg
) {
310 ret
= mtd
->write_user_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
315 struct mtd_oob_ops ops
;
317 ops
.mode
= MTD_OOB_RAW
;
322 ret
= mtd
->write_oob(mtd
, *ppos
, &ops
);
328 ret
= (*(mtd
->write
))(mtd
, *ppos
, len
, &retlen
, kbuf
);
332 total_retlen
+= retlen
;
346 /*======================================================================
348 IOCTL calls for getting device parameters.
350 ======================================================================*/
351 static void mtdchar_erase_callback (struct erase_info
*instr
)
353 wake_up((wait_queue_head_t
*)instr
->priv
);
356 #ifdef CONFIG_HAVE_MTD_OTP
357 static int otp_select_filemode(struct mtd_file_info
*mfi
, int mode
)
359 struct mtd_info
*mtd
= mfi
->mtd
;
363 case MTD_OTP_FACTORY
:
364 if (!mtd
->read_fact_prot_reg
)
367 mfi
->mode
= MTD_MODE_OTP_FACTORY
;
370 if (!mtd
->read_fact_prot_reg
)
373 mfi
->mode
= MTD_MODE_OTP_USER
;
383 # define otp_select_filemode(f,m) -EOPNOTSUPP
386 static int mtd_do_writeoob(struct file
*file
, struct mtd_info
*mtd
,
387 uint64_t start
, uint32_t length
, void __user
*ptr
,
388 uint32_t __user
*retp
)
390 struct mtd_oob_ops ops
;
394 if (!(file
->f_mode
& FMODE_WRITE
))
403 ret
= access_ok(VERIFY_READ
, ptr
, length
) ? 0 : -EFAULT
;
409 ops
.ooboffs
= start
& (mtd
->oobsize
- 1);
411 ops
.mode
= MTD_OOB_PLACE
;
413 if (ops
.ooboffs
&& ops
.ooblen
> (mtd
->oobsize
- ops
.ooboffs
))
416 ops
.oobbuf
= memdup_user(ptr
, length
);
417 if (IS_ERR(ops
.oobbuf
))
418 return PTR_ERR(ops
.oobbuf
);
420 start
&= ~((uint64_t)mtd
->oobsize
- 1);
421 ret
= mtd
->write_oob(mtd
, start
, &ops
);
423 if (ops
.oobretlen
> 0xFFFFFFFFU
)
425 retlen
= ops
.oobretlen
;
426 if (copy_to_user(retp
, &retlen
, sizeof(length
)))
433 static int mtd_do_readoob(struct mtd_info
*mtd
, uint64_t start
,
434 uint32_t length
, void __user
*ptr
, uint32_t __user
*retp
)
436 struct mtd_oob_ops ops
;
445 ret
= access_ok(VERIFY_WRITE
, ptr
,
446 length
) ? 0 : -EFAULT
;
451 ops
.ooboffs
= start
& (mtd
->oobsize
- 1);
453 ops
.mode
= MTD_OOB_PLACE
;
455 if (ops
.ooboffs
&& ops
.ooblen
> (mtd
->oobsize
- ops
.ooboffs
))
458 ops
.oobbuf
= kmalloc(length
, GFP_KERNEL
);
462 start
&= ~((uint64_t)mtd
->oobsize
- 1);
463 ret
= mtd
->read_oob(mtd
, start
, &ops
);
465 if (put_user(ops
.oobretlen
, retp
))
467 else if (ops
.oobretlen
&& copy_to_user(ptr
, ops
.oobbuf
,
475 static int mtd_ioctl(struct file
*file
, u_int cmd
, u_long arg
)
477 struct mtd_file_info
*mfi
= file
->private_data
;
478 struct mtd_info
*mtd
= mfi
->mtd
;
479 void __user
*argp
= (void __user
*)arg
;
482 struct mtd_info_user info
;
484 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_ioctl\n");
486 size
= (cmd
& IOCSIZE_MASK
) >> IOCSIZE_SHIFT
;
488 if (!access_ok(VERIFY_READ
, argp
, size
))
492 if (!access_ok(VERIFY_WRITE
, argp
, size
))
497 case MEMGETREGIONCOUNT
:
498 if (copy_to_user(argp
, &(mtd
->numeraseregions
), sizeof(int)))
502 case MEMGETREGIONINFO
:
505 struct mtd_erase_region_info
*kr
;
506 struct region_info_user __user
*ur
= argp
;
508 if (get_user(ur_idx
, &(ur
->regionindex
)))
511 kr
= &(mtd
->eraseregions
[ur_idx
]);
513 if (put_user(kr
->offset
, &(ur
->offset
))
514 || put_user(kr
->erasesize
, &(ur
->erasesize
))
515 || put_user(kr
->numblocks
, &(ur
->numblocks
)))
522 info
.type
= mtd
->type
;
523 info
.flags
= mtd
->flags
;
524 info
.size
= mtd
->size
;
525 info
.erasesize
= mtd
->erasesize
;
526 info
.writesize
= mtd
->writesize
;
527 info
.oobsize
= mtd
->oobsize
;
528 /* The below fields are obsolete */
531 if (copy_to_user(argp
, &info
, sizeof(struct mtd_info_user
)))
538 struct erase_info
*erase
;
540 if(!(file
->f_mode
& FMODE_WRITE
))
543 erase
=kzalloc(sizeof(struct erase_info
),GFP_KERNEL
);
547 wait_queue_head_t waitq
;
548 DECLARE_WAITQUEUE(wait
, current
);
550 init_waitqueue_head(&waitq
);
552 if (cmd
== MEMERASE64
) {
553 struct erase_info_user64 einfo64
;
555 if (copy_from_user(&einfo64
, argp
,
556 sizeof(struct erase_info_user64
))) {
560 erase
->addr
= einfo64
.start
;
561 erase
->len
= einfo64
.length
;
563 struct erase_info_user einfo32
;
565 if (copy_from_user(&einfo32
, argp
,
566 sizeof(struct erase_info_user
))) {
570 erase
->addr
= einfo32
.start
;
571 erase
->len
= einfo32
.length
;
574 erase
->callback
= mtdchar_erase_callback
;
575 erase
->priv
= (unsigned long)&waitq
;
577 ret
= mtd
->erase(mtd
, erase
);
579 set_current_state(TASK_UNINTERRUPTIBLE
);
580 add_wait_queue(&waitq
, &wait
);
581 if (erase
->state
!= MTD_ERASE_DONE
&&
582 erase
->state
!= MTD_ERASE_FAILED
)
584 remove_wait_queue(&waitq
, &wait
);
585 set_current_state(TASK_RUNNING
);
587 ret
= (erase
->state
== MTD_ERASE_FAILED
)?-EIO
:0;
596 struct mtd_oob_buf buf
;
597 struct mtd_oob_buf __user
*buf_user
= argp
;
599 /* NOTE: writes return length to buf_user->length */
600 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
603 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
, buf
.length
,
604 buf
.ptr
, &buf_user
->length
);
610 struct mtd_oob_buf buf
;
611 struct mtd_oob_buf __user
*buf_user
= argp
;
613 /* NOTE: writes return length to buf_user->start */
614 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
617 ret
= mtd_do_readoob(mtd
, buf
.start
, buf
.length
,
618 buf
.ptr
, &buf_user
->start
);
624 struct mtd_oob_buf64 buf
;
625 struct mtd_oob_buf64 __user
*buf_user
= argp
;
627 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
630 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
, buf
.length
,
631 (void __user
*)(uintptr_t)buf
.usr_ptr
,
638 struct mtd_oob_buf64 buf
;
639 struct mtd_oob_buf64 __user
*buf_user
= argp
;
641 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
644 ret
= mtd_do_readoob(mtd
, buf
.start
, buf
.length
,
645 (void __user
*)(uintptr_t)buf
.usr_ptr
,
652 struct erase_info_user einfo
;
654 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
660 ret
= mtd
->lock(mtd
, einfo
.start
, einfo
.length
);
666 struct erase_info_user einfo
;
668 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
674 ret
= mtd
->unlock(mtd
, einfo
.start
, einfo
.length
);
680 struct erase_info_user einfo
;
682 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
688 ret
= mtd
->is_locked(mtd
, einfo
.start
, einfo
.length
);
692 /* Legacy interface */
695 struct nand_oobinfo oi
;
699 if (mtd
->ecclayout
->eccbytes
> ARRAY_SIZE(oi
.eccpos
))
702 oi
.useecc
= MTD_NANDECC_AUTOPLACE
;
703 memcpy(&oi
.eccpos
, mtd
->ecclayout
->eccpos
, sizeof(oi
.eccpos
));
704 memcpy(&oi
.oobfree
, mtd
->ecclayout
->oobfree
,
706 oi
.eccbytes
= mtd
->ecclayout
->eccbytes
;
708 if (copy_to_user(argp
, &oi
, sizeof(struct nand_oobinfo
)))
717 if (copy_from_user(&offs
, argp
, sizeof(loff_t
)))
719 if (!mtd
->block_isbad
)
722 return mtd
->block_isbad(mtd
, offs
);
730 if (copy_from_user(&offs
, argp
, sizeof(loff_t
)))
732 if (!mtd
->block_markbad
)
735 return mtd
->block_markbad(mtd
, offs
);
739 #ifdef CONFIG_HAVE_MTD_OTP
743 if (copy_from_user(&mode
, argp
, sizeof(int)))
746 mfi
->mode
= MTD_MODE_NORMAL
;
748 ret
= otp_select_filemode(mfi
, mode
);
754 case OTPGETREGIONCOUNT
:
755 case OTPGETREGIONINFO
:
757 struct otp_info
*buf
= kmalloc(4096, GFP_KERNEL
);
762 case MTD_MODE_OTP_FACTORY
:
763 if (mtd
->get_fact_prot_info
)
764 ret
= mtd
->get_fact_prot_info(mtd
, buf
, 4096);
766 case MTD_MODE_OTP_USER
:
767 if (mtd
->get_user_prot_info
)
768 ret
= mtd
->get_user_prot_info(mtd
, buf
, 4096);
774 if (cmd
== OTPGETREGIONCOUNT
) {
775 int nbr
= ret
/ sizeof(struct otp_info
);
776 ret
= copy_to_user(argp
, &nbr
, sizeof(int));
778 ret
= copy_to_user(argp
, buf
, ret
);
788 struct otp_info oinfo
;
790 if (mfi
->mode
!= MTD_MODE_OTP_USER
)
792 if (copy_from_user(&oinfo
, argp
, sizeof(oinfo
)))
794 if (!mtd
->lock_user_prot_reg
)
796 ret
= mtd
->lock_user_prot_reg(mtd
, oinfo
.start
, oinfo
.length
);
806 if (copy_to_user(argp
, mtd
->ecclayout
,
807 sizeof(struct nand_ecclayout
)))
814 if (copy_to_user(argp
, &mtd
->ecc_stats
,
815 sizeof(struct mtd_ecc_stats
)))
825 case MTD_MODE_OTP_FACTORY
:
826 case MTD_MODE_OTP_USER
:
827 ret
= otp_select_filemode(mfi
, arg
);
831 if (!mtd
->read_oob
|| !mtd
->write_oob
)
835 case MTD_MODE_NORMAL
:
851 static long mtd_unlocked_ioctl(struct file
*file
, u_int cmd
, u_long arg
)
856 ret
= mtd_ioctl(file
, cmd
, arg
);
864 struct mtd_oob_buf32
{
867 compat_caddr_t ptr
; /* unsigned char* */
870 #define MEMWRITEOOB32 _IOWR('M', 3, struct mtd_oob_buf32)
871 #define MEMREADOOB32 _IOWR('M', 4, struct mtd_oob_buf32)
873 static long mtd_compat_ioctl(struct file
*file
, unsigned int cmd
,
876 struct mtd_file_info
*mfi
= file
->private_data
;
877 struct mtd_info
*mtd
= mfi
->mtd
;
878 void __user
*argp
= compat_ptr(arg
);
886 struct mtd_oob_buf32 buf
;
887 struct mtd_oob_buf32 __user
*buf_user
= argp
;
889 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
892 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
,
893 buf
.length
, compat_ptr(buf
.ptr
),
900 struct mtd_oob_buf32 buf
;
901 struct mtd_oob_buf32 __user
*buf_user
= argp
;
903 /* NOTE: writes return length to buf->start */
904 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
907 ret
= mtd_do_readoob(mtd
, buf
.start
,
908 buf
.length
, compat_ptr(buf
.ptr
),
913 ret
= mtd_ioctl(file
, cmd
, (unsigned long)argp
);
921 #endif /* CONFIG_COMPAT */
924 * try to determine where a shared mapping can be made
925 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
929 static unsigned long mtd_get_unmapped_area(struct file
*file
,
935 struct mtd_file_info
*mfi
= file
->private_data
;
936 struct mtd_info
*mtd
= mfi
->mtd
;
938 if (mtd
->get_unmapped_area
) {
939 unsigned long offset
;
942 return (unsigned long) -EINVAL
;
944 if (len
> mtd
->size
|| pgoff
>= (mtd
->size
>> PAGE_SHIFT
))
945 return (unsigned long) -EINVAL
;
947 offset
= pgoff
<< PAGE_SHIFT
;
948 if (offset
> mtd
->size
- len
)
949 return (unsigned long) -EINVAL
;
951 return mtd
->get_unmapped_area(mtd
, len
, offset
, flags
);
954 /* can't map directly */
955 return (unsigned long) -ENOSYS
;
960 * set up a mapping for shared memory segments
962 static int mtd_mmap(struct file
*file
, struct vm_area_struct
*vma
)
965 struct mtd_file_info
*mfi
= file
->private_data
;
966 struct mtd_info
*mtd
= mfi
->mtd
;
967 struct map_info
*map
= mtd
->priv
;
972 if (mtd
->type
== MTD_RAM
|| mtd
->type
== MTD_ROM
) {
973 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
975 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + map
->size
);
977 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
981 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
982 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
984 #ifdef pgprot_noncached
985 if (file
->f_flags
& O_DSYNC
|| off
>= __pa(high_memory
))
986 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
988 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
989 vma
->vm_end
- vma
->vm_start
,
997 return vma
->vm_flags
& VM_SHARED
? 0 : -ENOSYS
;
1001 static const struct file_operations mtd_fops
= {
1002 .owner
= THIS_MODULE
,
1003 .llseek
= mtd_lseek
,
1006 .unlocked_ioctl
= mtd_unlocked_ioctl
,
1007 #ifdef CONFIG_COMPAT
1008 .compat_ioctl
= mtd_compat_ioctl
,
1011 .release
= mtd_close
,
1014 .get_unmapped_area
= mtd_get_unmapped_area
,
1018 static int mtd_inodefs_get_sb(struct file_system_type
*fs_type
, int flags
,
1019 const char *dev_name
, void *data
,
1020 struct vfsmount
*mnt
)
1022 return get_sb_pseudo(fs_type
, "mtd_inode:", NULL
, MTD_INODE_FS_MAGIC
,
1026 static struct file_system_type mtd_inodefs_type
= {
1027 .name
= "mtd_inodefs",
1028 .get_sb
= mtd_inodefs_get_sb
,
1029 .kill_sb
= kill_anon_super
,
1032 static void mtdchar_notify_add(struct mtd_info
*mtd
)
1036 static void mtdchar_notify_remove(struct mtd_info
*mtd
)
1038 struct inode
*mtd_ino
= ilookup(mtd_inode_mnt
->mnt_sb
, mtd
->index
);
1041 /* Destroy the inode if it exists */
1042 mtd_ino
->i_nlink
= 0;
1047 static struct mtd_notifier mtdchar_notifier
= {
1048 .add
= mtdchar_notify_add
,
1049 .remove
= mtdchar_notify_remove
,
1052 static int __init
init_mtdchar(void)
1056 ret
= __register_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
,
1059 pr_notice("Can't allocate major number %d for "
1060 "Memory Technology Devices.\n", MTD_CHAR_MAJOR
);
1064 ret
= register_filesystem(&mtd_inodefs_type
);
1066 pr_notice("Can't register mtd_inodefs filesystem: %d\n", ret
);
1067 goto err_unregister_chdev
;
1070 mtd_inode_mnt
= kern_mount(&mtd_inodefs_type
);
1071 if (IS_ERR(mtd_inode_mnt
)) {
1072 ret
= PTR_ERR(mtd_inode_mnt
);
1073 pr_notice("Error mounting mtd_inodefs filesystem: %d\n", ret
);
1074 goto err_unregister_filesystem
;
1076 register_mtd_user(&mtdchar_notifier
);
1080 err_unregister_filesystem
:
1081 unregister_filesystem(&mtd_inodefs_type
);
1082 err_unregister_chdev
:
1083 __unregister_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
, "mtd");
1087 static void __exit
cleanup_mtdchar(void)
1089 unregister_mtd_user(&mtdchar_notifier
);
1090 mntput(mtd_inode_mnt
);
1091 unregister_filesystem(&mtd_inodefs_type
);
1092 __unregister_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
, "mtd");
1095 module_init(init_mtdchar
);
1096 module_exit(cleanup_mtdchar
);
1098 MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR
);
1100 MODULE_LICENSE("GPL");
1101 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1102 MODULE_DESCRIPTION("Direct character-device access to MTD devices");
1103 MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR
);