mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / pending-6.1 / 450-09-block-partitions-populate-fwnode.patch
1 From 614f4f6fdda09e30ecf7ef6c8091579db15018cb Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Fri, 21 Jul 2023 17:51:03 +0100
4 Subject: [PATCH 09/15] block: partitions: populate fwnode
5
6 Let block partitions to be represented by a firmware node and hence
7 allow them to being referenced e.g. for use with blk-nvmem.
8
9 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
10 ---
11 block/partitions/core.c | 41 +++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 41 insertions(+)
13
14 --- a/block/partitions/core.c
15 +++ b/block/partitions/core.c
16 @@ -10,6 +10,8 @@
17 #include <linux/ctype.h>
18 #include <linux/vmalloc.h>
19 #include <linux/raid/detect.h>
20 +#include <linux/property.h>
21 +
22 #include "check.h"
23
24 static int (*check_part[])(struct parsed_partitions *) = {
25 @@ -298,6 +300,43 @@ static ssize_t whole_disk_show(struct de
26 }
27 static DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
28
29 +static struct fwnode_handle *find_partition_fwnode(struct block_device *bdev)
30 +{
31 + struct fwnode_handle *fw_parts, *fw_part;
32 + struct device *ddev = disk_to_dev(bdev->bd_disk);
33 + const char *partname, *uuid;
34 + u32 partno;
35 +
36 + fw_parts = device_get_named_child_node(ddev, "partitions");
37 + if (!fw_parts)
38 + fw_parts = device_get_named_child_node(ddev->parent, "partitions");
39 +
40 + if (!fw_parts)
41 + return NULL;
42 +
43 + fwnode_for_each_child_node(fw_parts, fw_part) {
44 + if (!fwnode_property_read_string(fw_part, "uuid", &uuid) &&
45 + (!bdev->bd_meta_info || strncmp(uuid,
46 + bdev->bd_meta_info->uuid,
47 + PARTITION_META_INFO_UUIDLTH)))
48 + continue;
49 +
50 + if (!fwnode_property_read_string(fw_part, "partname", &partname) &&
51 + (!bdev->bd_meta_info || strncmp(partname,
52 + bdev->bd_meta_info->volname,
53 + PARTITION_META_INFO_VOLNAMELTH)))
54 + continue;
55 +
56 + if (!fwnode_property_read_u32(fw_part, "partno", &partno) &&
57 + bdev->bd_partno != partno)
58 + continue;
59 +
60 + return fw_part;
61 + }
62 +
63 + return NULL;
64 +}
65 +
66 /*
67 * Must be called either with open_mutex held, before a disk can be opened or
68 * after all disk users are gone.
69 @@ -380,6 +419,8 @@ static struct block_device *add_partitio
70 goto out_put;
71 }
72
73 + device_set_node(pdev, find_partition_fwnode(bdev));
74 +
75 /* delay uevent until 'holders' subdir is created */
76 dev_set_uevent_suppress(pdev, 1);
77 err = device_add(pdev);