mtdcore.c (c42c2710d64381fd48d36b278e0744aa683d93fe) | mtdcore.c (07fd2f871c5e3dfb8ff5eb9c4b44fdb4cf1aeff5) |
---|---|
1/* 2 * Core registration and callback routines for MTD 3 * drivers and users. 4 * 5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> 6 * Copyright © 2006 Red Hat UK Limited 7 * 8 * This program is free software; you can redistribute it and/or modify --- 518 unchanged lines hidden (view full) --- 527 } 528 529out_error: 530 mutex_unlock(&mtd_table_mutex); 531 return ret; 532} 533 534static int mtd_add_device_partitions(struct mtd_info *mtd, | 1/* 2 * Core registration and callback routines for MTD 3 * drivers and users. 4 * 5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> 6 * Copyright © 2006 Red Hat UK Limited 7 * 8 * This program is free software; you can redistribute it and/or modify --- 518 unchanged lines hidden (view full) --- 527 } 528 529out_error: 530 mutex_unlock(&mtd_table_mutex); 531 return ret; 532} 533 534static int mtd_add_device_partitions(struct mtd_info *mtd, |
535 const struct mtd_partition *real_parts, 536 int nbparts) | 535 struct mtd_partitions *parts) |
537{ | 536{ |
537 const struct mtd_partition *real_parts = parts->parts; 538 int nbparts = parts->nr_parts; |
|
538 int ret; 539 540 if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { 541 ret = add_mtd_device(mtd); 542 if (ret) 543 return ret; 544 } 545 --- 37 unchanged lines hidden (view full) --- 583 * 584 * Returns zero in case of success and a negative error code in case of failure. 585 */ 586int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, 587 struct mtd_part_parser_data *parser_data, 588 const struct mtd_partition *parts, 589 int nr_parts) 590{ | 539 int ret; 540 541 if (nbparts == 0 || IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { 542 ret = add_mtd_device(mtd); 543 if (ret) 544 return ret; 545 } 546 --- 37 unchanged lines hidden (view full) --- 584 * 585 * Returns zero in case of success and a negative error code in case of failure. 586 */ 587int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, 588 struct mtd_part_parser_data *parser_data, 589 const struct mtd_partition *parts, 590 int nr_parts) 591{ |
592 struct mtd_partitions parsed; |
|
591 int ret; | 593 int ret; |
592 const struct mtd_partition *real_parts = NULL; | |
593 | 594 |
594 ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); 595 if (ret <= 0 && nr_parts && parts) { 596 real_parts = parts; 597 ret = nr_parts; 598 } 599 /* Didn't come up with either parsed OR fallback partitions */ 600 if (ret < 0) { | 595 memset(&parsed, 0, sizeof(parsed)); 596 597 ret = parse_mtd_partitions(mtd, types, &parsed, parser_data); 598 if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) { 599 /* Fall back to driver-provided partitions */ 600 parsed = (struct mtd_partitions){ 601 .parts = parts, 602 .nr_parts = nr_parts, 603 }; 604 } else if (ret < 0) { 605 /* Didn't come up with parsed OR fallback partitions */ |
601 pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n", 602 ret); 603 /* Don't abort on errors; we can still use unpartitioned MTD */ | 606 pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n", 607 ret); 608 /* Don't abort on errors; we can still use unpartitioned MTD */ |
604 ret = 0; | 609 memset(&parsed, 0, sizeof(parsed)); |
605 } 606 | 610 } 611 |
607 ret = mtd_add_device_partitions(mtd, real_parts, ret); | 612 ret = mtd_add_device_partitions(mtd, &parsed); |
608 if (ret) 609 goto out; 610 611 /* 612 * FIXME: some drivers unfortunately call this function more than once. 613 * So we have to check if we've already assigned the reboot notifier. 614 * 615 * Generally, we can make multiple calls work for most cases, but it --- 4 unchanged lines hidden (view full) --- 620 "MTD already registered\n"); 621 if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) { 622 mtd->reboot_notifier.notifier_call = mtd_reboot_notifier; 623 register_reboot_notifier(&mtd->reboot_notifier); 624 } 625 626out: 627 /* Cleanup any parsed partitions */ | 613 if (ret) 614 goto out; 615 616 /* 617 * FIXME: some drivers unfortunately call this function more than once. 618 * So we have to check if we've already assigned the reboot notifier. 619 * 620 * Generally, we can make multiple calls work for most cases, but it --- 4 unchanged lines hidden (view full) --- 625 "MTD already registered\n"); 626 if (mtd->_reboot && !mtd->reboot_notifier.notifier_call) { 627 mtd->reboot_notifier.notifier_call = mtd_reboot_notifier; 628 register_reboot_notifier(&mtd->reboot_notifier); 629 } 630 631out: 632 /* Cleanup any parsed partitions */ |
628 if (real_parts != parts) 629 kfree(real_parts); | 633 if (parsed.parser) 634 kfree(parsed.parts); |
630 return ret; 631} 632EXPORT_SYMBOL_GPL(mtd_device_parse_register); 633 634/** 635 * mtd_device_unregister - unregister an existing MTD device. 636 * 637 * @master: the MTD device to unregister. This will unregister both the master --- 704 unchanged lines hidden --- | 635 return ret; 636} 637EXPORT_SYMBOL_GPL(mtd_device_parse_register); 638 639/** 640 * mtd_device_unregister - unregister an existing MTD device. 641 * 642 * @master: the MTD device to unregister. This will unregister both the master --- 704 unchanged lines hidden --- |