450-block-allow-setting-partition-of_node.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From decc6959a423c8617e87244fd269129fc4e7d0e6 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Mon, 7 Oct 2024 23:36:14 +0100
  4. Subject: [PATCH 1/8] block: allow setting partition of_node
  5. Allow partition parsers to set the Device Tree node for a partition by
  6. introducing of_put_partition() and extending struct parsed_partitions
  7. accordingly.
  8. As the partition information is preallocated independently of the actual
  9. number of partitions the additional pointer takes about 2 kiB of allocated
  10. memory which is worth avoiding in case CONFIG_OF is not set. This is
  11. achieved by only adding the corresponding field to the struct in case
  12. CONFIG_OF is set using #ifdef'ery.
  13. Signed-off-by: Daniel Golle <[email protected]>
  14. ---
  15. block/partitions/check.h | 16 +++++++++++++++-
  16. block/partitions/core.c | 14 +++++++++++---
  17. 2 files changed, 26 insertions(+), 4 deletions(-)
  18. --- a/block/partitions/check.h
  19. +++ b/block/partitions/check.h
  20. @@ -1,6 +1,7 @@
  21. /* SPDX-License-Identifier: GPL-2.0 */
  22. #include <linux/pagemap.h>
  23. #include <linux/blkdev.h>
  24. +#include <linux/of.h>
  25. #include "../blk.h"
  26. /*
  27. @@ -16,6 +17,9 @@ struct parsed_partitions {
  28. int flags;
  29. bool has_info;
  30. struct partition_meta_info info;
  31. +#ifdef CONFIG_OF
  32. + struct device_node *np;
  33. +#endif
  34. } *parts;
  35. int next;
  36. int limit;
  37. @@ -34,18 +38,28 @@ static inline void put_dev_sector(Sector
  38. }
  39. static inline void
  40. -put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
  41. +of_put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size,
  42. + struct device_node *np)
  43. {
  44. if (n < p->limit) {
  45. char tmp[1 + BDEVNAME_SIZE + 10 + 1];
  46. p->parts[n].from = from;
  47. p->parts[n].size = size;
  48. +#ifdef CONFIG_OF
  49. + p->parts[n].np = np;
  50. +#endif
  51. snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
  52. strlcat(p->pp_buf, tmp, PAGE_SIZE);
  53. }
  54. }
  55. +static inline void
  56. +put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
  57. +{
  58. + of_put_partition(p, n, from, size, NULL);
  59. +}
  60. +
  61. /* detection routines go here in alphabetical order: */
  62. int adfspart_check_ADFS(struct parsed_partitions *state);
  63. int adfspart_check_CUMANA(struct parsed_partitions *state);
  64. --- a/block/partitions/core.c
  65. +++ b/block/partitions/core.c
  66. @@ -9,6 +9,7 @@
  67. #include <linux/slab.h>
  68. #include <linux/ctype.h>
  69. #include <linux/vmalloc.h>
  70. +#include <linux/device.h>
  71. #include <linux/raid/detect.h>
  72. #include "check.h"
  73. @@ -290,7 +291,8 @@ static const DEVICE_ATTR(whole_disk, 044
  74. */
  75. static struct block_device *add_partition(struct gendisk *disk, int partno,
  76. sector_t start, sector_t len, int flags,
  77. - struct partition_meta_info *info)
  78. + struct partition_meta_info *info,
  79. + struct device_node *np)
  80. {
  81. dev_t devt = MKDEV(0, 0);
  82. struct device *ddev = disk_to_dev(disk);
  83. @@ -339,6 +341,7 @@ static struct block_device *add_partitio
  84. pdev->class = &block_class;
  85. pdev->type = &part_type;
  86. pdev->parent = ddev;
  87. + device_set_node(pdev, of_fwnode_handle(np));
  88. /* in consecutive minor range? */
  89. if (bdev_partno(bdev) < disk->minors) {
  90. @@ -445,7 +448,7 @@ int bdev_add_partition(struct gendisk *d
  91. }
  92. part = add_partition(disk, partno, start, length,
  93. - ADDPART_FLAG_NONE, NULL);
  94. + ADDPART_FLAG_NONE, NULL, NULL);
  95. ret = PTR_ERR_OR_ZERO(part);
  96. out:
  97. mutex_unlock(&disk->open_mutex);
  98. @@ -559,8 +562,13 @@ static bool blk_add_partition(struct gen
  99. size = get_capacity(disk) - from;
  100. }
  101. +#ifdef CONFIG_OF
  102. part = add_partition(disk, p, from, size, state->parts[p].flags,
  103. - &state->parts[p].info);
  104. + &state->parts[p].info, state->parts[p].np);
  105. +#else
  106. + part = add_partition(disk, p, from, size, state->parts[p].flags,
  107. + &state->parts[p].info, NULL);
  108. +#endif
  109. if (IS_ERR(part)) {
  110. if (PTR_ERR(part) != -ENXIO) {
  111. printk(KERN_ERR " %s: p%d could not be added: %pe\n",