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>
36 #include <linux/mtd/compatmac.h>
38 #include <asm/uaccess.h>
40 #define MTD_INODE_FS_MAGIC 0x11307854
41 static struct vfsmount
*mtd_inode_mnt __read_mostly
;
44 * Data structure to hold the pointer to the mtd device as well
45 * as mode information ofr various use cases.
47 struct mtd_file_info
{
50 enum mtd_file_modes mode
;
53 static loff_t
mtd_lseek (struct file
*file
, loff_t offset
, int orig
)
55 struct mtd_file_info
*mfi
= file
->private_data
;
56 struct mtd_info
*mtd
= mfi
->mtd
;
62 offset
+= file
->f_pos
;
71 if (offset
>= 0 && offset
<= mtd
->size
)
72 return file
->f_pos
= offset
;
79 static int mtd_open(struct inode
*inode
, struct file
*file
)
81 int minor
= iminor(inode
);
82 int devnum
= minor
>> 1;
85 struct mtd_file_info
*mfi
;
86 struct inode
*mtd_ino
;
88 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_open\n");
90 /* You can't open the RO devices RW */
91 if ((file
->f_mode
& FMODE_WRITE
) && (minor
& 1))
95 mtd
= get_mtd_device(NULL
, devnum
);
102 if (mtd
->type
== MTD_ABSENT
) {
108 mtd_ino
= iget_locked(mtd_inode_mnt
->mnt_sb
, devnum
);
114 if (mtd_ino
->i_state
& I_NEW
) {
115 mtd_ino
->i_private
= mtd
;
116 mtd_ino
->i_mode
= S_IFCHR
;
117 mtd_ino
->i_data
.backing_dev_info
= mtd
->backing_dev_info
;
118 unlock_new_inode(mtd_ino
);
120 file
->f_mapping
= mtd_ino
->i_mapping
;
122 /* You can't open it RW if it's not a writeable device */
123 if ((file
->f_mode
& FMODE_WRITE
) && !(mtd
->flags
& MTD_WRITEABLE
)) {
130 mfi
= kzalloc(sizeof(*mfi
), GFP_KERNEL
);
139 file
->private_data
= mfi
;
146 /*====================================================================*/
148 static int mtd_close(struct inode
*inode
, struct file
*file
)
150 struct mtd_file_info
*mfi
= file
->private_data
;
151 struct mtd_info
*mtd
= mfi
->mtd
;
153 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_close\n");
155 /* Only sync if opened RW */
156 if ((file
->f_mode
& FMODE_WRITE
) && mtd
->sync
)
162 file
->private_data
= NULL
;
168 /* FIXME: This _really_ needs to die. In 2.5, we should lock the
169 userspace buffer down and use it directly with readv/writev.
171 #define MAX_KMALLOC_SIZE 0x20000
173 static ssize_t
mtd_read(struct file
*file
, char __user
*buf
, size_t count
,loff_t
*ppos
)
175 struct mtd_file_info
*mfi
= file
->private_data
;
176 struct mtd_info
*mtd
= mfi
->mtd
;
178 size_t total_retlen
=0;
183 DEBUG(MTD_DEBUG_LEVEL0
,"MTD_read\n");
185 if (*ppos
+ count
> mtd
->size
)
186 count
= mtd
->size
- *ppos
;
191 /* FIXME: Use kiovec in 2.5 to lock down the user's buffers
192 and pass them directly to the MTD functions */
194 if (count
> MAX_KMALLOC_SIZE
)
195 kbuf
=kmalloc(MAX_KMALLOC_SIZE
, GFP_KERNEL
);
197 kbuf
=kmalloc(count
, GFP_KERNEL
);
204 if (count
> MAX_KMALLOC_SIZE
)
205 len
= MAX_KMALLOC_SIZE
;
210 case MTD_MODE_OTP_FACTORY
:
211 ret
= mtd
->read_fact_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
213 case MTD_MODE_OTP_USER
:
214 ret
= mtd
->read_user_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
218 struct mtd_oob_ops ops
;
220 ops
.mode
= MTD_OOB_RAW
;
225 ret
= mtd
->read_oob(mtd
, *ppos
, &ops
);
230 ret
= mtd
->read(mtd
, *ppos
, len
, &retlen
, kbuf
);
232 /* Nand returns -EBADMSG on ecc errors, but it returns
233 * the data. For our userspace tools it is important
234 * to dump areas with ecc errors !
235 * For kernel internal usage it also might return -EUCLEAN
236 * to signal the caller that a bitflip has occured and has
237 * been corrected by the ECC algorithm.
238 * Userspace software which accesses NAND this way
239 * must be aware of the fact that it deals with NAND
241 if (!ret
|| (ret
== -EUCLEAN
) || (ret
== -EBADMSG
)) {
243 if (copy_to_user(buf
, kbuf
, retlen
)) {
248 total_retlen
+= retlen
;
266 static ssize_t
mtd_write(struct file
*file
, const char __user
*buf
, size_t count
,loff_t
*ppos
)
268 struct mtd_file_info
*mfi
= file
->private_data
;
269 struct mtd_info
*mtd
= mfi
->mtd
;
272 size_t total_retlen
=0;
276 DEBUG(MTD_DEBUG_LEVEL0
,"MTD_write\n");
278 if (*ppos
== mtd
->size
)
281 if (*ppos
+ count
> mtd
->size
)
282 count
= mtd
->size
- *ppos
;
287 if (count
> MAX_KMALLOC_SIZE
)
288 kbuf
=kmalloc(MAX_KMALLOC_SIZE
, GFP_KERNEL
);
290 kbuf
=kmalloc(count
, GFP_KERNEL
);
297 if (count
> MAX_KMALLOC_SIZE
)
298 len
= MAX_KMALLOC_SIZE
;
302 if (copy_from_user(kbuf
, buf
, len
)) {
308 case MTD_MODE_OTP_FACTORY
:
311 case MTD_MODE_OTP_USER
:
312 if (!mtd
->write_user_prot_reg
) {
316 ret
= mtd
->write_user_prot_reg(mtd
, *ppos
, len
, &retlen
, kbuf
);
321 struct mtd_oob_ops ops
;
323 ops
.mode
= MTD_OOB_RAW
;
328 ret
= mtd
->write_oob(mtd
, *ppos
, &ops
);
334 ret
= (*(mtd
->write
))(mtd
, *ppos
, len
, &retlen
, kbuf
);
338 total_retlen
+= retlen
;
352 /*======================================================================
354 IOCTL calls for getting device parameters.
356 ======================================================================*/
357 static void mtdchar_erase_callback (struct erase_info
*instr
)
359 wake_up((wait_queue_head_t
*)instr
->priv
);
362 #ifdef CONFIG_HAVE_MTD_OTP
363 static int otp_select_filemode(struct mtd_file_info
*mfi
, int mode
)
365 struct mtd_info
*mtd
= mfi
->mtd
;
369 case MTD_OTP_FACTORY
:
370 if (!mtd
->read_fact_prot_reg
)
373 mfi
->mode
= MTD_MODE_OTP_FACTORY
;
376 if (!mtd
->read_fact_prot_reg
)
379 mfi
->mode
= MTD_MODE_OTP_USER
;
389 # define otp_select_filemode(f,m) -EOPNOTSUPP
392 static int mtd_do_writeoob(struct file
*file
, struct mtd_info
*mtd
,
393 uint64_t start
, uint32_t length
, void __user
*ptr
,
394 uint32_t __user
*retp
)
396 struct mtd_oob_ops ops
;
400 if (!(file
->f_mode
& FMODE_WRITE
))
409 ret
= access_ok(VERIFY_READ
, ptr
, length
) ? 0 : -EFAULT
;
415 ops
.ooboffs
= start
& (mtd
->oobsize
- 1);
417 ops
.mode
= MTD_OOB_PLACE
;
419 if (ops
.ooboffs
&& ops
.ooblen
> (mtd
->oobsize
- ops
.ooboffs
))
422 ops
.oobbuf
= memdup_user(ptr
, length
);
423 if (IS_ERR(ops
.oobbuf
))
424 return PTR_ERR(ops
.oobbuf
);
426 start
&= ~((uint64_t)mtd
->oobsize
- 1);
427 ret
= mtd
->write_oob(mtd
, start
, &ops
);
429 if (ops
.oobretlen
> 0xFFFFFFFFU
)
431 retlen
= ops
.oobretlen
;
432 if (copy_to_user(retp
, &retlen
, sizeof(length
)))
439 static int mtd_do_readoob(struct mtd_info
*mtd
, uint64_t start
,
440 uint32_t length
, void __user
*ptr
, uint32_t __user
*retp
)
442 struct mtd_oob_ops ops
;
451 ret
= access_ok(VERIFY_WRITE
, ptr
,
452 length
) ? 0 : -EFAULT
;
457 ops
.ooboffs
= start
& (mtd
->oobsize
- 1);
459 ops
.mode
= MTD_OOB_PLACE
;
461 if (ops
.ooboffs
&& ops
.ooblen
> (mtd
->oobsize
- ops
.ooboffs
))
464 ops
.oobbuf
= kmalloc(length
, GFP_KERNEL
);
468 start
&= ~((uint64_t)mtd
->oobsize
- 1);
469 ret
= mtd
->read_oob(mtd
, start
, &ops
);
471 if (put_user(ops
.oobretlen
, retp
))
473 else if (ops
.oobretlen
&& copy_to_user(ptr
, ops
.oobbuf
,
481 static int mtd_ioctl(struct inode
*inode
, struct file
*file
,
482 u_int cmd
, u_long arg
)
484 struct mtd_file_info
*mfi
= file
->private_data
;
485 struct mtd_info
*mtd
= mfi
->mtd
;
486 void __user
*argp
= (void __user
*)arg
;
489 struct mtd_info_user info
;
491 DEBUG(MTD_DEBUG_LEVEL0
, "MTD_ioctl\n");
493 size
= (cmd
& IOCSIZE_MASK
) >> IOCSIZE_SHIFT
;
495 if (!access_ok(VERIFY_READ
, argp
, size
))
499 if (!access_ok(VERIFY_WRITE
, argp
, size
))
504 case MEMGETREGIONCOUNT
:
505 if (copy_to_user(argp
, &(mtd
->numeraseregions
), sizeof(int)))
509 case MEMGETREGIONINFO
:
512 struct mtd_erase_region_info
*kr
;
513 struct region_info_user __user
*ur
= argp
;
515 if (get_user(ur_idx
, &(ur
->regionindex
)))
518 kr
= &(mtd
->eraseregions
[ur_idx
]);
520 if (put_user(kr
->offset
, &(ur
->offset
))
521 || put_user(kr
->erasesize
, &(ur
->erasesize
))
522 || put_user(kr
->numblocks
, &(ur
->numblocks
)))
529 info
.type
= mtd
->type
;
530 info
.flags
= mtd
->flags
;
531 info
.size
= mtd
->size
;
532 info
.erasesize
= mtd
->erasesize
;
533 info
.writesize
= mtd
->writesize
;
534 info
.oobsize
= mtd
->oobsize
;
535 /* The below fields are obsolete */
538 if (copy_to_user(argp
, &info
, sizeof(struct mtd_info_user
)))
545 struct erase_info
*erase
;
547 if(!(file
->f_mode
& FMODE_WRITE
))
550 erase
=kzalloc(sizeof(struct erase_info
),GFP_KERNEL
);
554 wait_queue_head_t waitq
;
555 DECLARE_WAITQUEUE(wait
, current
);
557 init_waitqueue_head(&waitq
);
559 if (cmd
== MEMERASE64
) {
560 struct erase_info_user64 einfo64
;
562 if (copy_from_user(&einfo64
, argp
,
563 sizeof(struct erase_info_user64
))) {
567 erase
->addr
= einfo64
.start
;
568 erase
->len
= einfo64
.length
;
570 struct erase_info_user einfo32
;
572 if (copy_from_user(&einfo32
, argp
,
573 sizeof(struct erase_info_user
))) {
577 erase
->addr
= einfo32
.start
;
578 erase
->len
= einfo32
.length
;
581 erase
->callback
= mtdchar_erase_callback
;
582 erase
->priv
= (unsigned long)&waitq
;
585 FIXME: Allow INTERRUPTIBLE. Which means
586 not having the wait_queue head on the stack.
588 If the wq_head is on the stack, and we
589 leave because we got interrupted, then the
590 wq_head is no longer there when the
591 callback routine tries to wake us up.
593 ret
= mtd
->erase(mtd
, erase
);
595 set_current_state(TASK_UNINTERRUPTIBLE
);
596 add_wait_queue(&waitq
, &wait
);
597 if (erase
->state
!= MTD_ERASE_DONE
&&
598 erase
->state
!= MTD_ERASE_FAILED
)
600 remove_wait_queue(&waitq
, &wait
);
601 set_current_state(TASK_RUNNING
);
603 ret
= (erase
->state
== MTD_ERASE_FAILED
)?-EIO
:0;
612 struct mtd_oob_buf buf
;
613 struct mtd_oob_buf __user
*buf_user
= argp
;
615 /* NOTE: writes return length to buf_user->length */
616 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
619 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
, buf
.length
,
620 buf
.ptr
, &buf_user
->length
);
626 struct mtd_oob_buf buf
;
627 struct mtd_oob_buf __user
*buf_user
= argp
;
629 /* NOTE: writes return length to buf_user->start */
630 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
633 ret
= mtd_do_readoob(mtd
, buf
.start
, buf
.length
,
634 buf
.ptr
, &buf_user
->start
);
640 struct mtd_oob_buf64 buf
;
641 struct mtd_oob_buf64 __user
*buf_user
= argp
;
643 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
646 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
, buf
.length
,
647 (void __user
*)(uintptr_t)buf
.usr_ptr
,
654 struct mtd_oob_buf64 buf
;
655 struct mtd_oob_buf64 __user
*buf_user
= argp
;
657 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
660 ret
= mtd_do_readoob(mtd
, buf
.start
, buf
.length
,
661 (void __user
*)(uintptr_t)buf
.usr_ptr
,
668 struct erase_info_user einfo
;
670 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
676 ret
= mtd
->lock(mtd
, einfo
.start
, einfo
.length
);
682 struct erase_info_user einfo
;
684 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
690 ret
= mtd
->unlock(mtd
, einfo
.start
, einfo
.length
);
696 struct erase_info_user einfo
;
698 if (copy_from_user(&einfo
, argp
, sizeof(einfo
)))
704 ret
= mtd
->is_locked(mtd
, einfo
.start
, einfo
.length
);
708 /* Legacy interface */
711 struct nand_oobinfo oi
;
715 if (mtd
->ecclayout
->eccbytes
> ARRAY_SIZE(oi
.eccpos
))
718 oi
.useecc
= MTD_NANDECC_AUTOPLACE
;
719 memcpy(&oi
.eccpos
, mtd
->ecclayout
->eccpos
, sizeof(oi
.eccpos
));
720 memcpy(&oi
.oobfree
, mtd
->ecclayout
->oobfree
,
722 oi
.eccbytes
= mtd
->ecclayout
->eccbytes
;
724 if (copy_to_user(argp
, &oi
, sizeof(struct nand_oobinfo
)))
733 if (copy_from_user(&offs
, argp
, sizeof(loff_t
)))
735 if (!mtd
->block_isbad
)
738 return mtd
->block_isbad(mtd
, offs
);
746 if (copy_from_user(&offs
, argp
, sizeof(loff_t
)))
748 if (!mtd
->block_markbad
)
751 return mtd
->block_markbad(mtd
, offs
);
755 #ifdef CONFIG_HAVE_MTD_OTP
759 if (copy_from_user(&mode
, argp
, sizeof(int)))
762 mfi
->mode
= MTD_MODE_NORMAL
;
764 ret
= otp_select_filemode(mfi
, mode
);
770 case OTPGETREGIONCOUNT
:
771 case OTPGETREGIONINFO
:
773 struct otp_info
*buf
= kmalloc(4096, GFP_KERNEL
);
778 case MTD_MODE_OTP_FACTORY
:
779 if (mtd
->get_fact_prot_info
)
780 ret
= mtd
->get_fact_prot_info(mtd
, buf
, 4096);
782 case MTD_MODE_OTP_USER
:
783 if (mtd
->get_user_prot_info
)
784 ret
= mtd
->get_user_prot_info(mtd
, buf
, 4096);
790 if (cmd
== OTPGETREGIONCOUNT
) {
791 int nbr
= ret
/ sizeof(struct otp_info
);
792 ret
= copy_to_user(argp
, &nbr
, sizeof(int));
794 ret
= copy_to_user(argp
, buf
, ret
);
804 struct otp_info oinfo
;
806 if (mfi
->mode
!= MTD_MODE_OTP_USER
)
808 if (copy_from_user(&oinfo
, argp
, sizeof(oinfo
)))
810 if (!mtd
->lock_user_prot_reg
)
812 ret
= mtd
->lock_user_prot_reg(mtd
, oinfo
.start
, oinfo
.length
);
822 if (copy_to_user(argp
, mtd
->ecclayout
,
823 sizeof(struct nand_ecclayout
)))
830 if (copy_to_user(argp
, &mtd
->ecc_stats
,
831 sizeof(struct mtd_ecc_stats
)))
841 case MTD_MODE_OTP_FACTORY
:
842 case MTD_MODE_OTP_USER
:
843 ret
= otp_select_filemode(mfi
, arg
);
847 if (!mtd
->read_oob
|| !mtd
->write_oob
)
851 case MTD_MODE_NORMAL
:
869 struct mtd_oob_buf32
{
872 compat_caddr_t ptr
; /* unsigned char* */
875 #define MEMWRITEOOB32 _IOWR('M', 3, struct mtd_oob_buf32)
876 #define MEMREADOOB32 _IOWR('M', 4, struct mtd_oob_buf32)
878 static long mtd_compat_ioctl(struct file
*file
, unsigned int cmd
,
881 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
882 struct mtd_file_info
*mfi
= file
->private_data
;
883 struct mtd_info
*mtd
= mfi
->mtd
;
884 void __user
*argp
= compat_ptr(arg
);
892 struct mtd_oob_buf32 buf
;
893 struct mtd_oob_buf32 __user
*buf_user
= argp
;
895 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
898 ret
= mtd_do_writeoob(file
, mtd
, buf
.start
,
899 buf
.length
, compat_ptr(buf
.ptr
),
906 struct mtd_oob_buf32 buf
;
907 struct mtd_oob_buf32 __user
*buf_user
= argp
;
909 /* NOTE: writes return length to buf->start */
910 if (copy_from_user(&buf
, argp
, sizeof(buf
)))
913 ret
= mtd_do_readoob(mtd
, buf
.start
,
914 buf
.length
, compat_ptr(buf
.ptr
),
919 ret
= mtd_ioctl(inode
, file
, cmd
, (unsigned long)argp
);
927 #endif /* CONFIG_COMPAT */
930 * try to determine where a shared mapping can be made
931 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
935 static unsigned long mtd_get_unmapped_area(struct file
*file
,
941 struct mtd_file_info
*mfi
= file
->private_data
;
942 struct mtd_info
*mtd
= mfi
->mtd
;
944 if (mtd
->get_unmapped_area
) {
945 unsigned long offset
;
948 return (unsigned long) -EINVAL
;
950 if (len
> mtd
->size
|| pgoff
>= (mtd
->size
>> PAGE_SHIFT
))
951 return (unsigned long) -EINVAL
;
953 offset
= pgoff
<< PAGE_SHIFT
;
954 if (offset
> mtd
->size
- len
)
955 return (unsigned long) -EINVAL
;
957 return mtd
->get_unmapped_area(mtd
, len
, offset
, flags
);
960 /* can't map directly */
961 return (unsigned long) -ENOSYS
;
966 * set up a mapping for shared memory segments
968 static int mtd_mmap(struct file
*file
, struct vm_area_struct
*vma
)
971 struct mtd_file_info
*mfi
= file
->private_data
;
972 struct mtd_info
*mtd
= mfi
->mtd
;
973 struct map_info
*map
= mtd
->priv
;
978 if (mtd
->type
== MTD_RAM
|| mtd
->type
== MTD_ROM
) {
979 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
981 len
= PAGE_ALIGN((start
& ~PAGE_MASK
) + map
->size
);
983 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
987 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
988 vma
->vm_flags
|= VM_IO
| VM_RESERVED
;
990 #ifdef pgprot_noncached
991 if (file
->f_flags
& O_DSYNC
|| off
>= __pa(high_memory
))
992 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
994 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
995 vma
->vm_end
- vma
->vm_start
,
1003 return vma
->vm_flags
& VM_SHARED
? 0 : -ENOSYS
;
1007 static const struct file_operations mtd_fops
= {
1008 .owner
= THIS_MODULE
,
1009 .llseek
= mtd_lseek
,
1013 #ifdef CONFIG_COMPAT
1014 .compat_ioctl
= mtd_compat_ioctl
,
1017 .release
= mtd_close
,
1020 .get_unmapped_area
= mtd_get_unmapped_area
,
1024 static int mtd_inodefs_get_sb(struct file_system_type
*fs_type
, int flags
,
1025 const char *dev_name
, void *data
,
1026 struct vfsmount
*mnt
)
1028 return get_sb_pseudo(fs_type
, "mtd_inode:", NULL
, MTD_INODE_FS_MAGIC
,
1032 static struct file_system_type mtd_inodefs_type
= {
1033 .name
= "mtd_inodefs",
1034 .get_sb
= mtd_inodefs_get_sb
,
1035 .kill_sb
= kill_anon_super
,
1038 static void mtdchar_notify_add(struct mtd_info
*mtd
)
1042 static void mtdchar_notify_remove(struct mtd_info
*mtd
)
1044 struct inode
*mtd_ino
= ilookup(mtd_inode_mnt
->mnt_sb
, mtd
->index
);
1047 /* Destroy the inode if it exists */
1048 mtd_ino
->i_nlink
= 0;
1053 static struct mtd_notifier mtdchar_notifier
= {
1054 .add
= mtdchar_notify_add
,
1055 .remove
= mtdchar_notify_remove
,
1058 static int __init
init_mtdchar(void)
1062 ret
= __register_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
,
1065 pr_notice("Can't allocate major number %d for "
1066 "Memory Technology Devices.\n", MTD_CHAR_MAJOR
);
1070 ret
= register_filesystem(&mtd_inodefs_type
);
1072 pr_notice("Can't register mtd_inodefs filesystem: %d\n", ret
);
1073 goto err_unregister_chdev
;
1076 mtd_inode_mnt
= kern_mount(&mtd_inodefs_type
);
1077 if (IS_ERR(mtd_inode_mnt
)) {
1078 ret
= PTR_ERR(mtd_inode_mnt
);
1079 pr_notice("Error mounting mtd_inodefs filesystem: %d\n", ret
);
1080 goto err_unregister_filesystem
;
1082 register_mtd_user(&mtdchar_notifier
);
1086 err_unregister_filesystem
:
1087 unregister_filesystem(&mtd_inodefs_type
);
1088 err_unregister_chdev
:
1089 __unregister_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
, "mtd");
1093 static void __exit
cleanup_mtdchar(void)
1095 unregister_mtd_user(&mtdchar_notifier
);
1096 mntput(mtd_inode_mnt
);
1097 unregister_filesystem(&mtd_inodefs_type
);
1098 __unregister_chrdev(MTD_CHAR_MAJOR
, 0, 1 << MINORBITS
, "mtd");
1101 module_init(init_mtdchar
);
1102 module_exit(cleanup_mtdchar
);
1104 MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR
);
1106 MODULE_LICENSE("GPL");
1107 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1108 MODULE_DESCRIPTION("Direct character-device access to MTD devices");
1109 MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR
);