| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * dev-path-parser.c - EFI Device Path parser |
|---|
| 3 | 4 | * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de> |
|---|
| .. | .. |
|---|
| 5 | 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | 7 | * it under the terms of the GNU General Public License (version 2) as |
|---|
| 7 | 8 | * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License |
|---|
| 15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 9 | */ |
|---|
| 17 | 10 | |
|---|
| 18 | 11 | #include <linux/acpi.h> |
|---|
| .. | .. |
|---|
| 24 | 17 | char uid[11]; /* UINT_MAX + null byte */ |
|---|
| 25 | 18 | }; |
|---|
| 26 | 19 | |
|---|
| 27 | | -static int __init match_acpi_dev(struct device *dev, void *data) |
|---|
| 20 | +static int __init match_acpi_dev(struct device *dev, const void *data) |
|---|
| 28 | 21 | { |
|---|
| 29 | | - struct acpi_hid_uid hid_uid = *(struct acpi_hid_uid *)data; |
|---|
| 22 | + struct acpi_hid_uid hid_uid = *(const struct acpi_hid_uid *)data; |
|---|
| 30 | 23 | struct acpi_device *adev = to_acpi_device(dev); |
|---|
| 31 | 24 | |
|---|
| 32 | 25 | if (acpi_match_device_ids(adev, hid_uid.hid)) |
|---|
| .. | .. |
|---|
| 38 | 31 | return !strcmp("0", hid_uid.uid); |
|---|
| 39 | 32 | } |
|---|
| 40 | 33 | |
|---|
| 41 | | -static long __init parse_acpi_path(struct efi_dev_path *node, |
|---|
| 34 | +static long __init parse_acpi_path(const struct efi_dev_path *node, |
|---|
| 42 | 35 | struct device *parent, struct device **child) |
|---|
| 43 | 36 | { |
|---|
| 44 | 37 | struct acpi_hid_uid hid_uid = {}; |
|---|
| 45 | 38 | struct device *phys_dev; |
|---|
| 46 | 39 | |
|---|
| 47 | | - if (node->length != 12) |
|---|
| 40 | + if (node->header.length != 12) |
|---|
| 48 | 41 | return -EINVAL; |
|---|
| 49 | 42 | |
|---|
| 50 | 43 | sprintf(hid_uid.hid[0].id, "%c%c%c%04X", |
|---|
| .. | .. |
|---|
| 76 | 69 | return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn; |
|---|
| 77 | 70 | } |
|---|
| 78 | 71 | |
|---|
| 79 | | -static long __init parse_pci_path(struct efi_dev_path *node, |
|---|
| 72 | +static long __init parse_pci_path(const struct efi_dev_path *node, |
|---|
| 80 | 73 | struct device *parent, struct device **child) |
|---|
| 81 | 74 | { |
|---|
| 82 | 75 | unsigned int devfn; |
|---|
| 83 | 76 | |
|---|
| 84 | | - if (node->length != 6) |
|---|
| 77 | + if (node->header.length != 6) |
|---|
| 85 | 78 | return -EINVAL; |
|---|
| 86 | 79 | if (!parent) |
|---|
| 87 | 80 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 112 | 105 | * search for a device. |
|---|
| 113 | 106 | */ |
|---|
| 114 | 107 | |
|---|
| 115 | | -static long __init parse_end_path(struct efi_dev_path *node, |
|---|
| 108 | +static long __init parse_end_path(const struct efi_dev_path *node, |
|---|
| 116 | 109 | struct device *parent, struct device **child) |
|---|
| 117 | 110 | { |
|---|
| 118 | | - if (node->length != 4) |
|---|
| 111 | + if (node->header.length != 4) |
|---|
| 119 | 112 | return -EINVAL; |
|---|
| 120 | | - if (node->sub_type != EFI_DEV_END_INSTANCE && |
|---|
| 121 | | - node->sub_type != EFI_DEV_END_ENTIRE) |
|---|
| 113 | + if (node->header.sub_type != EFI_DEV_END_INSTANCE && |
|---|
| 114 | + node->header.sub_type != EFI_DEV_END_ENTIRE) |
|---|
| 122 | 115 | return -EINVAL; |
|---|
| 123 | 116 | if (!parent) |
|---|
| 124 | 117 | return -ENODEV; |
|---|
| 125 | 118 | |
|---|
| 126 | 119 | *child = get_device(parent); |
|---|
| 127 | | - return node->sub_type; |
|---|
| 120 | + return node->header.sub_type; |
|---|
| 128 | 121 | } |
|---|
| 129 | 122 | |
|---|
| 130 | 123 | /** |
|---|
| .. | .. |
|---|
| 163 | 156 | * %ERR_PTR(-EINVAL) if a node is malformed or exceeds @len, |
|---|
| 164 | 157 | * %ERR_PTR(-ENOTSUPP) if support for a node type is not yet implemented. |
|---|
| 165 | 158 | */ |
|---|
| 166 | | -struct device * __init efi_get_device_by_path(struct efi_dev_path **node, |
|---|
| 159 | +struct device * __init efi_get_device_by_path(const struct efi_dev_path **node, |
|---|
| 167 | 160 | size_t *len) |
|---|
| 168 | 161 | { |
|---|
| 169 | 162 | struct device *parent = NULL, *child; |
|---|
| .. | .. |
|---|
| 173 | 166 | return NULL; |
|---|
| 174 | 167 | |
|---|
| 175 | 168 | while (!ret) { |
|---|
| 176 | | - if (*len < 4 || *len < (*node)->length) |
|---|
| 169 | + if (*len < 4 || *len < (*node)->header.length) |
|---|
| 177 | 170 | ret = -EINVAL; |
|---|
| 178 | | - else if ((*node)->type == EFI_DEV_ACPI && |
|---|
| 179 | | - (*node)->sub_type == EFI_DEV_BASIC_ACPI) |
|---|
| 171 | + else if ((*node)->header.type == EFI_DEV_ACPI && |
|---|
| 172 | + (*node)->header.sub_type == EFI_DEV_BASIC_ACPI) |
|---|
| 180 | 173 | ret = parse_acpi_path(*node, parent, &child); |
|---|
| 181 | | - else if ((*node)->type == EFI_DEV_HW && |
|---|
| 182 | | - (*node)->sub_type == EFI_DEV_PCI) |
|---|
| 174 | + else if ((*node)->header.type == EFI_DEV_HW && |
|---|
| 175 | + (*node)->header.sub_type == EFI_DEV_PCI) |
|---|
| 183 | 176 | ret = parse_pci_path(*node, parent, &child); |
|---|
| 184 | | - else if (((*node)->type == EFI_DEV_END_PATH || |
|---|
| 185 | | - (*node)->type == EFI_DEV_END_PATH2)) |
|---|
| 177 | + else if (((*node)->header.type == EFI_DEV_END_PATH || |
|---|
| 178 | + (*node)->header.type == EFI_DEV_END_PATH2)) |
|---|
| 186 | 179 | ret = parse_end_path(*node, parent, &child); |
|---|
| 187 | 180 | else |
|---|
| 188 | 181 | ret = -ENOTSUPP; |
|---|
| .. | .. |
|---|
| 192 | 185 | return ERR_PTR(ret); |
|---|
| 193 | 186 | |
|---|
| 194 | 187 | parent = child; |
|---|
| 195 | | - *node = (void *)*node + (*node)->length; |
|---|
| 196 | | - *len -= (*node)->length; |
|---|
| 188 | + *node = (void *)*node + (*node)->header.length; |
|---|
| 189 | + *len -= (*node)->header.length; |
|---|
| 197 | 190 | } |
|---|
| 198 | 191 | |
|---|
| 199 | 192 | if (ret == EFI_DEV_END_ENTIRE) |
|---|