|
1 |
| -From 7f4c9c534aabe1315669e076d3fe0af0fd374cda Mon Sep 17 00:00:00 2001 |
| 1 | +From patchwork Tue Jul 30 19:25:59 2024 |
| 2 | +Content-Type: text/plain; charset="utf-8" |
| 3 | +MIME-Version: 1.0 |
| 4 | +Content-Transfer-Encoding: 7bit |
| 5 | +X-Patchwork-Submitter: Daniel Golle < [email protected]> |
| 6 | +X-Patchwork-Id: 13747816 |
| 7 | +Date: Tue, 30 Jul 2024 20:25:59 +0100 |
2 | 8 | From: Daniel Golle < [email protected]>
|
3 |
| -Date: Thu, 30 May 2024 03:13:19 +0100 |
4 |
| -Subject: [PATCH 2/9] block: partitions: populate fwnode |
| 9 | +To: Rob Herring < [email protected]>, Krzysztof Kozlowski < [email protected]>, |
| 10 | + |
| 11 | + Daniel Golle < [email protected]>, Christian Brauner < [email protected]>, |
| 12 | + |
| 13 | + |
| 14 | + =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= < [email protected]>, |
| 15 | + Felix Fietkau < [email protected]>, John Crispin < [email protected]>, |
| 16 | + |
| 17 | + Tianling Shen < [email protected]>, Chuanhong Guo < [email protected]>, |
| 18 | + |
| 19 | + |
| 20 | +Subject: [PATCH v5 2/4] block: partitions: populate fwnode |
| 21 | +Message-ID: |
| 22 | + <3051ac090ad3b3e2f5adb6b67c923261ead729a5.1722365899.git.daniel@makrotopia.org> |
| 23 | + |
| 24 | +Precedence: bulk |
| 25 | + |
| 26 | +List-Id: <linux-block.vger.kernel.org> |
| 27 | +List-Subscribe: <mailto: [email protected]> |
| 28 | +List-Unsubscribe: <mailto: [email protected]> |
| 29 | +MIME-Version: 1.0 |
| 30 | +Content-Disposition: inline |
| 31 | + |
5 | 32 |
|
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. |
| 33 | +Assign matching firmware nodes to block partitions in order to allow |
| 34 | +them to be referenced e.g. as NVMEM providers. |
8 | 35 |
|
9 | 36 | Signed-off-by: Daniel Golle < [email protected]>
|
10 | 37 | ---
|
11 |
| - block/partitions/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ |
12 |
| - 1 file changed, 41 insertions(+) |
| 38 | + block/partitions/core.c | 72 +++++++++++++++++++++++++++++++++++++++++ |
| 39 | + 1 file changed, 72 insertions(+) |
13 | 40 |
|
14 | 41 | --- a/block/partitions/core.c
|
15 | 42 | +++ b/block/partitions/core.c
|
|
22 | 49 | #include "check.h"
|
23 | 50 |
|
24 | 51 | static int (*const check_part[])(struct parsed_partitions *) = {
|
25 |
| -@@ -292,6 +294,40 @@ static ssize_t whole_disk_show(struct de |
| 52 | +@@ -292,6 +294,74 @@ static ssize_t whole_disk_show(struct de |
26 | 53 | }
|
27 | 54 | static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
|
28 | 55 |
|
| 56 | ++static bool part_meta_match(const char *attr, const char *member, size_t length) |
| 57 | ++{ |
| 58 | ++ /* check if length of attr exceeds specified maximum length */ |
| 59 | ++ if (strnlen(attr, length) == length) |
| 60 | ++ return false; |
| 61 | ++ |
| 62 | ++ /* return true if strings match */ |
| 63 | ++ return !strncmp(attr, member, length); |
| 64 | ++} |
| 65 | ++ |
29 | 66 | +static struct fwnode_handle *find_partition_fwnode(struct block_device *bdev)
|
30 | 67 | +{
|
31 | 68 | + struct fwnode_handle *fw_parts, *fw_part;
|
32 | 69 | + struct device *ddev = disk_to_dev(bdev->bd_disk);
|
33 | 70 | + const char *partname, *uuid;
|
34 | 71 | + u32 partno;
|
| 72 | ++ bool got_uuid, got_partname, got_partno; |
35 | 73 | +
|
36 | 74 | + fw_parts = device_get_named_child_node(ddev, "partitions");
|
37 | 75 | + if (!fw_parts)
|
38 | 76 | + return NULL;
|
39 | 77 | +
|
40 | 78 | + fwnode_for_each_child_node(fw_parts, fw_part) {
|
41 |
| -+ if (!fwnode_property_read_string(fw_part, "uuid", &uuid) && |
42 |
| -+ (!bdev->bd_meta_info || strncmp(uuid, |
43 |
| -+ bdev->bd_meta_info->uuid, |
44 |
| -+ PARTITION_META_INFO_UUIDLTH))) |
| 79 | ++ got_uuid = false; |
| 80 | ++ got_partname = false; |
| 81 | ++ got_partno = false; |
| 82 | ++ /* |
| 83 | ++ * In case 'uuid' is defined in the partitions firmware node |
| 84 | ++ * require partition meta info being present and the specified |
| 85 | ++ * uuid to match. |
| 86 | ++ */ |
| 87 | ++ got_uuid = !fwnode_property_read_string(fw_part, "uuid", &uuid); |
| 88 | ++ if (got_uuid && (!bdev->bd_meta_info || |
| 89 | ++ !part_meta_match(uuid, bdev->bd_meta_info->uuid, |
| 90 | ++ PARTITION_META_INFO_UUIDLTH))) |
| 91 | ++ continue; |
| 92 | ++ |
| 93 | ++ /* |
| 94 | ++ * In case 'partname' is defined in the partitions firmware node |
| 95 | ++ * require partition meta info being present and the specified |
| 96 | ++ * volname to match. |
| 97 | ++ */ |
| 98 | ++ got_partname = !fwnode_property_read_string(fw_part, "partname", |
| 99 | ++ &partname); |
| 100 | ++ if (got_partname && (!bdev->bd_meta_info || |
| 101 | ++ !part_meta_match(partname, |
| 102 | ++ bdev->bd_meta_info->volname, |
| 103 | ++ PARTITION_META_INFO_VOLNAMELTH))) |
45 | 104 | + continue;
|
46 | 105 | +
|
47 |
| -+ if (!fwnode_property_read_string(fw_part, "partname", &partname) && |
48 |
| -+ (!bdev->bd_meta_info || strncmp(partname, |
49 |
| -+ bdev->bd_meta_info->volname, |
50 |
| -+ PARTITION_META_INFO_VOLNAMELTH))) |
| 106 | ++ /* |
| 107 | ++ * In case 'partno' is defined in the partitions firmware node |
| 108 | ++ * the specified partno needs to match. |
| 109 | ++ */ |
| 110 | ++ got_partno = !fwnode_property_read_u32(fw_part, "partno", &partno); |
| 111 | ++ if (got_partno && bdev->bd_partno != partno) |
51 | 112 | + continue;
|
52 | 113 | +
|
53 |
| -+ if (!fwnode_property_read_u32(fw_part, "partno", &partno) && |
54 |
| -+ bdev->bd_partno != partno) |
| 114 | ++ /* Skip if no matching criteria is present in firmware node */ |
| 115 | ++ if (!got_uuid && !got_partname && !got_partno) |
55 | 116 | + continue;
|
56 | 117 | +
|
57 | 118 | + return fw_part;
|
|
63 | 124 | /*
|
64 | 125 | * Must be called either with open_mutex held, before a disk can be opened or
|
65 | 126 | * after all disk users are gone.
|
66 |
| -@@ -374,6 +410,8 @@ static struct block_device *add_partitio |
| 127 | +@@ -374,6 +444,8 @@ static struct block_device *add_partitio |
67 | 128 | goto out_put;
|
68 | 129 | }
|
69 | 130 |
|
|
0 commit comments