mtdchar.c 28.2 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
D
David Woodhouse 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18 19
 *
 */

20 21
#include <linux/device.h>
#include <linux/fs.h>
A
Andrew Morton 已提交
22
#include <linux/mm.h>
23
#include <linux/err.h>
24
#include <linux/init.h>
L
Linus Torvalds 已提交
25 26
#include <linux/kernel.h>
#include <linux/module.h>
27 28
#include <linux/slab.h>
#include <linux/sched.h>
29
#include <linux/mutex.h>
30
#include <linux/backing-dev.h>
K
Kevin Cernekee 已提交
31
#include <linux/compat.h>
32
#include <linux/mount.h>
33
#include <linux/blkpg.h>
L
Linus Torvalds 已提交
34
#include <linux/mtd/mtd.h>
35
#include <linux/mtd/partitions.h>
36
#include <linux/mtd/map.h>
L
Linus Torvalds 已提交
37

38
#include <asm/uaccess.h>
39

40
#define MTD_INODE_FS_MAGIC 0x11307854
41
static DEFINE_MUTEX(mtd_mutex);
42
static struct vfsmount *mtd_inode_mnt __read_mostly;
L
Linus Torvalds 已提交
43

44
/*
45
 * Data structure to hold the pointer to the mtd device as well
B
Brian Norris 已提交
46
 * as mode information of various use cases.
47
 */
48 49
struct mtd_file_info {
	struct mtd_info *mtd;
50
	struct inode *ino;
51 52
	enum mtd_file_modes mode;
};
53

54
static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig)
L
Linus Torvalds 已提交
55
{
56 57
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
L
Linus Torvalds 已提交
58 59

	switch (orig) {
60
	case SEEK_SET:
L
Linus Torvalds 已提交
61
		break;
62
	case SEEK_CUR:
63
		offset += file->f_pos;
L
Linus Torvalds 已提交
64
		break;
65
	case SEEK_END:
66
		offset += mtd->size;
L
Linus Torvalds 已提交
67 68 69 70 71
		break;
	default:
		return -EINVAL;
	}

72
	if (offset >= 0 && offset <= mtd->size)
73
		return file->f_pos = offset;
L
Linus Torvalds 已提交
74

75
	return -EINVAL;
L
Linus Torvalds 已提交
76 77 78 79
}



80
static int mtdchar_open(struct inode *inode, struct file *file)
L
Linus Torvalds 已提交
81 82 83
{
	int minor = iminor(inode);
	int devnum = minor >> 1;
84
	int ret = 0;
L
Linus Torvalds 已提交
85
	struct mtd_info *mtd;
86
	struct mtd_file_info *mfi;
87
	struct inode *mtd_ino;
L
Linus Torvalds 已提交
88

89
	pr_debug("MTD_open\n");
L
Linus Torvalds 已提交
90 91

	/* You can't open the RO devices RW */
92
	if ((file->f_mode & FMODE_WRITE) && (minor & 1))
L
Linus Torvalds 已提交
93 94
		return -EACCES;

95
	mutex_lock(&mtd_mutex);
L
Linus Torvalds 已提交
96
	mtd = get_mtd_device(NULL, devnum);
97

98 99 100 101
	if (IS_ERR(mtd)) {
		ret = PTR_ERR(mtd);
		goto out;
	}
102

103
	if (mtd->type == MTD_ABSENT) {
L
Linus Torvalds 已提交
104
		put_mtd_device(mtd);
105 106
		ret = -ENODEV;
		goto out;
L
Linus Torvalds 已提交
107 108
	}

109 110 111 112 113 114 115 116 117 118 119 120 121
	mtd_ino = iget_locked(mtd_inode_mnt->mnt_sb, devnum);
	if (!mtd_ino) {
		put_mtd_device(mtd);
		ret = -ENOMEM;
		goto out;
	}
	if (mtd_ino->i_state & I_NEW) {
		mtd_ino->i_private = mtd;
		mtd_ino->i_mode = S_IFCHR;
		mtd_ino->i_data.backing_dev_info = mtd->backing_dev_info;
		unlock_new_inode(mtd_ino);
	}
	file->f_mapping = mtd_ino->i_mapping;
122

L
Linus Torvalds 已提交
123
	/* You can't open it RW if it's not a writeable device */
124
	if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
125
		iput(mtd_ino);
L
Linus Torvalds 已提交
126
		put_mtd_device(mtd);
127 128
		ret = -EACCES;
		goto out;
L
Linus Torvalds 已提交
129
	}
130

131 132
	mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
	if (!mfi) {
133
		iput(mtd_ino);
134
		put_mtd_device(mtd);
135 136
		ret = -ENOMEM;
		goto out;
137
	}
138
	mfi->ino = mtd_ino;
139 140 141
	mfi->mtd = mtd;
	file->private_data = mfi;

142
out:
143
	mutex_unlock(&mtd_mutex);
144
	return ret;
145
} /* mtdchar_open */
L
Linus Torvalds 已提交
146 147 148

/*====================================================================*/

149
static int mtdchar_close(struct inode *inode, struct file *file)
L
Linus Torvalds 已提交
150
{
151 152
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
L
Linus Torvalds 已提交
153

154
	pr_debug("MTD_close\n");
L
Linus Torvalds 已提交
155

156
	/* Only sync if opened RW */
157
	if ((file->f_mode & FMODE_WRITE) && mtd->sync)
L
Linus Torvalds 已提交
158
		mtd->sync(mtd);
159

160 161
	iput(mfi->ino);

L
Linus Torvalds 已提交
162
	put_mtd_device(mtd);
163 164
	file->private_data = NULL;
	kfree(mfi);
L
Linus Torvalds 已提交
165 166

	return 0;
167
} /* mtdchar_close */
L
Linus Torvalds 已提交
168

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
/* Back in June 2001, dwmw2 wrote:
 *
 *   FIXME: This _really_ needs to die. In 2.5, we should lock the
 *   userspace buffer down and use it directly with readv/writev.
 *
 * The implementation below, using mtd_kmalloc_up_to, mitigates
 * allocation failures when the system is under low-memory situations
 * or if memory is highly fragmented at the cost of reducing the
 * performance of the requested transfer due to a smaller buffer size.
 *
 * A more complex but more memory-efficient implementation based on
 * get_user_pages and iovecs to cover extents of those pages is a
 * longer-term goal, as intimated by dwmw2 above. However, for the
 * write case, this requires yet more complex head and tail transfer
 * handling when those head and tail offsets and sizes are such that
 * alignment requirements are not met in the NAND subdriver.
 */
L
Linus Torvalds 已提交
186

187 188
static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count,
			loff_t *ppos)
L
Linus Torvalds 已提交
189
{
190 191
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
L
Linus Torvalds 已提交
192 193 194 195
	size_t retlen=0;
	size_t total_retlen=0;
	int ret=0;
	int len;
196
	size_t size = count;
L
Linus Torvalds 已提交
197
	char *kbuf;
198

199
	pr_debug("MTD_read\n");
L
Linus Torvalds 已提交
200 201 202 203 204 205

	if (*ppos + count > mtd->size)
		count = mtd->size - *ppos;

	if (!count)
		return 0;
206

207
	kbuf = mtd_kmalloc_up_to(mtd, &size);
208 209 210
	if (!kbuf)
		return -ENOMEM;

L
Linus Torvalds 已提交
211
	while (count) {
212
		len = min_t(size_t, count, size);
L
Linus Torvalds 已提交
213

214
		switch (mfi->mode) {
215
		case MTD_FILE_MODE_OTP_FACTORY:
216 217
			ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf);
			break;
218
		case MTD_FILE_MODE_OTP_USER:
219 220
			ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
			break;
221
		case MTD_FILE_MODE_RAW:
222 223 224
		{
			struct mtd_oob_ops ops;

225
			ops.mode = MTD_OPS_RAW;
226 227 228 229
			ops.datbuf = kbuf;
			ops.oobbuf = NULL;
			ops.len = len;

230
			ret = mtd_read_oob(mtd, *ppos, &ops);
231 232 233
			retlen = ops.retlen;
			break;
		}
234
		default:
235
			ret = mtd_read(mtd, *ppos, len, &retlen, kbuf);
236
		}
237
		/* Nand returns -EBADMSG on ECC errors, but it returns
L
Linus Torvalds 已提交
238
		 * the data. For our userspace tools it is important
239
		 * to dump areas with ECC errors!
240
		 * For kernel internal usage it also might return -EUCLEAN
L
Lucas De Marchi 已提交
241
		 * to signal the caller that a bitflip has occurred and has
242
		 * been corrected by the ECC algorithm.
L
Linus Torvalds 已提交
243 244 245
		 * Userspace software which accesses NAND this way
		 * must be aware of the fact that it deals with NAND
		 */
246
		if (!ret || mtd_is_bitflip_or_eccerr(ret)) {
L
Linus Torvalds 已提交
247 248
			*ppos += retlen;
			if (copy_to_user(buf, kbuf, retlen)) {
249
				kfree(kbuf);
L
Linus Torvalds 已提交
250 251 252 253 254 255 256
				return -EFAULT;
			}
			else
				total_retlen += retlen;

			count -= retlen;
			buf += retlen;
257 258
			if (retlen == 0)
				count = 0;
L
Linus Torvalds 已提交
259 260 261 262 263
		}
		else {
			kfree(kbuf);
			return ret;
		}
264

L
Linus Torvalds 已提交
265 266
	}

267
	kfree(kbuf);
L
Linus Torvalds 已提交
268
	return total_retlen;
269
} /* mtdchar_read */
L
Linus Torvalds 已提交
270

271 272
static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t count,
			loff_t *ppos)
L
Linus Torvalds 已提交
273
{
274 275
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
276
	size_t size = count;
L
Linus Torvalds 已提交
277 278 279 280 281 282
	char *kbuf;
	size_t retlen;
	size_t total_retlen=0;
	int ret=0;
	int len;

283
	pr_debug("MTD_write\n");
284

L
Linus Torvalds 已提交
285 286
	if (*ppos == mtd->size)
		return -ENOSPC;
287

L
Linus Torvalds 已提交
288 289 290 291 292 293
	if (*ppos + count > mtd->size)
		count = mtd->size - *ppos;

	if (!count)
		return 0;

294
	kbuf = mtd_kmalloc_up_to(mtd, &size);
295 296 297
	if (!kbuf)
		return -ENOMEM;

L
Linus Torvalds 已提交
298
	while (count) {
299
		len = min_t(size_t, count, size);
L
Linus Torvalds 已提交
300 301 302 303 304

		if (copy_from_user(kbuf, buf, len)) {
			kfree(kbuf);
			return -EFAULT;
		}
305

306
		switch (mfi->mode) {
307
		case MTD_FILE_MODE_OTP_FACTORY:
308 309
			ret = -EROFS;
			break;
310
		case MTD_FILE_MODE_OTP_USER:
311 312 313 314 315 316
			if (!mtd->write_user_prot_reg) {
				ret = -EOPNOTSUPP;
				break;
			}
			ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf);
			break;
317

318
		case MTD_FILE_MODE_RAW:
319 320 321
		{
			struct mtd_oob_ops ops;

322
			ops.mode = MTD_OPS_RAW;
323 324
			ops.datbuf = kbuf;
			ops.oobbuf = NULL;
325
			ops.ooboffs = 0;
326 327 328 329 330 331 332
			ops.len = len;

			ret = mtd->write_oob(mtd, *ppos, &ops);
			retlen = ops.retlen;
			break;
		}

333
		default:
334
			ret = mtd_write(mtd, *ppos, len, &retlen, kbuf);
335
		}
L
Linus Torvalds 已提交
336 337 338 339 340 341 342 343 344 345 346 347
		if (!ret) {
			*ppos += retlen;
			total_retlen += retlen;
			count -= retlen;
			buf += retlen;
		}
		else {
			kfree(kbuf);
			return ret;
		}
	}

348
	kfree(kbuf);
L
Linus Torvalds 已提交
349
	return total_retlen;
350
} /* mtdchar_write */
L
Linus Torvalds 已提交
351 352 353 354 355 356 357 358 359 360 361

/*======================================================================

    IOCTL calls for getting device parameters.

======================================================================*/
static void mtdchar_erase_callback (struct erase_info *instr)
{
	wake_up((wait_queue_head_t *)instr->priv);
}

D
David Brownell 已提交
362
#ifdef CONFIG_HAVE_MTD_OTP
363 364 365 366 367 368 369 370 371 372
static int otp_select_filemode(struct mtd_file_info *mfi, int mode)
{
	struct mtd_info *mtd = mfi->mtd;
	int ret = 0;

	switch (mode) {
	case MTD_OTP_FACTORY:
		if (!mtd->read_fact_prot_reg)
			ret = -EOPNOTSUPP;
		else
373
			mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
374 375 376 377 378
		break;
	case MTD_OTP_USER:
		if (!mtd->read_fact_prot_reg)
			ret = -EOPNOTSUPP;
		else
379
			mfi->mode = MTD_FILE_MODE_OTP_USER;
380 381 382 383 384 385 386 387 388 389 390 391
		break;
	default:
		ret = -EINVAL;
	case MTD_OTP_OFF:
		break;
	}
	return ret;
}
#else
# define otp_select_filemode(f,m)	-EOPNOTSUPP
#endif

392
static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd,
K
Kevin Cernekee 已提交
393 394 395
	uint64_t start, uint32_t length, void __user *ptr,
	uint32_t __user *retp)
{
396
	struct mtd_file_info *mfi = file->private_data;
K
Kevin Cernekee 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409
	struct mtd_oob_ops ops;
	uint32_t retlen;
	int ret = 0;

	if (!(file->f_mode & FMODE_WRITE))
		return -EPERM;

	if (length > 4096)
		return -EINVAL;

	if (!mtd->write_oob)
		ret = -EOPNOTSUPP;
	else
410
		ret = access_ok(VERIFY_READ, ptr, length) ? 0 : -EFAULT;
K
Kevin Cernekee 已提交
411 412 413 414 415

	if (ret)
		return ret;

	ops.ooblen = length;
416
	ops.ooboffs = start & (mtd->writesize - 1);
K
Kevin Cernekee 已提交
417
	ops.datbuf = NULL;
418
	ops.mode = (mfi->mode == MTD_FILE_MODE_RAW) ? MTD_OPS_RAW :
419
		MTD_OPS_PLACE_OOB;
K
Kevin Cernekee 已提交
420 421 422 423

	if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
		return -EINVAL;

J
Julia Lawall 已提交
424 425 426
	ops.oobbuf = memdup_user(ptr, length);
	if (IS_ERR(ops.oobbuf))
		return PTR_ERR(ops.oobbuf);
K
Kevin Cernekee 已提交
427

428
	start &= ~((uint64_t)mtd->writesize - 1);
K
Kevin Cernekee 已提交
429 430 431 432 433 434 435 436 437 438 439 440
	ret = mtd->write_oob(mtd, start, &ops);

	if (ops.oobretlen > 0xFFFFFFFFU)
		ret = -EOVERFLOW;
	retlen = ops.oobretlen;
	if (copy_to_user(retp, &retlen, sizeof(length)))
		ret = -EFAULT;

	kfree(ops.oobbuf);
	return ret;
}

441
static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
442 443
	uint64_t start, uint32_t length, void __user *ptr,
	uint32_t __user *retp)
K
Kevin Cernekee 已提交
444
{
445
	struct mtd_file_info *mfi = file->private_data;
K
Kevin Cernekee 已提交
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
	struct mtd_oob_ops ops;
	int ret = 0;

	if (length > 4096)
		return -EINVAL;

	if (!mtd->read_oob)
		ret = -EOPNOTSUPP;
	else
		ret = access_ok(VERIFY_WRITE, ptr,
				length) ? 0 : -EFAULT;
	if (ret)
		return ret;

	ops.ooblen = length;
461
	ops.ooboffs = start & (mtd->writesize - 1);
K
Kevin Cernekee 已提交
462
	ops.datbuf = NULL;
463
	ops.mode = (mfi->mode == MTD_FILE_MODE_RAW) ? MTD_OPS_RAW :
464
		MTD_OPS_PLACE_OOB;
K
Kevin Cernekee 已提交
465 466 467 468 469 470 471 472

	if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
		return -EINVAL;

	ops.oobbuf = kmalloc(length, GFP_KERNEL);
	if (!ops.oobbuf)
		return -ENOMEM;

473
	start &= ~((uint64_t)mtd->writesize - 1);
474
	ret = mtd_read_oob(mtd, start, &ops);
K
Kevin Cernekee 已提交
475 476 477 478 479 480 481 482

	if (put_user(ops.oobretlen, retp))
		ret = -EFAULT;
	else if (ops.oobretlen && copy_to_user(ptr, ops.oobbuf,
					    ops.oobretlen))
		ret = -EFAULT;

	kfree(ops.oobbuf);
483 484 485 486 487 488 489 490 491

	/*
	 * NAND returns -EBADMSG on ECC errors, but it returns the OOB
	 * data. For our userspace tools it is important to dump areas
	 * with ECC errors!
	 * For kernel internal usage it also might return -EUCLEAN
	 * to signal the caller that a bitflip has occured and has
	 * been corrected by the ECC algorithm.
	 *
B
Brian Norris 已提交
492 493 494
	 * Note: currently the standard NAND function, nand_read_oob_std,
	 * does not calculate ECC for the OOB area, so do not rely on
	 * this behavior unless you have replaced it with your own.
495
	 */
496
	if (mtd_is_bitflip_or_eccerr(ret))
497 498
		return 0;

K
Kevin Cernekee 已提交
499 500 501
	return ret;
}

502 503 504
/*
 * Copies (and truncates, if necessary) data from the larger struct,
 * nand_ecclayout, to the smaller, deprecated layout struct,
B
Brian Norris 已提交
505
 * nand_ecclayout_user. This is necessary only to support the deprecated
506 507 508 509 510 511 512 513 514 515 516 517 518 519
 * API ioctl ECCGETLAYOUT while allowing all new functionality to use
 * nand_ecclayout flexibly (i.e. the struct may change size in new
 * releases without requiring major rewrites).
 */
static int shrink_ecclayout(const struct nand_ecclayout *from,
		struct nand_ecclayout_user *to)
{
	int i;

	if (!from || !to)
		return -EINVAL;

	memset(to, 0, sizeof(*to));

520
	to->eccbytes = min((int)from->eccbytes, MTD_MAX_ECCPOS_ENTRIES);
521 522 523 524 525 526 527 528 529 530 531 532 533 534
	for (i = 0; i < to->eccbytes; i++)
		to->eccpos[i] = from->eccpos[i];

	for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) {
		if (from->oobfree[i].length == 0 &&
				from->oobfree[i].offset == 0)
			break;
		to->oobavail += from->oobfree[i].length;
		to->oobfree[i] = from->oobfree[i];
	}

	return 0;
}

535
static int mtdchar_blkpg_ioctl(struct mtd_info *mtd,
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
			   struct blkpg_ioctl_arg __user *arg)
{
	struct blkpg_ioctl_arg a;
	struct blkpg_partition p;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	if (copy_from_user(&a, arg, sizeof(struct blkpg_ioctl_arg)))
		return -EFAULT;

	if (copy_from_user(&p, a.data, sizeof(struct blkpg_partition)))
		return -EFAULT;

	switch (a.op) {
	case BLKPG_ADD_PARTITION:

553 554 555 556
		/* Only master mtd device must be used to add partitions */
		if (mtd_is_partition(mtd))
			return -EINVAL;

557 558 559 560 561 562 563 564 565 566 567 568 569 570
		return mtd_add_partition(mtd, p.devname, p.start, p.length);

	case BLKPG_DEL_PARTITION:

		if (p.pno < 0)
			return -EINVAL;

		return mtd_del_partition(mtd, p.pno);

	default:
		return -EINVAL;
	}
}

571
static int mtdchar_write_ioctl(struct mtd_info *mtd,
B
Brian Norris 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
		struct mtd_write_req __user *argp)
{
	struct mtd_write_req req;
	struct mtd_oob_ops ops;
	void __user *usr_data, *usr_oob;
	int ret;

	if (copy_from_user(&req, argp, sizeof(req)) ||
			!access_ok(VERIFY_READ, req.usr_data, req.len) ||
			!access_ok(VERIFY_READ, req.usr_oob, req.ooblen))
		return -EFAULT;
	if (!mtd->write_oob)
		return -EOPNOTSUPP;

	ops.mode = req.mode;
	ops.len = (size_t)req.len;
	ops.ooblen = (size_t)req.ooblen;
	ops.ooboffs = 0;

	usr_data = (void __user *)(uintptr_t)req.usr_data;
	usr_oob = (void __user *)(uintptr_t)req.usr_oob;

	if (req.usr_data) {
		ops.datbuf = memdup_user(usr_data, ops.len);
		if (IS_ERR(ops.datbuf))
			return PTR_ERR(ops.datbuf);
	} else {
		ops.datbuf = NULL;
	}

	if (req.usr_oob) {
		ops.oobbuf = memdup_user(usr_oob, ops.ooblen);
		if (IS_ERR(ops.oobbuf)) {
			kfree(ops.datbuf);
			return PTR_ERR(ops.oobbuf);
		}
	} else {
		ops.oobbuf = NULL;
	}

	ret = mtd->write_oob(mtd, (loff_t)req.start, &ops);

	kfree(ops.datbuf);
	kfree(ops.oobbuf);

	return ret;
}

620
static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
L
Linus Torvalds 已提交
621
{
622 623
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
L
Linus Torvalds 已提交
624 625 626
	void __user *argp = (void __user *)arg;
	int ret = 0;
	u_long size;
627
	struct mtd_info_user info;
628

629
	pr_debug("MTD_ioctl\n");
L
Linus Torvalds 已提交
630 631 632 633 634 635 636 637 638 639

	size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
	if (cmd & IOC_IN) {
		if (!access_ok(VERIFY_READ, argp, size))
			return -EFAULT;
	}
	if (cmd & IOC_OUT) {
		if (!access_ok(VERIFY_WRITE, argp, size))
			return -EFAULT;
	}
640

L
Linus Torvalds 已提交
641 642 643 644 645 646 647 648
	switch (cmd) {
	case MEMGETREGIONCOUNT:
		if (copy_to_user(argp, &(mtd->numeraseregions), sizeof(int)))
			return -EFAULT;
		break;

	case MEMGETREGIONINFO:
	{
649 650
		uint32_t ur_idx;
		struct mtd_erase_region_info *kr;
651
		struct region_info_user __user *ur = argp;
L
Linus Torvalds 已提交
652

653
		if (get_user(ur_idx, &(ur->regionindex)))
L
Linus Torvalds 已提交
654 655
			return -EFAULT;

D
Dan Carpenter 已提交
656 657 658
		if (ur_idx >= mtd->numeraseregions)
			return -EINVAL;

659 660 661 662 663
		kr = &(mtd->eraseregions[ur_idx]);

		if (put_user(kr->offset, &(ur->offset))
		    || put_user(kr->erasesize, &(ur->erasesize))
		    || put_user(kr->numblocks, &(ur->numblocks)))
L
Linus Torvalds 已提交
664
			return -EFAULT;
665

L
Linus Torvalds 已提交
666 667 668 669
		break;
	}

	case MEMGETINFO:
670
		memset(&info, 0, sizeof(info));
671 672 673 674 675 676
		info.type	= mtd->type;
		info.flags	= mtd->flags;
		info.size	= mtd->size;
		info.erasesize	= mtd->erasesize;
		info.writesize	= mtd->writesize;
		info.oobsize	= mtd->oobsize;
677 678
		/* The below field is obsolete */
		info.padding	= 0;
679
		if (copy_to_user(argp, &info, sizeof(struct mtd_info_user)))
L
Linus Torvalds 已提交
680 681 682 683
			return -EFAULT;
		break;

	case MEMERASE:
684
	case MEMERASE64:
L
Linus Torvalds 已提交
685 686 687
	{
		struct erase_info *erase;

688
		if(!(file->f_mode & FMODE_WRITE))
L
Linus Torvalds 已提交
689 690
			return -EPERM;

691
		erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
L
Linus Torvalds 已提交
692 693 694 695 696 697 698 699
		if (!erase)
			ret = -ENOMEM;
		else {
			wait_queue_head_t waitq;
			DECLARE_WAITQUEUE(wait, current);

			init_waitqueue_head(&waitq);

700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
			if (cmd == MEMERASE64) {
				struct erase_info_user64 einfo64;

				if (copy_from_user(&einfo64, argp,
					    sizeof(struct erase_info_user64))) {
					kfree(erase);
					return -EFAULT;
				}
				erase->addr = einfo64.start;
				erase->len = einfo64.length;
			} else {
				struct erase_info_user einfo32;

				if (copy_from_user(&einfo32, argp,
					    sizeof(struct erase_info_user))) {
					kfree(erase);
					return -EFAULT;
				}
				erase->addr = einfo32.start;
				erase->len = einfo32.length;
L
Linus Torvalds 已提交
720 721 722 723
			}
			erase->mtd = mtd;
			erase->callback = mtdchar_erase_callback;
			erase->priv = (unsigned long)&waitq;
724

L
Linus Torvalds 已提交
725 726 727
			/*
			  FIXME: Allow INTERRUPTIBLE. Which means
			  not having the wait_queue head on the stack.
728

L
Linus Torvalds 已提交
729 730 731 732 733
			  If the wq_head is on the stack, and we
			  leave because we got interrupted, then the
			  wq_head is no longer there when the
			  callback routine tries to wake us up.
			*/
734
			ret = mtd_erase(mtd, erase);
L
Linus Torvalds 已提交
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
			if (!ret) {
				set_current_state(TASK_UNINTERRUPTIBLE);
				add_wait_queue(&waitq, &wait);
				if (erase->state != MTD_ERASE_DONE &&
				    erase->state != MTD_ERASE_FAILED)
					schedule();
				remove_wait_queue(&waitq, &wait);
				set_current_state(TASK_RUNNING);

				ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0;
			}
			kfree(erase);
		}
		break;
	}

	case MEMWRITEOOB:
	{
		struct mtd_oob_buf buf;
K
Kevin Cernekee 已提交
754
		struct mtd_oob_buf __user *buf_user = argp;
L
Linus Torvalds 已提交
755

K
Kevin Cernekee 已提交
756 757
		/* NOTE: writes return length to buf_user->length */
		if (copy_from_user(&buf, argp, sizeof(buf)))
L
Linus Torvalds 已提交
758
			ret = -EFAULT;
K
Kevin Cernekee 已提交
759
		else
760
			ret = mtdchar_writeoob(file, mtd, buf.start, buf.length,
K
Kevin Cernekee 已提交
761
				buf.ptr, &buf_user->length);
L
Linus Torvalds 已提交
762 763 764 765 766 767
		break;
	}

	case MEMREADOOB:
	{
		struct mtd_oob_buf buf;
K
Kevin Cernekee 已提交
768
		struct mtd_oob_buf __user *buf_user = argp;
769

K
Kevin Cernekee 已提交
770 771
		/* NOTE: writes return length to buf_user->start */
		if (copy_from_user(&buf, argp, sizeof(buf)))
L
Linus Torvalds 已提交
772
			ret = -EFAULT;
K
Kevin Cernekee 已提交
773
		else
774
			ret = mtdchar_readoob(file, mtd, buf.start, buf.length,
K
Kevin Cernekee 已提交
775
				buf.ptr, &buf_user->start);
L
Linus Torvalds 已提交
776 777 778
		break;
	}

779 780 781 782 783 784 785 786
	case MEMWRITEOOB64:
	{
		struct mtd_oob_buf64 buf;
		struct mtd_oob_buf64 __user *buf_user = argp;

		if (copy_from_user(&buf, argp, sizeof(buf)))
			ret = -EFAULT;
		else
787
			ret = mtdchar_writeoob(file, mtd, buf.start, buf.length,
788 789 790 791 792 793 794 795 796 797 798 799 800
				(void __user *)(uintptr_t)buf.usr_ptr,
				&buf_user->length);
		break;
	}

	case MEMREADOOB64:
	{
		struct mtd_oob_buf64 buf;
		struct mtd_oob_buf64 __user *buf_user = argp;

		if (copy_from_user(&buf, argp, sizeof(buf)))
			ret = -EFAULT;
		else
801
			ret = mtdchar_readoob(file, mtd, buf.start, buf.length,
802 803 804 805 806
				(void __user *)(uintptr_t)buf.usr_ptr,
				&buf_user->length);
		break;
	}

B
Brian Norris 已提交
807 808
	case MEMWRITE:
	{
809
		ret = mtdchar_write_ioctl(mtd,
B
Brian Norris 已提交
810 811 812 813
		      (struct mtd_write_req __user *)arg);
		break;
	}

L
Linus Torvalds 已提交
814 815
	case MEMLOCK:
	{
816
		struct erase_info_user einfo;
L
Linus Torvalds 已提交
817

818
		if (copy_from_user(&einfo, argp, sizeof(einfo)))
L
Linus Torvalds 已提交
819 820 821 822 823
			return -EFAULT;

		if (!mtd->lock)
			ret = -EOPNOTSUPP;
		else
824
			ret = mtd->lock(mtd, einfo.start, einfo.length);
L
Linus Torvalds 已提交
825 826 827 828 829
		break;
	}

	case MEMUNLOCK:
	{
830
		struct erase_info_user einfo;
L
Linus Torvalds 已提交
831

832
		if (copy_from_user(&einfo, argp, sizeof(einfo)))
L
Linus Torvalds 已提交
833 834 835 836 837
			return -EFAULT;

		if (!mtd->unlock)
			ret = -EOPNOTSUPP;
		else
838
			ret = mtd->unlock(mtd, einfo.start, einfo.length);
L
Linus Torvalds 已提交
839 840 841
		break;
	}

842 843 844 845 846 847 848 849 850 851 852 853 854 855
	case MEMISLOCKED:
	{
		struct erase_info_user einfo;

		if (copy_from_user(&einfo, argp, sizeof(einfo)))
			return -EFAULT;

		if (!mtd->is_locked)
			ret = -EOPNOTSUPP;
		else
			ret = mtd->is_locked(mtd, einfo.start, einfo.length);
		break;
	}

856
	/* Legacy interface */
L
Linus Torvalds 已提交
857 858
	case MEMGETOOBSEL:
	{
859 860 861 862 863 864 865 866 867 868 869
		struct nand_oobinfo oi;

		if (!mtd->ecclayout)
			return -EOPNOTSUPP;
		if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos))
			return -EINVAL;

		oi.useecc = MTD_NANDECC_AUTOPLACE;
		memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
		memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
		       sizeof(oi.oobfree));
870
		oi.eccbytes = mtd->ecclayout->eccbytes;
871 872

		if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
L
Linus Torvalds 已提交
873 874 875 876 877 878 879
			return -EFAULT;
		break;
	}

	case MEMGETBADBLOCK:
	{
		loff_t offs;
880

L
Linus Torvalds 已提交
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
		if (copy_from_user(&offs, argp, sizeof(loff_t)))
			return -EFAULT;
		if (!mtd->block_isbad)
			ret = -EOPNOTSUPP;
		else
			return mtd->block_isbad(mtd, offs);
		break;
	}

	case MEMSETBADBLOCK:
	{
		loff_t offs;

		if (copy_from_user(&offs, argp, sizeof(loff_t)))
			return -EFAULT;
		if (!mtd->block_markbad)
			ret = -EOPNOTSUPP;
		else
			return mtd->block_markbad(mtd, offs);
		break;
	}

D
David Brownell 已提交
903
#ifdef CONFIG_HAVE_MTD_OTP
904 905 906 907 908
	case OTPSELECT:
	{
		int mode;
		if (copy_from_user(&mode, argp, sizeof(int)))
			return -EFAULT;
909

910
		mfi->mode = MTD_FILE_MODE_NORMAL;
911 912 913

		ret = otp_select_filemode(mfi, mode);

914
		file->f_pos = 0;
915 916 917 918 919 920 921 922 923 924
		break;
	}

	case OTPGETREGIONCOUNT:
	case OTPGETREGIONINFO:
	{
		struct otp_info *buf = kmalloc(4096, GFP_KERNEL);
		if (!buf)
			return -ENOMEM;
		ret = -EOPNOTSUPP;
925
		switch (mfi->mode) {
926
		case MTD_FILE_MODE_OTP_FACTORY:
927 928 929
			if (mtd->get_fact_prot_info)
				ret = mtd->get_fact_prot_info(mtd, buf, 4096);
			break;
930
		case MTD_FILE_MODE_OTP_USER:
931 932 933
			if (mtd->get_user_prot_info)
				ret = mtd->get_user_prot_info(mtd, buf, 4096);
			break;
934 935
		default:
			break;
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
		}
		if (ret >= 0) {
			if (cmd == OTPGETREGIONCOUNT) {
				int nbr = ret / sizeof(struct otp_info);
				ret = copy_to_user(argp, &nbr, sizeof(int));
			} else
				ret = copy_to_user(argp, buf, ret);
			if (ret)
				ret = -EFAULT;
		}
		kfree(buf);
		break;
	}

	case OTPLOCK:
	{
952
		struct otp_info oinfo;
953

954
		if (mfi->mode != MTD_FILE_MODE_OTP_USER)
955
			return -EINVAL;
956
		if (copy_from_user(&oinfo, argp, sizeof(oinfo)))
957 958 959
			return -EFAULT;
		if (!mtd->lock_user_prot_reg)
			return -EOPNOTSUPP;
960
		ret = mtd->lock_user_prot_reg(mtd, oinfo.start, oinfo.length);
961 962 963 964
		break;
	}
#endif

965
	/* This ioctl is being deprecated - it truncates the ECC layout */
966 967
	case ECCGETLAYOUT:
	{
968 969
		struct nand_ecclayout_user *usrlay;

970 971 972
		if (!mtd->ecclayout)
			return -EOPNOTSUPP;

973 974 975 976 977 978 979 980 981
		usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);
		if (!usrlay)
			return -ENOMEM;

		shrink_ecclayout(mtd->ecclayout, usrlay);

		if (copy_to_user(argp, usrlay, sizeof(*usrlay)))
			ret = -EFAULT;
		kfree(usrlay);
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
		break;
	}

	case ECCGETSTATS:
	{
		if (copy_to_user(argp, &mtd->ecc_stats,
				 sizeof(struct mtd_ecc_stats)))
			return -EFAULT;
		break;
	}

	case MTDFILEMODE:
	{
		mfi->mode = 0;

		switch(arg) {
998 999
		case MTD_FILE_MODE_OTP_FACTORY:
		case MTD_FILE_MODE_OTP_USER:
1000 1001 1002
			ret = otp_select_filemode(mfi, arg);
			break;

1003
		case MTD_FILE_MODE_RAW:
1004 1005 1006 1007
			if (!mtd->read_oob || !mtd->write_oob)
				return -EOPNOTSUPP;
			mfi->mode = arg;

1008
		case MTD_FILE_MODE_NORMAL:
1009 1010 1011 1012 1013 1014 1015 1016
			break;
		default:
			ret = -EINVAL;
		}
		file->f_pos = 0;
		break;
	}

1017 1018
	case BLKPG:
	{
1019
		ret = mtdchar_blkpg_ioctl(mtd,
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
		      (struct blkpg_ioctl_arg __user *)arg);
		break;
	}

	case BLKRRPART:
	{
		/* No reread partition feature. Just return ok */
		ret = 0;
		break;
	}

L
Linus Torvalds 已提交
1031 1032 1033 1034 1035 1036 1037
	default:
		ret = -ENOTTY;
	}

	return ret;
} /* memory_ioctl */

1038
static long mtdchar_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
1039 1040 1041
{
	int ret;

1042
	mutex_lock(&mtd_mutex);
1043
	ret = mtdchar_ioctl(file, cmd, arg);
1044
	mutex_unlock(&mtd_mutex);
1045 1046 1047 1048

	return ret;
}

K
Kevin Cernekee 已提交
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
#ifdef CONFIG_COMPAT

struct mtd_oob_buf32 {
	u_int32_t start;
	u_int32_t length;
	compat_caddr_t ptr;	/* unsigned char* */
};

#define MEMWRITEOOB32		_IOWR('M', 3, struct mtd_oob_buf32)
#define MEMREADOOB32		_IOWR('M', 4, struct mtd_oob_buf32)

1060
static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
K
Kevin Cernekee 已提交
1061 1062 1063 1064
	unsigned long arg)
{
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
1065
	void __user *argp = compat_ptr(arg);
K
Kevin Cernekee 已提交
1066 1067
	int ret = 0;

1068
	mutex_lock(&mtd_mutex);
K
Kevin Cernekee 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078

	switch (cmd) {
	case MEMWRITEOOB32:
	{
		struct mtd_oob_buf32 buf;
		struct mtd_oob_buf32 __user *buf_user = argp;

		if (copy_from_user(&buf, argp, sizeof(buf)))
			ret = -EFAULT;
		else
1079
			ret = mtdchar_writeoob(file, mtd, buf.start,
K
Kevin Cernekee 已提交
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
				buf.length, compat_ptr(buf.ptr),
				&buf_user->length);
		break;
	}

	case MEMREADOOB32:
	{
		struct mtd_oob_buf32 buf;
		struct mtd_oob_buf32 __user *buf_user = argp;

		/* NOTE: writes return length to buf->start */
		if (copy_from_user(&buf, argp, sizeof(buf)))
			ret = -EFAULT;
		else
1094
			ret = mtdchar_readoob(file, mtd, buf.start,
K
Kevin Cernekee 已提交
1095 1096 1097 1098 1099
				buf.length, compat_ptr(buf.ptr),
				&buf_user->start);
		break;
	}
	default:
1100
		ret = mtdchar_ioctl(file, cmd, (unsigned long)argp);
K
Kevin Cernekee 已提交
1101 1102
	}

1103
	mutex_unlock(&mtd_mutex);
K
Kevin Cernekee 已提交
1104 1105 1106 1107 1108 1109

	return ret;
}

#endif /* CONFIG_COMPAT */

1110 1111 1112 1113 1114 1115
/*
 * try to determine where a shared mapping can be made
 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
 *   mappings)
 */
#ifndef CONFIG_MMU
1116
static unsigned long mtdchar_get_unmapped_area(struct file *file,
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
					   unsigned long addr,
					   unsigned long len,
					   unsigned long pgoff,
					   unsigned long flags)
{
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;

	if (mtd->get_unmapped_area) {
		unsigned long offset;

		if (addr != 0)
			return (unsigned long) -EINVAL;

		if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
			return (unsigned long) -EINVAL;

		offset = pgoff << PAGE_SHIFT;
		if (offset > mtd->size - len)
			return (unsigned long) -EINVAL;

1138
		return mtd_get_unmapped_area(mtd, len, offset, flags);
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
	}

	/* can't map directly */
	return (unsigned long) -ENOSYS;
}
#endif

/*
 * set up a mapping for shared memory segments
 */
1149
static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
1150 1151 1152 1153
{
#ifdef CONFIG_MMU
	struct mtd_file_info *mfi = file->private_data;
	struct mtd_info *mtd = mfi->mtd;
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
	struct map_info *map = mtd->priv;
	unsigned long start;
	unsigned long off;
	u32 len;

	if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
		off = vma->vm_pgoff << PAGE_SHIFT;
		start = map->phys;
		len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
		start &= PAGE_MASK;
		if ((vma->vm_end - vma->vm_start + off) > len)
			return -EINVAL;

		off += start;
		vma->vm_pgoff = off >> PAGE_SHIFT;
		vma->vm_flags |= VM_IO | VM_RESERVED;

#ifdef pgprot_noncached
		if (file->f_flags & O_DSYNC || off >= __pa(high_memory))
			vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
#endif
		if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
				       vma->vm_end - vma->vm_start,
				       vma->vm_page_prot))
			return -EAGAIN;
1179 1180

		return 0;
1181
	}
1182 1183 1184 1185 1186 1187
	return -ENOSYS;
#else
	return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS;
#endif
}

1188
static const struct file_operations mtd_fops = {
L
Linus Torvalds 已提交
1189
	.owner		= THIS_MODULE,
1190 1191 1192 1193
	.llseek		= mtdchar_lseek,
	.read		= mtdchar_read,
	.write		= mtdchar_write,
	.unlocked_ioctl	= mtdchar_unlocked_ioctl,
K
Kevin Cernekee 已提交
1194
#ifdef CONFIG_COMPAT
1195
	.compat_ioctl	= mtdchar_compat_ioctl,
K
Kevin Cernekee 已提交
1196
#endif
1197 1198 1199
	.open		= mtdchar_open,
	.release	= mtdchar_close,
	.mmap		= mtdchar_mmap,
1200
#ifndef CONFIG_MMU
1201
	.get_unmapped_area = mtdchar_get_unmapped_area,
1202
#endif
L
Linus Torvalds 已提交
1203 1204
};

A
Al Viro 已提交
1205 1206
static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type,
				int flags, const char *dev_name, void *data)
1207
{
1208
	return mount_pseudo(fs_type, "mtd_inode:", NULL, NULL, MTD_INODE_FS_MAGIC);
1209 1210 1211 1212
}

static struct file_system_type mtd_inodefs_type = {
       .name = "mtd_inodefs",
A
Al Viro 已提交
1213
       .mount = mtd_inodefs_mount,
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
       .kill_sb = kill_anon_super,
};

static void mtdchar_notify_add(struct mtd_info *mtd)
{
}

static void mtdchar_notify_remove(struct mtd_info *mtd)
{
	struct inode *mtd_ino = ilookup(mtd_inode_mnt->mnt_sb, mtd->index);

	if (mtd_ino) {
		/* Destroy the inode if it exists */
1227
		clear_nlink(mtd_ino);
1228 1229 1230 1231 1232 1233 1234 1235 1236
		iput(mtd_ino);
	}
}

static struct mtd_notifier mtdchar_notifier = {
	.add = mtdchar_notify_add,
	.remove = mtdchar_notify_remove,
};

L
Linus Torvalds 已提交
1237 1238
static int __init init_mtdchar(void)
{
1239
	int ret;
D
David Brownell 已提交
1240

1241
	ret = __register_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS,
1242
				   "mtd", &mtd_fops);
1243 1244 1245 1246
	if (ret < 0) {
		pr_notice("Can't allocate major number %d for "
				"Memory Technology Devices.\n", MTD_CHAR_MAJOR);
		return ret;
1247 1248
	}

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
	ret = register_filesystem(&mtd_inodefs_type);
	if (ret) {
		pr_notice("Can't register mtd_inodefs filesystem: %d\n", ret);
		goto err_unregister_chdev;
	}

	mtd_inode_mnt = kern_mount(&mtd_inodefs_type);
	if (IS_ERR(mtd_inode_mnt)) {
		ret = PTR_ERR(mtd_inode_mnt);
		pr_notice("Error mounting mtd_inodefs filesystem: %d\n", ret);
		goto err_unregister_filesystem;
	}
	register_mtd_user(&mtdchar_notifier);

	return ret;

err_unregister_filesystem:
	unregister_filesystem(&mtd_inodefs_type);
err_unregister_chdev:
	__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
	return ret;
L
Linus Torvalds 已提交
1270 1271 1272 1273
}

static void __exit cleanup_mtdchar(void)
{
1274
	unregister_mtd_user(&mtdchar_notifier);
1275
	kern_unmount(mtd_inode_mnt);
1276
	unregister_filesystem(&mtd_inodefs_type);
1277
	__unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
L
Linus Torvalds 已提交
1278 1279 1280 1281 1282
}

module_init(init_mtdchar);
module_exit(cleanup_mtdchar);

D
David Brownell 已提交
1283
MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
L
Linus Torvalds 已提交
1284 1285 1286 1287

MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
MODULE_DESCRIPTION("Direct character-device access to MTD devices");
1288
MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);