aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdcore.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r--drivers/mtd/mtdcore.c70
1 files changed, 53 insertions, 17 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c510aff289a..b01993ea260 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -362,7 +362,7 @@ int add_mtd_device(struct mtd_info *mtd)
362 MTD_DEVT(i) + 1, 362 MTD_DEVT(i) + 1,
363 NULL, "mtd%dro", i); 363 NULL, "mtd%dro", i);
364 364
365 DEBUG(0, "mtd: Giving out device %d to %s\n", i, mtd->name); 365 pr_debug("mtd: Giving out device %d to %s\n", i, mtd->name);
366 /* No need to get a refcount on the module containing 366 /* No need to get a refcount on the module containing
367 the notifier, since we hold the mtd_table_mutex */ 367 the notifier, since we hold the mtd_table_mutex */
368 list_for_each_entry(not, &mtd_notifiers, list) 368 list_for_each_entry(not, &mtd_notifiers, list)
@@ -429,27 +429,63 @@ out_error:
429} 429}
430 430
431/** 431/**
432 * mtd_device_register - register an MTD device. 432 * mtd_device_parse_register - parse partitions and register an MTD device.
433 * 433 *
434 * @master: the MTD device to register 434 * @mtd: the MTD device to register
435 * @parts: the partitions to register - only valid if nr_parts > 0 435 * @types: the list of MTD partition probes to try, see
436 * @nr_parts: the number of partitions in parts. If zero then the full MTD 436 * 'parse_mtd_partitions()' for more information
437 * device is registered 437 * @parser_data: MTD partition parser-specific data
438 * @parts: fallback partition information to register, if parsing fails;
439 * only valid if %nr_parts > %0
440 * @nr_parts: the number of partitions in parts, if zero then the full
441 * MTD device is registered if no partition info is found
438 * 442 *
439 * Register an MTD device with the system and optionally, a number of 443 * This function aggregates MTD partitions parsing (done by
440 * partitions. If nr_parts is 0 then the whole device is registered, otherwise 444 * 'parse_mtd_partitions()') and MTD device and partitions registering. It
441 * only the partitions are registered. To register both the full device *and* 445 * basically follows the most common pattern found in many MTD drivers:
442 * the partitions, call mtd_device_register() twice, once with nr_parts == 0 446 *
443 * and once equal to the number of partitions. 447 * * It first tries to probe partitions on MTD device @mtd using parsers
448 * specified in @types (if @types is %NULL, then the default list of parsers
449 * is used, see 'parse_mtd_partitions()' for more information). If none are
450 * found this functions tries to fallback to information specified in
451 * @parts/@nr_parts.
452 * * If any partitioning info was found, this function registers the found
453 * partitions.
454 * * If no partitions were found this function just registers the MTD device
455 * @mtd and exits.
456 *
457 * Returns zero in case of success and a negative error code in case of failure.
444 */ 458 */
445int mtd_device_register(struct mtd_info *master, 459int mtd_device_parse_register(struct mtd_info *mtd, const char **types,
446 const struct mtd_partition *parts, 460 struct mtd_part_parser_data *parser_data,
447 int nr_parts) 461 const struct mtd_partition *parts,
462 int nr_parts)
448{ 463{
449 return parts ? add_mtd_partitions(master, parts, nr_parts) : 464 int err;
450 add_mtd_device(master); 465 struct mtd_partition *real_parts;
466
467 err = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
468 if (err <= 0 && nr_parts && parts) {
469 real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
470 GFP_KERNEL);
471 if (!real_parts)
472 err = -ENOMEM;
473 else
474 err = nr_parts;
475 }
476
477 if (err > 0) {
478 err = add_mtd_partitions(mtd, real_parts, err);
479 kfree(real_parts);
480 } else if (err == 0) {
481 err = add_mtd_device(mtd);
482 if (err == 1)
483 err = -ENODEV;
484 }
485
486 return err;
451} 487}
452EXPORT_SYMBOL_GPL(mtd_device_register); 488EXPORT_SYMBOL_GPL(mtd_device_parse_register);
453 489
454/** 490/**
455 * mtd_device_unregister - unregister an existing MTD device. 491 * mtd_device_unregister - unregister an existing MTD device.