1 // SPDX-License-Identifier: GPL-2.0+
3 * Core registration and callback routines for MTD
6 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
7 * Copyright © 2006 Red Hat UK Limited
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/ptrace.h>
15 #include <linux/seq_file.h>
16 #include <linux/string.h>
17 #include <linux/timer.h>
18 #include <linux/major.h>
20 #include <linux/err.h>
21 #include <linux/ioctl.h>
22 #include <linux/init.h>
23 #include <linux/proc_fs.h>
24 #include <linux/idr.h>
25 #include <linux/backing-dev.h>
26 #include <linux/gfp.h>
27 #include <linux/slab.h>
29 #include <linux/err.h>
30 #include <ubi_uboot.h>
33 #include <linux/log2.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/partitions.h>
41 * backing device capabilities for non-mappable devices (such as NAND flash)
42 * - permits private mappings, copies are taken of the data
44 static struct backing_dev_info mtd_bdi_unmappable = {
45 .capabilities = BDI_CAP_MAP_COPY,
49 * backing device capabilities for R/O mappable devices (such as ROM)
50 * - permits private mappings, copies are taken of the data
51 * - permits non-writable shared mappings
53 static struct backing_dev_info mtd_bdi_ro_mappable = {
54 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
55 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
59 * backing device capabilities for writable mappable devices (such as RAM)
60 * - permits private mappings, copies are taken of the data
61 * - permits non-writable shared mappings
63 static struct backing_dev_info mtd_bdi_rw_mappable = {
64 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
65 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
69 static int mtd_cls_suspend(struct device *dev, pm_message_t state);
70 static int mtd_cls_resume(struct device *dev);
72 static struct class mtd_class = {
75 .suspend = mtd_cls_suspend,
76 .resume = mtd_cls_resume,
79 struct mtd_info *mtd_table[MAX_MTD_DEVICES];
89 struct idr_layer id[MAX_IDR_ID];
92 #define DEFINE_IDR(name) struct idr name;
94 void idr_remove(struct idr *idp, int id)
101 void *idr_find(struct idr *idp, int id)
103 if (idp->id[id].used)
104 return idp->id[id].ptr;
109 void *idr_get_next(struct idr *idp, int *next)
114 ret = idr_find(idp, id);
117 if (!idp->id[id].used)
127 int idr_alloc(struct idr *idp, void *ptr, int start, int end, gfp_t gfp_mask)
129 struct idr_layer *idl;
132 while (i < MAX_IDR_ID) {
134 if (idl->used == 0) {
145 static DEFINE_IDR(mtd_idr);
147 /* These are exported solely for the purpose of mtd_blkdevs.c. You
148 should not use them for _anything_ else */
149 DEFINE_MUTEX(mtd_table_mutex);
150 EXPORT_SYMBOL_GPL(mtd_table_mutex);
152 struct mtd_info *__mtd_next_device(int i)
154 return idr_get_next(&mtd_idr, &i);
156 EXPORT_SYMBOL_GPL(__mtd_next_device);
159 static LIST_HEAD(mtd_notifiers);
162 #define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)
164 /* REVISIT once MTD uses the driver model better, whoever allocates
165 * the mtd_info will probably want to use the release() hook...
167 static void mtd_release(struct device *dev)
169 struct mtd_info __maybe_unused *mtd = dev_get_drvdata(dev);
170 dev_t index = MTD_DEVT(mtd->index);
172 /* remove /dev/mtdXro node if needed */
174 device_destroy(&mtd_class, index + 1);
177 static int mtd_cls_suspend(struct device *dev, pm_message_t state)
179 struct mtd_info *mtd = dev_get_drvdata(dev);
181 return mtd ? mtd_suspend(mtd) : 0;
184 static int mtd_cls_resume(struct device *dev)
186 struct mtd_info *mtd = dev_get_drvdata(dev);
193 static ssize_t mtd_type_show(struct device *dev,
194 struct device_attribute *attr, char *buf)
196 struct mtd_info *mtd = dev_get_drvdata(dev);
221 case MTD_MLCNANDFLASH:
228 return snprintf(buf, PAGE_SIZE, "%s\n", type);
230 static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL);
232 static ssize_t mtd_flags_show(struct device *dev,
233 struct device_attribute *attr, char *buf)
235 struct mtd_info *mtd = dev_get_drvdata(dev);
237 return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags);
240 static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL);
242 static ssize_t mtd_size_show(struct device *dev,
243 struct device_attribute *attr, char *buf)
245 struct mtd_info *mtd = dev_get_drvdata(dev);
247 return snprintf(buf, PAGE_SIZE, "%llu\n",
248 (unsigned long long)mtd->size);
251 static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL);
253 static ssize_t mtd_erasesize_show(struct device *dev,
254 struct device_attribute *attr, char *buf)
256 struct mtd_info *mtd = dev_get_drvdata(dev);
258 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize);
261 static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL);
263 static ssize_t mtd_writesize_show(struct device *dev,
264 struct device_attribute *attr, char *buf)
266 struct mtd_info *mtd = dev_get_drvdata(dev);
268 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize);
271 static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL);
273 static ssize_t mtd_subpagesize_show(struct device *dev,
274 struct device_attribute *attr, char *buf)
276 struct mtd_info *mtd = dev_get_drvdata(dev);
277 unsigned int subpagesize = mtd->writesize >> mtd->subpage_sft;
279 return snprintf(buf, PAGE_SIZE, "%u\n", subpagesize);
282 static DEVICE_ATTR(subpagesize, S_IRUGO, mtd_subpagesize_show, NULL);
284 static ssize_t mtd_oobsize_show(struct device *dev,
285 struct device_attribute *attr, char *buf)
287 struct mtd_info *mtd = dev_get_drvdata(dev);
289 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize);
292 static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL);
294 static ssize_t mtd_numeraseregions_show(struct device *dev,
295 struct device_attribute *attr, char *buf)
297 struct mtd_info *mtd = dev_get_drvdata(dev);
299 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions);
302 static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show,
305 static ssize_t mtd_name_show(struct device *dev,
306 struct device_attribute *attr, char *buf)
308 struct mtd_info *mtd = dev_get_drvdata(dev);
310 return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name);
313 static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
315 static ssize_t mtd_ecc_strength_show(struct device *dev,
316 struct device_attribute *attr, char *buf)
318 struct mtd_info *mtd = dev_get_drvdata(dev);
320 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_strength);
322 static DEVICE_ATTR(ecc_strength, S_IRUGO, mtd_ecc_strength_show, NULL);
324 static ssize_t mtd_bitflip_threshold_show(struct device *dev,
325 struct device_attribute *attr,
328 struct mtd_info *mtd = dev_get_drvdata(dev);
330 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->bitflip_threshold);
333 static ssize_t mtd_bitflip_threshold_store(struct device *dev,
334 struct device_attribute *attr,
335 const char *buf, size_t count)
337 struct mtd_info *mtd = dev_get_drvdata(dev);
338 unsigned int bitflip_threshold;
341 retval = kstrtouint(buf, 0, &bitflip_threshold);
345 mtd->bitflip_threshold = bitflip_threshold;
348 static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
349 mtd_bitflip_threshold_show,
350 mtd_bitflip_threshold_store);
352 static ssize_t mtd_ecc_step_size_show(struct device *dev,
353 struct device_attribute *attr, char *buf)
355 struct mtd_info *mtd = dev_get_drvdata(dev);
357 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_step_size);
360 static DEVICE_ATTR(ecc_step_size, S_IRUGO, mtd_ecc_step_size_show, NULL);
362 static struct attribute *mtd_attrs[] = {
364 &dev_attr_flags.attr,
366 &dev_attr_erasesize.attr,
367 &dev_attr_writesize.attr,
368 &dev_attr_subpagesize.attr,
369 &dev_attr_oobsize.attr,
370 &dev_attr_numeraseregions.attr,
372 &dev_attr_ecc_strength.attr,
373 &dev_attr_ecc_step_size.attr,
374 &dev_attr_bitflip_threshold.attr,
377 ATTRIBUTE_GROUPS(mtd);
379 static struct device_type mtd_devtype = {
381 .groups = mtd_groups,
382 .release = mtd_release,
387 * add_mtd_device - register an MTD device
388 * @mtd: pointer to new MTD device info structure
390 * Add a device to the list of MTD devices present in the system, and
391 * notify each currently active MTD 'user' of its arrival. Returns
392 * zero on success or 1 on failure, which currently will only happen
393 * if there is insufficient memory or a sysfs error.
396 int add_mtd_device(struct mtd_info *mtd)
399 struct mtd_notifier *not;
404 if (!mtd->backing_dev_info) {
407 mtd->backing_dev_info = &mtd_bdi_rw_mappable;
410 mtd->backing_dev_info = &mtd_bdi_ro_mappable;
413 mtd->backing_dev_info = &mtd_bdi_unmappable;
419 BUG_ON(mtd->writesize == 0);
420 mutex_lock(&mtd_table_mutex);
422 i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
429 /* default value if not set by driver */
430 if (mtd->bitflip_threshold == 0)
431 mtd->bitflip_threshold = mtd->ecc_strength;
433 if (is_power_of_2(mtd->erasesize))
434 mtd->erasesize_shift = ffs(mtd->erasesize) - 1;
436 mtd->erasesize_shift = 0;
438 if (is_power_of_2(mtd->writesize))
439 mtd->writesize_shift = ffs(mtd->writesize) - 1;
441 mtd->writesize_shift = 0;
443 mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1;
444 mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
446 /* Some chips always power up locked. Unlock them now */
447 if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) {
448 error = mtd_unlock(mtd, 0, mtd->size);
449 if (error && error != -EOPNOTSUPP)
451 "%s: unlock failed, writes may not work\n",
456 /* Caller should have set dev.parent to match the
459 mtd->dev.type = &mtd_devtype;
460 mtd->dev.class = &mtd_class;
461 mtd->dev.devt = MTD_DEVT(i);
462 dev_set_name(&mtd->dev, "mtd%d", i);
463 dev_set_drvdata(&mtd->dev, mtd);
464 if (device_register(&mtd->dev) != 0)
468 device_create(&mtd_class, mtd->dev.parent,
472 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
473 /* No need to get a refcount on the module containing
474 the notifier, since we hold the mtd_table_mutex */
475 list_for_each_entry(not, &mtd_notifiers, list)
478 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
481 mutex_unlock(&mtd_table_mutex);
482 /* We _know_ we aren't being removed, because
483 our caller is still holding us here. So none
484 of this try_ nonsense, and no bitching about it
486 __module_get(THIS_MODULE);
491 idr_remove(&mtd_idr, i);
494 mutex_unlock(&mtd_table_mutex);
499 * del_mtd_device - unregister an MTD device
500 * @mtd: pointer to MTD device info structure
502 * Remove a device from the list of MTD devices present in the system,
503 * and notify each currently active MTD 'user' of its departure.
504 * Returns zero on success or 1 on failure, which currently will happen
505 * if the requested device does not appear to be present in the list.
508 int del_mtd_device(struct mtd_info *mtd)
512 struct mtd_notifier *not;
515 mutex_lock(&mtd_table_mutex);
517 if (idr_find(&mtd_idr, mtd->index) != mtd) {
523 /* No need to get a refcount on the module containing
524 the notifier, since we hold the mtd_table_mutex */
525 list_for_each_entry(not, &mtd_notifiers, list)
530 printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n",
531 mtd->index, mtd->name, mtd->usecount);
535 device_unregister(&mtd->dev);
538 idr_remove(&mtd_idr, mtd->index);
540 module_put(THIS_MODULE);
545 mutex_unlock(&mtd_table_mutex);
551 * mtd_device_parse_register - parse partitions and register an MTD device.
553 * @mtd: the MTD device to register
554 * @types: the list of MTD partition probes to try, see
555 * 'parse_mtd_partitions()' for more information
556 * @parser_data: MTD partition parser-specific data
557 * @parts: fallback partition information to register, if parsing fails;
558 * only valid if %nr_parts > %0
559 * @nr_parts: the number of partitions in parts, if zero then the full
560 * MTD device is registered if no partition info is found
562 * This function aggregates MTD partitions parsing (done by
563 * 'parse_mtd_partitions()') and MTD device and partitions registering. It
564 * basically follows the most common pattern found in many MTD drivers:
566 * * It first tries to probe partitions on MTD device @mtd using parsers
567 * specified in @types (if @types is %NULL, then the default list of parsers
568 * is used, see 'parse_mtd_partitions()' for more information). If none are
569 * found this functions tries to fallback to information specified in
571 * * If any partitioning info was found, this function registers the found
573 * * If no partitions were found this function just registers the MTD device
576 * Returns zero in case of success and a negative error code in case of failure.
578 int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
579 struct mtd_part_parser_data *parser_data,
580 const struct mtd_partition *parts,
584 struct mtd_partition *real_parts;
586 err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
587 if (err <= 0 && nr_parts && parts) {
588 real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
597 err = add_mtd_partitions(mtd, real_parts, err);
599 } else if (err == 0) {
600 err = add_mtd_device(mtd);
607 EXPORT_SYMBOL_GPL(mtd_device_parse_register);
610 * mtd_device_unregister - unregister an existing MTD device.
612 * @master: the MTD device to unregister. This will unregister both the master
613 * and any partitions if registered.
615 int mtd_device_unregister(struct mtd_info *master)
619 err = del_mtd_partitions(master);
623 if (!device_is_registered(&master->dev))
626 return del_mtd_device(master);
628 EXPORT_SYMBOL_GPL(mtd_device_unregister);
631 * register_mtd_user - register a 'user' of MTD devices.
632 * @new: pointer to notifier info structure
634 * Registers a pair of callbacks function to be called upon addition
635 * or removal of MTD devices. Causes the 'add' callback to be immediately
636 * invoked for each MTD device currently present in the system.
638 void register_mtd_user (struct mtd_notifier *new)
640 struct mtd_info *mtd;
642 mutex_lock(&mtd_table_mutex);
644 list_add(&new->list, &mtd_notifiers);
646 __module_get(THIS_MODULE);
648 mtd_for_each_device(mtd)
651 mutex_unlock(&mtd_table_mutex);
653 EXPORT_SYMBOL_GPL(register_mtd_user);
656 * unregister_mtd_user - unregister a 'user' of MTD devices.
657 * @old: pointer to notifier info structure
659 * Removes a callback function pair from the list of 'users' to be
660 * notified upon addition or removal of MTD devices. Causes the
661 * 'remove' callback to be immediately invoked for each MTD device
662 * currently present in the system.
664 int unregister_mtd_user (struct mtd_notifier *old)
666 struct mtd_info *mtd;
668 mutex_lock(&mtd_table_mutex);
670 module_put(THIS_MODULE);
672 mtd_for_each_device(mtd)
675 list_del(&old->list);
676 mutex_unlock(&mtd_table_mutex);
679 EXPORT_SYMBOL_GPL(unregister_mtd_user);
683 * get_mtd_device - obtain a validated handle for an MTD device
684 * @mtd: last known address of the required MTD device
685 * @num: internal device number of the required MTD device
687 * Given a number and NULL address, return the num'th entry in the device
688 * table, if any. Given an address and num == -1, search the device table
689 * for a device with that address and return if it's still present. Given
690 * both, return the num'th driver only if its address matches. Return
693 struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
695 struct mtd_info *ret = NULL, *other;
698 mutex_lock(&mtd_table_mutex);
701 mtd_for_each_device(other) {
707 } else if (num >= 0) {
708 ret = idr_find(&mtd_idr, num);
709 if (mtd && mtd != ret)
718 err = __get_mtd_device(ret);
722 mutex_unlock(&mtd_table_mutex);
725 EXPORT_SYMBOL_GPL(get_mtd_device);
728 int __get_mtd_device(struct mtd_info *mtd)
732 if (!try_module_get(mtd->owner))
735 if (mtd->_get_device) {
736 err = mtd->_get_device(mtd);
739 module_put(mtd->owner);
746 EXPORT_SYMBOL_GPL(__get_mtd_device);
749 * get_mtd_device_nm - obtain a validated handle for an MTD device by
751 * @name: MTD device name to open
753 * This function returns MTD device description structure in case of
754 * success and an error code in case of failure.
756 struct mtd_info *get_mtd_device_nm(const char *name)
759 struct mtd_info *mtd = NULL, *other;
761 mutex_lock(&mtd_table_mutex);
763 mtd_for_each_device(other) {
764 if (!strcmp(name, other->name)) {
773 err = __get_mtd_device(mtd);
777 mutex_unlock(&mtd_table_mutex);
781 mutex_unlock(&mtd_table_mutex);
784 EXPORT_SYMBOL_GPL(get_mtd_device_nm);
786 #if defined(CONFIG_CMD_MTDPARTS_SPREAD)
788 * mtd_get_len_incl_bad
790 * Check if length including bad blocks fits into device.
792 * @param mtd an MTD device
793 * @param offset offset in flash
794 * @param length image length
795 * @return image length including bad blocks in *len_incl_bad and whether or not
796 * the length returned was truncated in *truncated
798 void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
799 const uint64_t length, uint64_t *len_incl_bad,
805 if (!mtd->_block_isbad) {
806 *len_incl_bad = length;
810 uint64_t len_excl_bad = 0;
813 while (len_excl_bad < length) {
814 if (offset >= mtd->size) {
819 block_len = mtd->erasesize - (offset & (mtd->erasesize - 1));
821 if (!mtd->_block_isbad(mtd, offset & ~(mtd->erasesize - 1)))
822 len_excl_bad += block_len;
824 *len_incl_bad += block_len;
828 #endif /* defined(CONFIG_CMD_MTDPARTS_SPREAD) */
830 void put_mtd_device(struct mtd_info *mtd)
832 mutex_lock(&mtd_table_mutex);
833 __put_mtd_device(mtd);
834 mutex_unlock(&mtd_table_mutex);
837 EXPORT_SYMBOL_GPL(put_mtd_device);
839 void __put_mtd_device(struct mtd_info *mtd)
842 BUG_ON(mtd->usecount < 0);
844 if (mtd->_put_device)
845 mtd->_put_device(mtd);
847 module_put(mtd->owner);
849 EXPORT_SYMBOL_GPL(__put_mtd_device);
852 * Erase is an asynchronous operation. Device drivers are supposed
853 * to call instr->callback() whenever the operation completes, even
854 * if it completes with a failure.
855 * Callers are supposed to pass a callback function and wait for it
856 * to be called before writing to the block.
858 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
860 if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr)
862 if (!(mtd->flags & MTD_WRITEABLE))
864 instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN;
866 instr->state = MTD_ERASE_DONE;
867 mtd_erase_callback(instr);
870 return mtd->_erase(mtd, instr);
872 EXPORT_SYMBOL_GPL(mtd_erase);
876 * This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
878 int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
879 void **virt, resource_size_t *phys)
887 if (from < 0 || from > mtd->size || len > mtd->size - from)
891 return mtd->_point(mtd, from, len, retlen, virt, phys);
893 EXPORT_SYMBOL_GPL(mtd_point);
895 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
896 int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
900 if (from < 0 || from > mtd->size || len > mtd->size - from)
904 return mtd->_unpoint(mtd, from, len);
906 EXPORT_SYMBOL_GPL(mtd_unpoint);
910 * Allow NOMMU mmap() to directly map the device (if not NULL)
911 * - return the address to which the offset maps
912 * - return -ENOSYS to indicate refusal to do the mapping
914 unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
915 unsigned long offset, unsigned long flags)
917 if (!mtd->_get_unmapped_area)
919 if (offset > mtd->size || len > mtd->size - offset)
921 return mtd->_get_unmapped_area(mtd, len, offset, flags);
923 EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
925 int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
930 if (from < 0 || from > mtd->size || len > mtd->size - from)
936 * In the absence of an error, drivers return a non-negative integer
937 * representing the maximum number of bitflips that were corrected on
938 * any one ecc region (if applicable; zero otherwise).
941 ret_code = mtd->_read(mtd, from, len, retlen, buf);
942 } else if (mtd->_read_oob) {
943 struct mtd_oob_ops ops = {
948 ret_code = mtd->_read_oob(mtd, from, &ops);
949 *retlen = ops.retlen;
954 if (unlikely(ret_code < 0))
956 if (mtd->ecc_strength == 0)
957 return 0; /* device lacks ecc */
958 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
960 EXPORT_SYMBOL_GPL(mtd_read);
962 int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
966 if (to < 0 || to > mtd->size || len > mtd->size - to)
968 if ((!mtd->_write && !mtd->_write_oob) ||
969 !(mtd->flags & MTD_WRITEABLE))
975 struct mtd_oob_ops ops = {
981 ret = mtd->_write_oob(mtd, to, &ops);
982 *retlen = ops.retlen;
986 return mtd->_write(mtd, to, len, retlen, buf);
988 EXPORT_SYMBOL_GPL(mtd_write);
991 * In blackbox flight recorder like scenarios we want to make successful writes
992 * in interrupt context. panic_write() is only intended to be called when its
993 * known the kernel is about to panic and we need the write to succeed. Since
994 * the kernel is not going to be running for much longer, this function can
995 * break locks and delay to ensure the write succeeds (but not sleep).
997 int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
1001 if (!mtd->_panic_write)
1003 if (to < 0 || to > mtd->size || len > mtd->size - to)
1005 if (!(mtd->flags & MTD_WRITEABLE))
1009 return mtd->_panic_write(mtd, to, len, retlen, buf);
1011 EXPORT_SYMBOL_GPL(mtd_panic_write);
1013 static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs,
1014 struct mtd_oob_ops *ops)
1017 * Some users are setting ->datbuf or ->oobbuf to NULL, but are leaving
1018 * ->len or ->ooblen uninitialized. Force ->len and ->ooblen to 0 in
1027 if (offs < 0 || offs + ops->len > mtd->size)
1033 if (ops->ooboffs >= mtd_oobavail(mtd, ops))
1036 maxooblen = ((mtd_div_by_ws(mtd->size, mtd) -
1037 mtd_div_by_ws(offs, mtd)) *
1038 mtd_oobavail(mtd, ops)) - ops->ooboffs;
1039 if (ops->ooblen > maxooblen)
1046 int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
1049 ops->retlen = ops->oobretlen = 0;
1050 if (!mtd->_read_oob)
1053 ret_code = mtd_check_oob_ops(mtd, from, ops);
1058 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
1059 * similar to mtd->_read(), returning a non-negative integer
1060 * representing max bitflips. In other cases, mtd->_read_oob() may
1061 * return -EUCLEAN. In all cases, perform similar logic to mtd_read().
1063 ret_code = mtd->_read_oob(mtd, from, ops);
1064 if (unlikely(ret_code < 0))
1066 if (mtd->ecc_strength == 0)
1067 return 0; /* device lacks ecc */
1068 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
1070 EXPORT_SYMBOL_GPL(mtd_read_oob);
1072 int mtd_write_oob(struct mtd_info *mtd, loff_t to,
1073 struct mtd_oob_ops *ops)
1077 ops->retlen = ops->oobretlen = 0;
1078 if (!mtd->_write_oob)
1080 if (!(mtd->flags & MTD_WRITEABLE))
1083 ret = mtd_check_oob_ops(mtd, to, ops);
1087 return mtd->_write_oob(mtd, to, ops);
1089 EXPORT_SYMBOL_GPL(mtd_write_oob);
1092 * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
1093 * @mtd: MTD device structure
1094 * @section: ECC section. Depending on the layout you may have all the ECC
1095 * bytes stored in a single contiguous section, or one section
1096 * per ECC chunk (and sometime several sections for a single ECC
1098 * @oobecc: OOB region struct filled with the appropriate ECC position
1101 * This function returns ECC section information in the OOB area. If you want
1102 * to get all the ECC bytes information, then you should call
1103 * mtd_ooblayout_ecc(mtd, section++, oobecc) until it returns -ERANGE.
1105 * Returns zero on success, a negative error code otherwise.
1107 int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
1108 struct mtd_oob_region *oobecc)
1110 memset(oobecc, 0, sizeof(*oobecc));
1112 if (!mtd || section < 0)
1115 if (!mtd->ooblayout || !mtd->ooblayout->ecc)
1118 return mtd->ooblayout->ecc(mtd, section, oobecc);
1120 EXPORT_SYMBOL_GPL(mtd_ooblayout_ecc);
1123 * mtd_ooblayout_free - Get the OOB region definition of a specific free
1125 * @mtd: MTD device structure
1126 * @section: Free section you are interested in. Depending on the layout
1127 * you may have all the free bytes stored in a single contiguous
1128 * section, or one section per ECC chunk plus an extra section
1129 * for the remaining bytes (or other funky layout).
1130 * @oobfree: OOB region struct filled with the appropriate free position
1133 * This function returns free bytes position in the OOB area. If you want
1134 * to get all the free bytes information, then you should call
1135 * mtd_ooblayout_free(mtd, section++, oobfree) until it returns -ERANGE.
1137 * Returns zero on success, a negative error code otherwise.
1139 int mtd_ooblayout_free(struct mtd_info *mtd, int section,
1140 struct mtd_oob_region *oobfree)
1142 memset(oobfree, 0, sizeof(*oobfree));
1144 if (!mtd || section < 0)
1147 if (!mtd->ooblayout || !mtd->ooblayout->free)
1150 return mtd->ooblayout->free(mtd, section, oobfree);
1152 EXPORT_SYMBOL_GPL(mtd_ooblayout_free);
1155 * mtd_ooblayout_find_region - Find the region attached to a specific byte
1156 * @mtd: mtd info structure
1157 * @byte: the byte we are searching for
1158 * @sectionp: pointer where the section id will be stored
1159 * @oobregion: used to retrieve the ECC position
1160 * @iter: iterator function. Should be either mtd_ooblayout_free or
1161 * mtd_ooblayout_ecc depending on the region type you're searching for
1163 * This function returns the section id and oobregion information of a
1164 * specific byte. For example, say you want to know where the 4th ECC byte is
1165 * stored, you'll use:
1167 * mtd_ooblayout_find_region(mtd, 3, §ion, &oobregion, mtd_ooblayout_ecc);
1169 * Returns zero on success, a negative error code otherwise.
1171 static int mtd_ooblayout_find_region(struct mtd_info *mtd, int byte,
1172 int *sectionp, struct mtd_oob_region *oobregion,
1173 int (*iter)(struct mtd_info *,
1175 struct mtd_oob_region *oobregion))
1177 int pos = 0, ret, section = 0;
1179 memset(oobregion, 0, sizeof(*oobregion));
1182 ret = iter(mtd, section, oobregion);
1186 if (pos + oobregion->length > byte)
1189 pos += oobregion->length;
1194 * Adjust region info to make it start at the beginning at the
1197 oobregion->offset += byte - pos;
1198 oobregion->length -= byte - pos;
1199 *sectionp = section;
1205 * mtd_ooblayout_find_eccregion - Find the ECC region attached to a specific
1207 * @mtd: mtd info structure
1208 * @eccbyte: the byte we are searching for
1209 * @sectionp: pointer where the section id will be stored
1210 * @oobregion: OOB region information
1212 * Works like mtd_ooblayout_find_region() except it searches for a specific ECC
1215 * Returns zero on success, a negative error code otherwise.
1217 int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
1219 struct mtd_oob_region *oobregion)
1221 return mtd_ooblayout_find_region(mtd, eccbyte, section, oobregion,
1224 EXPORT_SYMBOL_GPL(mtd_ooblayout_find_eccregion);
1227 * mtd_ooblayout_get_bytes - Extract OOB bytes from the oob buffer
1228 * @mtd: mtd info structure
1229 * @buf: destination buffer to store OOB bytes
1230 * @oobbuf: OOB buffer
1231 * @start: first byte to retrieve
1232 * @nbytes: number of bytes to retrieve
1233 * @iter: section iterator
1235 * Extract bytes attached to a specific category (ECC or free)
1236 * from the OOB buffer and copy them into buf.
1238 * Returns zero on success, a negative error code otherwise.
1240 static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,
1241 const u8 *oobbuf, int start, int nbytes,
1242 int (*iter)(struct mtd_info *,
1244 struct mtd_oob_region *oobregion))
1246 struct mtd_oob_region oobregion;
1249 ret = mtd_ooblayout_find_region(mtd, start, §ion,
1255 cnt = min_t(int, nbytes, oobregion.length);
1256 memcpy(buf, oobbuf + oobregion.offset, cnt);
1263 ret = iter(mtd, ++section, &oobregion);
1270 * mtd_ooblayout_set_bytes - put OOB bytes into the oob buffer
1271 * @mtd: mtd info structure
1272 * @buf: source buffer to get OOB bytes from
1273 * @oobbuf: OOB buffer
1274 * @start: first OOB byte to set
1275 * @nbytes: number of OOB bytes to set
1276 * @iter: section iterator
1278 * Fill the OOB buffer with data provided in buf. The category (ECC or free)
1279 * is selected by passing the appropriate iterator.
1281 * Returns zero on success, a negative error code otherwise.
1283 static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,
1284 u8 *oobbuf, int start, int nbytes,
1285 int (*iter)(struct mtd_info *,
1287 struct mtd_oob_region *oobregion))
1289 struct mtd_oob_region oobregion;
1292 ret = mtd_ooblayout_find_region(mtd, start, §ion,
1298 cnt = min_t(int, nbytes, oobregion.length);
1299 memcpy(oobbuf + oobregion.offset, buf, cnt);
1306 ret = iter(mtd, ++section, &oobregion);
1313 * mtd_ooblayout_count_bytes - count the number of bytes in a OOB category
1314 * @mtd: mtd info structure
1315 * @iter: category iterator
1317 * Count the number of bytes in a given category.
1319 * Returns a positive value on success, a negative error code otherwise.
1321 static int mtd_ooblayout_count_bytes(struct mtd_info *mtd,
1322 int (*iter)(struct mtd_info *,
1324 struct mtd_oob_region *oobregion))
1326 struct mtd_oob_region oobregion;
1327 int section = 0, ret, nbytes = 0;
1330 ret = iter(mtd, section++, &oobregion);
1337 nbytes += oobregion.length;
1344 * mtd_ooblayout_get_eccbytes - extract ECC bytes from the oob buffer
1345 * @mtd: mtd info structure
1346 * @eccbuf: destination buffer to store ECC bytes
1347 * @oobbuf: OOB buffer
1348 * @start: first ECC byte to retrieve
1349 * @nbytes: number of ECC bytes to retrieve
1351 * Works like mtd_ooblayout_get_bytes(), except it acts on ECC bytes.
1353 * Returns zero on success, a negative error code otherwise.
1355 int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
1356 const u8 *oobbuf, int start, int nbytes)
1358 return mtd_ooblayout_get_bytes(mtd, eccbuf, oobbuf, start, nbytes,
1361 EXPORT_SYMBOL_GPL(mtd_ooblayout_get_eccbytes);
1364 * mtd_ooblayout_set_eccbytes - set ECC bytes into the oob buffer
1365 * @mtd: mtd info structure
1366 * @eccbuf: source buffer to get ECC bytes from
1367 * @oobbuf: OOB buffer
1368 * @start: first ECC byte to set
1369 * @nbytes: number of ECC bytes to set
1371 * Works like mtd_ooblayout_set_bytes(), except it acts on ECC bytes.
1373 * Returns zero on success, a negative error code otherwise.
1375 int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
1376 u8 *oobbuf, int start, int nbytes)
1378 return mtd_ooblayout_set_bytes(mtd, eccbuf, oobbuf, start, nbytes,
1381 EXPORT_SYMBOL_GPL(mtd_ooblayout_set_eccbytes);
1384 * mtd_ooblayout_get_databytes - extract data bytes from the oob buffer
1385 * @mtd: mtd info structure
1386 * @databuf: destination buffer to store ECC bytes
1387 * @oobbuf: OOB buffer
1388 * @start: first ECC byte to retrieve
1389 * @nbytes: number of ECC bytes to retrieve
1391 * Works like mtd_ooblayout_get_bytes(), except it acts on free bytes.
1393 * Returns zero on success, a negative error code otherwise.
1395 int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
1396 const u8 *oobbuf, int start, int nbytes)
1398 return mtd_ooblayout_get_bytes(mtd, databuf, oobbuf, start, nbytes,
1399 mtd_ooblayout_free);
1401 EXPORT_SYMBOL_GPL(mtd_ooblayout_get_databytes);
1404 * mtd_ooblayout_get_eccbytes - set data bytes into the oob buffer
1405 * @mtd: mtd info structure
1406 * @eccbuf: source buffer to get data bytes from
1407 * @oobbuf: OOB buffer
1408 * @start: first ECC byte to set
1409 * @nbytes: number of ECC bytes to set
1411 * Works like mtd_ooblayout_get_bytes(), except it acts on free bytes.
1413 * Returns zero on success, a negative error code otherwise.
1415 int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
1416 u8 *oobbuf, int start, int nbytes)
1418 return mtd_ooblayout_set_bytes(mtd, databuf, oobbuf, start, nbytes,
1419 mtd_ooblayout_free);
1421 EXPORT_SYMBOL_GPL(mtd_ooblayout_set_databytes);
1424 * mtd_ooblayout_count_freebytes - count the number of free bytes in OOB
1425 * @mtd: mtd info structure
1427 * Works like mtd_ooblayout_count_bytes(), except it count free bytes.
1429 * Returns zero on success, a negative error code otherwise.
1431 int mtd_ooblayout_count_freebytes(struct mtd_info *mtd)
1433 return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_free);
1435 EXPORT_SYMBOL_GPL(mtd_ooblayout_count_freebytes);
1438 * mtd_ooblayout_count_freebytes - count the number of ECC bytes in OOB
1439 * @mtd: mtd info structure
1441 * Works like mtd_ooblayout_count_bytes(), except it count ECC bytes.
1443 * Returns zero on success, a negative error code otherwise.
1445 int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd)
1447 return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_ecc);
1449 EXPORT_SYMBOL_GPL(mtd_ooblayout_count_eccbytes);
1452 * Method to access the protection register area, present in some flash
1453 * devices. The user data is one time programmable but the factory data is read
1456 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
1457 struct otp_info *buf)
1459 if (!mtd->_get_fact_prot_info)
1463 return mtd->_get_fact_prot_info(mtd, len, retlen, buf);
1465 EXPORT_SYMBOL_GPL(mtd_get_fact_prot_info);
1467 int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
1468 size_t *retlen, u_char *buf)
1471 if (!mtd->_read_fact_prot_reg)
1475 return mtd->_read_fact_prot_reg(mtd, from, len, retlen, buf);
1477 EXPORT_SYMBOL_GPL(mtd_read_fact_prot_reg);
1479 int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
1480 struct otp_info *buf)
1482 if (!mtd->_get_user_prot_info)
1486 return mtd->_get_user_prot_info(mtd, len, retlen, buf);
1488 EXPORT_SYMBOL_GPL(mtd_get_user_prot_info);
1490 int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
1491 size_t *retlen, u_char *buf)
1494 if (!mtd->_read_user_prot_reg)
1498 return mtd->_read_user_prot_reg(mtd, from, len, retlen, buf);
1500 EXPORT_SYMBOL_GPL(mtd_read_user_prot_reg);
1502 int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
1503 size_t *retlen, u_char *buf)
1508 if (!mtd->_write_user_prot_reg)
1512 ret = mtd->_write_user_prot_reg(mtd, to, len, retlen, buf);
1517 * If no data could be written at all, we are out of memory and
1518 * must return -ENOSPC.
1520 return (*retlen) ? 0 : -ENOSPC;
1522 EXPORT_SYMBOL_GPL(mtd_write_user_prot_reg);
1524 int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len)
1526 if (!mtd->_lock_user_prot_reg)
1530 return mtd->_lock_user_prot_reg(mtd, from, len);
1532 EXPORT_SYMBOL_GPL(mtd_lock_user_prot_reg);
1534 /* Chip-supported device locking */
1535 int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1539 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1543 return mtd->_lock(mtd, ofs, len);
1545 EXPORT_SYMBOL_GPL(mtd_lock);
1547 int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1551 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1555 return mtd->_unlock(mtd, ofs, len);
1557 EXPORT_SYMBOL_GPL(mtd_unlock);
1559 int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1561 if (!mtd->_is_locked)
1563 if (ofs < 0 || ofs > mtd->size || len > mtd->size - ofs)
1567 return mtd->_is_locked(mtd, ofs, len);
1569 EXPORT_SYMBOL_GPL(mtd_is_locked);
1571 int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs)
1573 if (ofs < 0 || ofs > mtd->size)
1575 if (!mtd->_block_isreserved)
1577 return mtd->_block_isreserved(mtd, ofs);
1579 EXPORT_SYMBOL_GPL(mtd_block_isreserved);
1581 int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs)
1583 if (ofs < 0 || ofs > mtd->size)
1585 if (!mtd->_block_isbad)
1587 return mtd->_block_isbad(mtd, ofs);
1589 EXPORT_SYMBOL_GPL(mtd_block_isbad);
1591 int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
1593 if (!mtd->_block_markbad)
1595 if (ofs < 0 || ofs > mtd->size)
1597 if (!(mtd->flags & MTD_WRITEABLE))
1599 return mtd->_block_markbad(mtd, ofs);
1601 EXPORT_SYMBOL_GPL(mtd_block_markbad);
1605 * default_mtd_writev - the default writev method
1606 * @mtd: mtd device description object pointer
1607 * @vecs: the vectors to write
1608 * @count: count of vectors in @vecs
1609 * @to: the MTD device offset to write to
1610 * @retlen: on exit contains the count of bytes written to the MTD device.
1612 * This function returns zero in case of success and a negative error code in
1615 static int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
1616 unsigned long count, loff_t to, size_t *retlen)
1619 size_t totlen = 0, thislen;
1622 for (i = 0; i < count; i++) {
1623 if (!vecs[i].iov_len)
1625 ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen,
1628 if (ret || thislen != vecs[i].iov_len)
1630 to += vecs[i].iov_len;
1637 * mtd_writev - the vector-based MTD write method
1638 * @mtd: mtd device description object pointer
1639 * @vecs: the vectors to write
1640 * @count: count of vectors in @vecs
1641 * @to: the MTD device offset to write to
1642 * @retlen: on exit contains the count of bytes written to the MTD device.
1644 * This function returns zero in case of success and a negative error code in
1647 int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
1648 unsigned long count, loff_t to, size_t *retlen)
1651 if (!(mtd->flags & MTD_WRITEABLE))
1654 return default_mtd_writev(mtd, vecs, count, to, retlen);
1655 return mtd->_writev(mtd, vecs, count, to, retlen);
1657 EXPORT_SYMBOL_GPL(mtd_writev);
1660 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
1661 * @mtd: mtd device description object pointer
1662 * @size: a pointer to the ideal or maximum size of the allocation, points
1663 * to the actual allocation size on success.
1665 * This routine attempts to allocate a contiguous kernel buffer up to
1666 * the specified size, backing off the size of the request exponentially
1667 * until the request succeeds or until the allocation size falls below
1668 * the system page size. This attempts to make sure it does not adversely
1669 * impact system performance, so when allocating more than one page, we
1670 * ask the memory allocator to avoid re-trying, swapping, writing back
1671 * or performing I/O.
1673 * Note, this function also makes sure that the allocated buffer is aligned to
1674 * the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.
1676 * This is called, for example by mtd_{read,write} and jffs2_scan_medium,
1677 * to handle smaller (i.e. degraded) buffer allocations under low- or
1678 * fragmented-memory situations where such reduced allocations, from a
1679 * requested ideal, are allowed.
1681 * Returns a pointer to the allocated buffer on success; otherwise, NULL.
1683 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
1685 gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
1686 __GFP_NORETRY | __GFP_NO_KSWAPD;
1687 size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
1690 *size = min_t(size_t, *size, KMALLOC_MAX_SIZE);
1692 while (*size > min_alloc) {
1693 kbuf = kmalloc(*size, flags);
1698 *size = ALIGN(*size, mtd->writesize);
1702 * For the last resort allocation allow 'kmalloc()' to do all sorts of
1703 * things (write-back, dropping caches, etc) by using GFP_KERNEL.
1705 return kmalloc(*size, GFP_KERNEL);
1707 EXPORT_SYMBOL_GPL(mtd_kmalloc_up_to);
1710 #ifdef CONFIG_PROC_FS
1712 /*====================================================================*/
1713 /* Support for /proc/mtd */
1715 static int mtd_proc_show(struct seq_file *m, void *v)
1717 struct mtd_info *mtd;
1719 seq_puts(m, "dev: size erasesize name\n");
1720 mutex_lock(&mtd_table_mutex);
1721 mtd_for_each_device(mtd) {
1722 seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
1723 mtd->index, (unsigned long long)mtd->size,
1724 mtd->erasesize, mtd->name);
1726 mutex_unlock(&mtd_table_mutex);
1730 static int mtd_proc_open(struct inode *inode, struct file *file)
1732 return single_open(file, mtd_proc_show, NULL);
1735 static const struct file_operations mtd_proc_ops = {
1736 .open = mtd_proc_open,
1738 .llseek = seq_lseek,
1739 .release = single_release,
1741 #endif /* CONFIG_PROC_FS */
1743 /*====================================================================*/
1747 static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)
1751 ret = bdi_init(bdi);
1753 ret = bdi_register(bdi, NULL, "%s", name);
1761 static struct proc_dir_entry *proc_mtd;
1763 static int __init init_mtd(void)
1767 ret = class_register(&mtd_class);
1771 ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap");
1775 ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
1779 ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
1783 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
1785 ret = init_mtdchar();
1793 remove_proc_entry("mtd", NULL);
1795 bdi_destroy(&mtd_bdi_ro_mappable);
1797 bdi_destroy(&mtd_bdi_unmappable);
1799 class_unregister(&mtd_class);
1801 pr_err("Error registering mtd class or bdi: %d\n", ret);
1805 static void __exit cleanup_mtd(void)
1809 remove_proc_entry("mtd", NULL);
1810 class_unregister(&mtd_class);
1811 bdi_destroy(&mtd_bdi_unmappable);
1812 bdi_destroy(&mtd_bdi_ro_mappable);
1813 bdi_destroy(&mtd_bdi_rw_mappable);
1816 module_init(init_mtd);
1817 module_exit(cleanup_mtd);
1820 MODULE_LICENSE("GPL");
1821 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
1822 MODULE_DESCRIPTION("Core MTD registration and access routines");