406-v6.2-0001-mtd-core-simplify-a-bit-code-find-partition-matching.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From 63db0cb35e1cb3b3c134906d1062f65513fdda2d Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  3. Date: Tue, 4 Oct 2022 10:37:09 +0200
  4. Subject: [PATCH] mtd: core: simplify (a bit) code find partition-matching
  5. dynamic OF node
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. 1. Don't hardcode "partition-" string twice
  10. 2. Use simpler logic & use ->name to avoid of_property_read_string()
  11. 3. Use mtd_get_of_node() helper
  12. Cc: Christian Marangi <[email protected]>
  13. Signed-off-by: Rafał Miłecki <[email protected]>
  14. Signed-off-by: Miquel Raynal <[email protected]>
  15. Link: https://lore.kernel.org/linux-mtd/[email protected]
  16. ---
  17. drivers/mtd/mtdcore.c | 16 +++++++---------
  18. 1 file changed, 7 insertions(+), 9 deletions(-)
  19. --- a/drivers/mtd/mtdcore.c
  20. +++ b/drivers/mtd/mtdcore.c
  21. @@ -551,18 +551,16 @@ static void mtd_check_of_node(struct mtd
  22. struct device_node *partitions, *parent_dn, *mtd_dn = NULL;
  23. const char *pname, *prefix = "partition-";
  24. int plen, mtd_name_len, offset, prefix_len;
  25. - struct mtd_info *parent;
  26. bool found = false;
  27. /* Check if MTD already has a device node */
  28. - if (dev_of_node(&mtd->dev))
  29. + if (mtd_get_of_node(mtd))
  30. return;
  31. /* Check if a partitions node exist */
  32. if (!mtd_is_partition(mtd))
  33. return;
  34. - parent = mtd->parent;
  35. - parent_dn = of_node_get(dev_of_node(&parent->dev));
  36. + parent_dn = of_node_get(mtd_get_of_node(mtd->parent));
  37. if (!parent_dn)
  38. return;
  39. @@ -575,15 +573,15 @@ static void mtd_check_of_node(struct mtd
  40. /* Search if a partition is defined with the same name */
  41. for_each_child_of_node(partitions, mtd_dn) {
  42. - offset = 0;
  43. -
  44. /* Skip partition with no/wrong prefix */
  45. - if (!of_node_name_prefix(mtd_dn, "partition-"))
  46. + if (!of_node_name_prefix(mtd_dn, prefix))
  47. continue;
  48. /* Label have priority. Check that first */
  49. - if (of_property_read_string(mtd_dn, "label", &pname)) {
  50. - of_property_read_string(mtd_dn, "name", &pname);
  51. + if (!of_property_read_string(mtd_dn, "label", &pname)) {
  52. + offset = 0;
  53. + } else {
  54. + pname = mtd_dn->name;
  55. offset = prefix_len;
  56. }