Bluetooth: hci_uart: Use generic functionality from Broadcom module
[linux/fpc-iii.git] / drivers / mtd / mtdpart.c
blobe779de315ade505f1a508edefc541f7a4223af97
1 /*
2 * Simple MTD partitioning layer
4 * Copyright © 2000 Nicolas Pitre <nico@fluxnic.net>
5 * Copyright © 2002 Thomas Gleixner <gleixner@linutronix.de>
6 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/list.h>
29 #include <linux/kmod.h>
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/partitions.h>
32 #include <linux/err.h>
34 #include "mtdcore.h"
36 /* Our partition linked list */
37 static LIST_HEAD(mtd_partitions);
38 static DEFINE_MUTEX(mtd_partitions_mutex);
40 /* Our partition node structure */
41 struct mtd_part {
42 struct mtd_info mtd;
43 struct mtd_info *master;
44 uint64_t offset;
45 struct list_head list;
49 * Given a pointer to the MTD object in the mtd_part structure, we can retrieve
50 * the pointer to that structure with this macro.
52 #define PART(x) ((struct mtd_part *)(x))
56 * MTD methods which simply translate the effective address and pass through
57 * to the _real_ device.
60 static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
61 size_t *retlen, u_char *buf)
63 struct mtd_part *part = PART(mtd);
64 struct mtd_ecc_stats stats;
65 int res;
67 stats = part->master->ecc_stats;
68 res = part->master->_read(part->master, from + part->offset, len,
69 retlen, buf);
70 if (unlikely(mtd_is_eccerr(res)))
71 mtd->ecc_stats.failed +=
72 part->master->ecc_stats.failed - stats.failed;
73 else
74 mtd->ecc_stats.corrected +=
75 part->master->ecc_stats.corrected - stats.corrected;
76 return res;
79 static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
80 size_t *retlen, void **virt, resource_size_t *phys)
82 struct mtd_part *part = PART(mtd);
84 return part->master->_point(part->master, from + part->offset, len,
85 retlen, virt, phys);
88 static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
90 struct mtd_part *part = PART(mtd);
92 return part->master->_unpoint(part->master, from + part->offset, len);
95 static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
96 unsigned long len,
97 unsigned long offset,
98 unsigned long flags)
100 struct mtd_part *part = PART(mtd);
102 offset += part->offset;
103 return part->master->_get_unmapped_area(part->master, len, offset,
104 flags);
107 static int part_read_oob(struct mtd_info *mtd, loff_t from,
108 struct mtd_oob_ops *ops)
110 struct mtd_part *part = PART(mtd);
111 int res;
113 if (from >= mtd->size)
114 return -EINVAL;
115 if (ops->datbuf && from + ops->len > mtd->size)
116 return -EINVAL;
119 * If OOB is also requested, make sure that we do not read past the end
120 * of this partition.
122 if (ops->oobbuf) {
123 size_t len, pages;
125 if (ops->mode == MTD_OPS_AUTO_OOB)
126 len = mtd->oobavail;
127 else
128 len = mtd->oobsize;
129 pages = mtd_div_by_ws(mtd->size, mtd);
130 pages -= mtd_div_by_ws(from, mtd);
131 if (ops->ooboffs + ops->ooblen > pages * len)
132 return -EINVAL;
135 res = part->master->_read_oob(part->master, from + part->offset, ops);
136 if (unlikely(res)) {
137 if (mtd_is_bitflip(res))
138 mtd->ecc_stats.corrected++;
139 if (mtd_is_eccerr(res))
140 mtd->ecc_stats.failed++;
142 return res;
145 static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
146 size_t len, size_t *retlen, u_char *buf)
148 struct mtd_part *part = PART(mtd);
149 return part->master->_read_user_prot_reg(part->master, from, len,
150 retlen, buf);
153 static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
154 size_t *retlen, struct otp_info *buf)
156 struct mtd_part *part = PART(mtd);
157 return part->master->_get_user_prot_info(part->master, len, retlen,
158 buf);
161 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
162 size_t len, size_t *retlen, u_char *buf)
164 struct mtd_part *part = PART(mtd);
165 return part->master->_read_fact_prot_reg(part->master, from, len,
166 retlen, buf);
169 static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
170 size_t *retlen, struct otp_info *buf)
172 struct mtd_part *part = PART(mtd);
173 return part->master->_get_fact_prot_info(part->master, len, retlen,
174 buf);
177 static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
178 size_t *retlen, const u_char *buf)
180 struct mtd_part *part = PART(mtd);
181 return part->master->_write(part->master, to + part->offset, len,
182 retlen, buf);
185 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
186 size_t *retlen, const u_char *buf)
188 struct mtd_part *part = PART(mtd);
189 return part->master->_panic_write(part->master, to + part->offset, len,
190 retlen, buf);
193 static int part_write_oob(struct mtd_info *mtd, loff_t to,
194 struct mtd_oob_ops *ops)
196 struct mtd_part *part = PART(mtd);
198 if (to >= mtd->size)
199 return -EINVAL;
200 if (ops->datbuf && to + ops->len > mtd->size)
201 return -EINVAL;
202 return part->master->_write_oob(part->master, to + part->offset, ops);
205 static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
206 size_t len, size_t *retlen, u_char *buf)
208 struct mtd_part *part = PART(mtd);
209 return part->master->_write_user_prot_reg(part->master, from, len,
210 retlen, buf);
213 static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
214 size_t len)
216 struct mtd_part *part = PART(mtd);
217 return part->master->_lock_user_prot_reg(part->master, from, len);
220 static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
221 unsigned long count, loff_t to, size_t *retlen)
223 struct mtd_part *part = PART(mtd);
224 return part->master->_writev(part->master, vecs, count,
225 to + part->offset, retlen);
228 static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
230 struct mtd_part *part = PART(mtd);
231 int ret;
233 instr->addr += part->offset;
234 ret = part->master->_erase(part->master, instr);
235 if (ret) {
236 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
237 instr->fail_addr -= part->offset;
238 instr->addr -= part->offset;
240 return ret;
243 void mtd_erase_callback(struct erase_info *instr)
245 if (instr->mtd->_erase == part_erase) {
246 struct mtd_part *part = PART(instr->mtd);
248 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
249 instr->fail_addr -= part->offset;
250 instr->addr -= part->offset;
252 if (instr->callback)
253 instr->callback(instr);
255 EXPORT_SYMBOL_GPL(mtd_erase_callback);
257 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
259 struct mtd_part *part = PART(mtd);
260 return part->master->_lock(part->master, ofs + part->offset, len);
263 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
265 struct mtd_part *part = PART(mtd);
266 return part->master->_unlock(part->master, ofs + part->offset, len);
269 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
271 struct mtd_part *part = PART(mtd);
272 return part->master->_is_locked(part->master, ofs + part->offset, len);
275 static void part_sync(struct mtd_info *mtd)
277 struct mtd_part *part = PART(mtd);
278 part->master->_sync(part->master);
281 static int part_suspend(struct mtd_info *mtd)
283 struct mtd_part *part = PART(mtd);
284 return part->master->_suspend(part->master);
287 static void part_resume(struct mtd_info *mtd)
289 struct mtd_part *part = PART(mtd);
290 part->master->_resume(part->master);
293 static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
295 struct mtd_part *part = PART(mtd);
296 ofs += part->offset;
297 return part->master->_block_isreserved(part->master, ofs);
300 static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
302 struct mtd_part *part = PART(mtd);
303 ofs += part->offset;
304 return part->master->_block_isbad(part->master, ofs);
307 static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
309 struct mtd_part *part = PART(mtd);
310 int res;
312 ofs += part->offset;
313 res = part->master->_block_markbad(part->master, ofs);
314 if (!res)
315 mtd->ecc_stats.badblocks++;
316 return res;
319 static inline void free_partition(struct mtd_part *p)
321 kfree(p->mtd.name);
322 kfree(p);
326 * This function unregisters and destroy all slave MTD objects which are
327 * attached to the given master MTD object.
330 int del_mtd_partitions(struct mtd_info *master)
332 struct mtd_part *slave, *next;
333 int ret, err = 0;
335 mutex_lock(&mtd_partitions_mutex);
336 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
337 if (slave->master == master) {
338 ret = del_mtd_device(&slave->mtd);
339 if (ret < 0) {
340 err = ret;
341 continue;
343 list_del(&slave->list);
344 free_partition(slave);
346 mutex_unlock(&mtd_partitions_mutex);
348 return err;
351 static struct mtd_part *allocate_partition(struct mtd_info *master,
352 const struct mtd_partition *part, int partno,
353 uint64_t cur_offset)
355 struct mtd_part *slave;
356 char *name;
358 /* allocate the partition structure */
359 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
360 name = kstrdup(part->name, GFP_KERNEL);
361 if (!name || !slave) {
362 printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
363 master->name);
364 kfree(name);
365 kfree(slave);
366 return ERR_PTR(-ENOMEM);
369 /* set up the MTD object for this partition */
370 slave->mtd.type = master->type;
371 slave->mtd.flags = master->flags & ~part->mask_flags;
372 slave->mtd.size = part->size;
373 slave->mtd.writesize = master->writesize;
374 slave->mtd.writebufsize = master->writebufsize;
375 slave->mtd.oobsize = master->oobsize;
376 slave->mtd.oobavail = master->oobavail;
377 slave->mtd.subpage_sft = master->subpage_sft;
379 slave->mtd.name = name;
380 slave->mtd.owner = master->owner;
382 /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone
383 * to have the same data be in two different partitions.
385 slave->mtd.dev.parent = master->dev.parent;
387 slave->mtd._read = part_read;
388 slave->mtd._write = part_write;
390 if (master->_panic_write)
391 slave->mtd._panic_write = part_panic_write;
393 if (master->_point && master->_unpoint) {
394 slave->mtd._point = part_point;
395 slave->mtd._unpoint = part_unpoint;
398 if (master->_get_unmapped_area)
399 slave->mtd._get_unmapped_area = part_get_unmapped_area;
400 if (master->_read_oob)
401 slave->mtd._read_oob = part_read_oob;
402 if (master->_write_oob)
403 slave->mtd._write_oob = part_write_oob;
404 if (master->_read_user_prot_reg)
405 slave->mtd._read_user_prot_reg = part_read_user_prot_reg;
406 if (master->_read_fact_prot_reg)
407 slave->mtd._read_fact_prot_reg = part_read_fact_prot_reg;
408 if (master->_write_user_prot_reg)
409 slave->mtd._write_user_prot_reg = part_write_user_prot_reg;
410 if (master->_lock_user_prot_reg)
411 slave->mtd._lock_user_prot_reg = part_lock_user_prot_reg;
412 if (master->_get_user_prot_info)
413 slave->mtd._get_user_prot_info = part_get_user_prot_info;
414 if (master->_get_fact_prot_info)
415 slave->mtd._get_fact_prot_info = part_get_fact_prot_info;
416 if (master->_sync)
417 slave->mtd._sync = part_sync;
418 if (!partno && !master->dev.class && master->_suspend &&
419 master->_resume) {
420 slave->mtd._suspend = part_suspend;
421 slave->mtd._resume = part_resume;
423 if (master->_writev)
424 slave->mtd._writev = part_writev;
425 if (master->_lock)
426 slave->mtd._lock = part_lock;
427 if (master->_unlock)
428 slave->mtd._unlock = part_unlock;
429 if (master->_is_locked)
430 slave->mtd._is_locked = part_is_locked;
431 if (master->_block_isreserved)
432 slave->mtd._block_isreserved = part_block_isreserved;
433 if (master->_block_isbad)
434 slave->mtd._block_isbad = part_block_isbad;
435 if (master->_block_markbad)
436 slave->mtd._block_markbad = part_block_markbad;
437 slave->mtd._erase = part_erase;
438 slave->master = master;
439 slave->offset = part->offset;
441 if (slave->offset == MTDPART_OFS_APPEND)
442 slave->offset = cur_offset;
443 if (slave->offset == MTDPART_OFS_NXTBLK) {
444 slave->offset = cur_offset;
445 if (mtd_mod_by_eb(cur_offset, master) != 0) {
446 /* Round up to next erasesize */
447 slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
448 printk(KERN_NOTICE "Moving partition %d: "
449 "0x%012llx -> 0x%012llx\n", partno,
450 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
453 if (slave->offset == MTDPART_OFS_RETAIN) {
454 slave->offset = cur_offset;
455 if (master->size - slave->offset >= slave->mtd.size) {
456 slave->mtd.size = master->size - slave->offset
457 - slave->mtd.size;
458 } else {
459 printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
460 part->name, master->size - slave->offset,
461 slave->mtd.size);
462 /* register to preserve ordering */
463 goto out_register;
466 if (slave->mtd.size == MTDPART_SIZ_FULL)
467 slave->mtd.size = master->size - slave->offset;
469 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset,
470 (unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name);
472 /* let's do some sanity checks */
473 if (slave->offset >= master->size) {
474 /* let's register it anyway to preserve ordering */
475 slave->offset = 0;
476 slave->mtd.size = 0;
477 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
478 part->name);
479 goto out_register;
481 if (slave->offset + slave->mtd.size > master->size) {
482 slave->mtd.size = master->size - slave->offset;
483 printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
484 part->name, master->name, (unsigned long long)slave->mtd.size);
486 if (master->numeraseregions > 1) {
487 /* Deal with variable erase size stuff */
488 int i, max = master->numeraseregions;
489 u64 end = slave->offset + slave->mtd.size;
490 struct mtd_erase_region_info *regions = master->eraseregions;
492 /* Find the first erase regions which is part of this
493 * partition. */
494 for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
496 /* The loop searched for the region _behind_ the first one */
497 if (i > 0)
498 i--;
500 /* Pick biggest erasesize */
501 for (; i < max && regions[i].offset < end; i++) {
502 if (slave->mtd.erasesize < regions[i].erasesize) {
503 slave->mtd.erasesize = regions[i].erasesize;
506 BUG_ON(slave->mtd.erasesize == 0);
507 } else {
508 /* Single erase size */
509 slave->mtd.erasesize = master->erasesize;
512 if ((slave->mtd.flags & MTD_WRITEABLE) &&
513 mtd_mod_by_eb(slave->offset, &slave->mtd)) {
514 /* Doesn't start on a boundary of major erase size */
515 /* FIXME: Let it be writable if it is on a boundary of
516 * _minor_ erase size though */
517 slave->mtd.flags &= ~MTD_WRITEABLE;
518 printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
519 part->name);
521 if ((slave->mtd.flags & MTD_WRITEABLE) &&
522 mtd_mod_by_eb(slave->mtd.size, &slave->mtd)) {
523 slave->mtd.flags &= ~MTD_WRITEABLE;
524 printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
525 part->name);
528 slave->mtd.ecclayout = master->ecclayout;
529 slave->mtd.ecc_step_size = master->ecc_step_size;
530 slave->mtd.ecc_strength = master->ecc_strength;
531 slave->mtd.bitflip_threshold = master->bitflip_threshold;
533 if (master->_block_isbad) {
534 uint64_t offs = 0;
536 while (offs < slave->mtd.size) {
537 if (mtd_block_isreserved(master, offs + slave->offset))
538 slave->mtd.ecc_stats.bbtblocks++;
539 else if (mtd_block_isbad(master, offs + slave->offset))
540 slave->mtd.ecc_stats.badblocks++;
541 offs += slave->mtd.erasesize;
545 out_register:
546 return slave;
549 int mtd_add_partition(struct mtd_info *master, const char *name,
550 long long offset, long long length)
552 struct mtd_partition part;
553 struct mtd_part *p, *new;
554 uint64_t start, end;
555 int ret = 0;
557 /* the direct offset is expected */
558 if (offset == MTDPART_OFS_APPEND ||
559 offset == MTDPART_OFS_NXTBLK)
560 return -EINVAL;
562 if (length == MTDPART_SIZ_FULL)
563 length = master->size - offset;
565 if (length <= 0)
566 return -EINVAL;
568 part.name = name;
569 part.size = length;
570 part.offset = offset;
571 part.mask_flags = 0;
572 part.ecclayout = NULL;
574 new = allocate_partition(master, &part, -1, offset);
575 if (IS_ERR(new))
576 return PTR_ERR(new);
578 start = offset;
579 end = offset + length;
581 mutex_lock(&mtd_partitions_mutex);
582 list_for_each_entry(p, &mtd_partitions, list)
583 if (p->master == master) {
584 if ((start >= p->offset) &&
585 (start < (p->offset + p->mtd.size)))
586 goto err_inv;
588 if ((end >= p->offset) &&
589 (end < (p->offset + p->mtd.size)))
590 goto err_inv;
593 list_add(&new->list, &mtd_partitions);
594 mutex_unlock(&mtd_partitions_mutex);
596 add_mtd_device(&new->mtd);
598 return ret;
599 err_inv:
600 mutex_unlock(&mtd_partitions_mutex);
601 free_partition(new);
602 return -EINVAL;
604 EXPORT_SYMBOL_GPL(mtd_add_partition);
606 int mtd_del_partition(struct mtd_info *master, int partno)
608 struct mtd_part *slave, *next;
609 int ret = -EINVAL;
611 mutex_lock(&mtd_partitions_mutex);
612 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
613 if ((slave->master == master) &&
614 (slave->mtd.index == partno)) {
615 ret = del_mtd_device(&slave->mtd);
616 if (ret < 0)
617 break;
619 list_del(&slave->list);
620 free_partition(slave);
621 break;
623 mutex_unlock(&mtd_partitions_mutex);
625 return ret;
627 EXPORT_SYMBOL_GPL(mtd_del_partition);
630 * This function, given a master MTD object and a partition table, creates
631 * and registers slave MTD objects which are bound to the master according to
632 * the partition definitions.
634 * We don't register the master, or expect the caller to have done so,
635 * for reasons of data integrity.
638 int add_mtd_partitions(struct mtd_info *master,
639 const struct mtd_partition *parts,
640 int nbparts)
642 struct mtd_part *slave;
643 uint64_t cur_offset = 0;
644 int i;
646 printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
648 for (i = 0; i < nbparts; i++) {
649 slave = allocate_partition(master, parts + i, i, cur_offset);
650 if (IS_ERR(slave))
651 return PTR_ERR(slave);
653 mutex_lock(&mtd_partitions_mutex);
654 list_add(&slave->list, &mtd_partitions);
655 mutex_unlock(&mtd_partitions_mutex);
657 add_mtd_device(&slave->mtd);
659 cur_offset = slave->offset + slave->mtd.size;
662 return 0;
665 static DEFINE_SPINLOCK(part_parser_lock);
666 static LIST_HEAD(part_parsers);
668 static struct mtd_part_parser *get_partition_parser(const char *name)
670 struct mtd_part_parser *p, *ret = NULL;
672 spin_lock(&part_parser_lock);
674 list_for_each_entry(p, &part_parsers, list)
675 if (!strcmp(p->name, name) && try_module_get(p->owner)) {
676 ret = p;
677 break;
680 spin_unlock(&part_parser_lock);
682 return ret;
685 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
687 void register_mtd_parser(struct mtd_part_parser *p)
689 spin_lock(&part_parser_lock);
690 list_add(&p->list, &part_parsers);
691 spin_unlock(&part_parser_lock);
693 EXPORT_SYMBOL_GPL(register_mtd_parser);
695 void deregister_mtd_parser(struct mtd_part_parser *p)
697 spin_lock(&part_parser_lock);
698 list_del(&p->list);
699 spin_unlock(&part_parser_lock);
701 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
704 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
705 * are changing this array!
707 static const char * const default_mtd_part_types[] = {
708 "cmdlinepart",
709 "ofpart",
710 NULL
714 * parse_mtd_partitions - parse MTD partitions
715 * @master: the master partition (describes whole MTD device)
716 * @types: names of partition parsers to try or %NULL
717 * @pparts: array of partitions found is returned here
718 * @data: MTD partition parser-specific data
720 * This function tries to find partition on MTD device @master. It uses MTD
721 * partition parsers, specified in @types. However, if @types is %NULL, then
722 * the default list of parsers is used. The default list contains only the
723 * "cmdlinepart" and "ofpart" parsers ATM.
724 * Note: If there are more then one parser in @types, the kernel only takes the
725 * partitions parsed out by the first parser.
727 * This function may return:
728 * o a negative error code in case of failure
729 * o zero if no partitions were found
730 * o a positive number of found partitions, in which case on exit @pparts will
731 * point to an array containing this number of &struct mtd_info objects.
733 int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
734 struct mtd_partition **pparts,
735 struct mtd_part_parser_data *data)
737 struct mtd_part_parser *parser;
738 int ret = 0;
740 if (!types)
741 types = default_mtd_part_types;
743 for ( ; ret <= 0 && *types; types++) {
744 parser = get_partition_parser(*types);
745 if (!parser && !request_module("%s", *types))
746 parser = get_partition_parser(*types);
747 if (!parser)
748 continue;
749 ret = (*parser->parse_fn)(master, pparts, data);
750 put_partition_parser(parser);
751 if (ret > 0) {
752 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
753 ret, parser->name, master->name);
754 break;
757 return ret;
760 int mtd_is_partition(const struct mtd_info *mtd)
762 struct mtd_part *part;
763 int ispart = 0;
765 mutex_lock(&mtd_partitions_mutex);
766 list_for_each_entry(part, &mtd_partitions, list)
767 if (&part->mtd == mtd) {
768 ispart = 1;
769 break;
771 mutex_unlock(&mtd_partitions_mutex);
773 return ispart;
775 EXPORT_SYMBOL_GPL(mtd_is_partition);
777 /* Returns the size of the entire flash chip */
778 uint64_t mtd_get_device_size(const struct mtd_info *mtd)
780 if (!mtd_is_partition(mtd))
781 return mtd->size;
783 return PART(mtd)->master->size;
785 EXPORT_SYMBOL_GPL(mtd_get_device_size);