065-v4.13-0002-mtd-partitions-factor-out-code-calling-parser.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 01f9c7240a900d5676a8496496f2974dd36996b1 Mon Sep 17 00:00:00 2001
  2. From: Brian Norris <computersforpeace@gmail.com>
  3. Date: Tue, 23 May 2017 07:30:20 +0200
  4. Subject: [PATCH] mtd: partitions: factor out code calling parser
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This code is going to be reused for parsers matched using OF so let's
  9. factor it out to make this easier.
  10. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  11. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  12. Acked-by: Brian Norris <computersforpeace@gmail.com>
  13. ---
  14. drivers/mtd/mtdpart.c | 33 ++++++++++++++++++++++++---------
  15. 1 file changed, 24 insertions(+), 9 deletions(-)
  16. --- a/drivers/mtd/mtdpart.c
  17. +++ b/drivers/mtd/mtdpart.c
  18. @@ -807,6 +807,27 @@ static const char * const default_mtd_pa
  19. NULL
  20. };
  21. +static int mtd_part_do_parse(struct mtd_part_parser *parser,
  22. + struct mtd_info *master,
  23. + struct mtd_partitions *pparts,
  24. + struct mtd_part_parser_data *data)
  25. +{
  26. + int ret;
  27. +
  28. + ret = (*parser->parse_fn)(master, &pparts->parts, data);
  29. + pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret);
  30. + if (ret <= 0)
  31. + return ret;
  32. +
  33. + pr_notice("%d %s partitions found on MTD device %s\n", ret,
  34. + parser->name, master->name);
  35. +
  36. + pparts->nr_parts = ret;
  37. + pparts->parser = parser;
  38. +
  39. + return ret;
  40. +}
  41. +
  42. /**
  43. * parse_mtd_partitions - parse MTD partitions
  44. * @master: the master partition (describes whole MTD device)
  45. @@ -847,16 +868,10 @@ int parse_mtd_partitions(struct mtd_info
  46. parser ? parser->name : NULL);
  47. if (!parser)
  48. continue;
  49. - ret = (*parser->parse_fn)(master, &pparts->parts, data);
  50. - pr_debug("%s: parser %s: %i\n",
  51. - master->name, parser->name, ret);
  52. - if (ret > 0) {
  53. - printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
  54. - ret, parser->name, master->name);
  55. - pparts->nr_parts = ret;
  56. - pparts->parser = parser;
  57. + ret = mtd_part_do_parse(parser, master, pparts, data);
  58. + /* Found partitions! */
  59. + if (ret > 0)
  60. return 0;
  61. - }
  62. mtd_part_parser_put(parser);
  63. /*
  64. * Stash the first error we see; only report it if no parser