hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/platform/x86/wmi.c
....@@ -40,7 +40,7 @@
4040 static LIST_HEAD(wmi_block_list);
4141
4242 struct guid_block {
43
- char guid[16];
43
+ guid_t guid;
4444 union {
4545 char object_id[2];
4646 struct {
....@@ -121,7 +121,7 @@
121121 list_for_each_entry(wblock, &wmi_block_list, list) {
122122 block = &wblock->gblock;
123123
124
- if (memcmp(block->guid, &guid_input, 16) == 0) {
124
+ if (guid_equal(&block->guid, &guid_input)) {
125125 if (out)
126126 *out = wblock;
127127 return true;
....@@ -130,11 +130,20 @@
130130 return false;
131131 }
132132
133
+static bool guid_parse_and_compare(const char *string, const guid_t *guid)
134
+{
135
+ guid_t guid_input;
136
+
137
+ if (guid_parse(string, &guid_input))
138
+ return false;
139
+
140
+ return guid_equal(&guid_input, guid);
141
+}
142
+
133143 static const void *find_guid_context(struct wmi_block *wblock,
134144 struct wmi_driver *wdriver)
135145 {
136146 const struct wmi_device_id *id;
137
- guid_t guid_input;
138147
139148 if (wblock == NULL || wdriver == NULL)
140149 return NULL;
....@@ -143,9 +152,7 @@
143152
144153 id = wdriver->id_table;
145154 while (*id->guid_string) {
146
- if (guid_parse(id->guid_string, &guid_input))
147
- continue;
148
- if (!memcmp(wblock->gblock.guid, &guid_input, 16))
155
+ if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
149156 return id->context;
150157 id++;
151158 }
....@@ -457,7 +464,7 @@
457464
458465 static void wmi_dump_wdg(const struct guid_block *g)
459466 {
460
- pr_info("%pUL:\n", g->guid);
467
+ pr_info("%pUL:\n", &g->guid);
461468 if (g->flags & ACPI_WMI_EVENT)
462469 pr_info("\tnotify_id: 0x%02X\n", g->notify_id);
463470 else
....@@ -539,7 +546,7 @@
539546 list_for_each_entry(block, &wmi_block_list, list) {
540547 acpi_status wmi_status;
541548
542
- if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
549
+ if (guid_equal(&block->gblock.guid, &guid_input)) {
543550 if (block->handler &&
544551 block->handler != wmi_notify_debug)
545552 return AE_ALREADY_ACQUIRED;
....@@ -579,7 +586,7 @@
579586 list_for_each_entry(block, &wmi_block_list, list) {
580587 acpi_status wmi_status;
581588
582
- if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
589
+ if (guid_equal(&block->gblock.guid, &guid_input)) {
583590 if (!block->handler ||
584591 block->handler == wmi_notify_debug)
585592 return AE_NULL_ENTRY;
....@@ -615,7 +622,6 @@
615622 {
616623 struct acpi_object_list input;
617624 union acpi_object params[1];
618
- struct guid_block *gblock;
619625 struct wmi_block *wblock;
620626
621627 input.count = 1;
....@@ -624,7 +630,7 @@
624630 params[0].integer.value = event;
625631
626632 list_for_each_entry(wblock, &wmi_block_list, list) {
627
- gblock = &wblock->gblock;
633
+ struct guid_block *gblock = &wblock->gblock;
628634
629635 if ((gblock->flags & ACPI_WMI_EVENT) &&
630636 (gblock->notify_id == event))
....@@ -685,7 +691,7 @@
685691 {
686692 struct wmi_block *wblock = dev_to_wblock(dev);
687693
688
- return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid);
694
+ return sprintf(buf, "wmi:%pUL\n", &wblock->gblock.guid);
689695 }
690696 static DEVICE_ATTR_RO(modalias);
691697
....@@ -694,7 +700,7 @@
694700 {
695701 struct wmi_block *wblock = dev_to_wblock(dev);
696702
697
- return sprintf(buf, "%pUL\n", wblock->gblock.guid);
703
+ return sprintf(buf, "%pUL\n", &wblock->gblock.guid);
698704 }
699705 static DEVICE_ATTR_RO(guid);
700706
....@@ -777,10 +783,10 @@
777783 {
778784 struct wmi_block *wblock = dev_to_wblock(dev);
779785
780
- if (add_uevent_var(env, "MODALIAS=wmi:%pUL", wblock->gblock.guid))
786
+ if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid))
781787 return -ENOMEM;
782788
783
- if (add_uevent_var(env, "WMI_GUID=%pUL", wblock->gblock.guid))
789
+ if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid))
784790 return -ENOMEM;
785791
786792 return 0;
....@@ -804,11 +810,7 @@
804810 return 0;
805811
806812 while (*id->guid_string) {
807
- guid_t driver_guid;
808
-
809
- if (WARN_ON(guid_parse(id->guid_string, &driver_guid)))
810
- continue;
811
- if (!memcmp(&driver_guid, wblock->gblock.guid, 16))
813
+ if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
812814 return 1;
813815
814816 id++;
....@@ -1042,7 +1044,6 @@
10421044 };
10431045
10441046 static int wmi_create_device(struct device *wmi_bus_dev,
1045
- const struct guid_block *gblock,
10461047 struct wmi_block *wblock,
10471048 struct acpi_device *device)
10481049 {
....@@ -1050,12 +1051,12 @@
10501051 char method[5];
10511052 int result;
10521053
1053
- if (gblock->flags & ACPI_WMI_EVENT) {
1054
+ if (wblock->gblock.flags & ACPI_WMI_EVENT) {
10541055 wblock->dev.dev.type = &wmi_type_event;
10551056 goto out_init;
10561057 }
10571058
1058
- if (gblock->flags & ACPI_WMI_METHOD) {
1059
+ if (wblock->gblock.flags & ACPI_WMI_METHOD) {
10591060 wblock->dev.dev.type = &wmi_type_method;
10601061 mutex_init(&wblock->char_mutex);
10611062 goto out_init;
....@@ -1105,7 +1106,7 @@
11051106 wblock->dev.dev.bus = &wmi_bus_type;
11061107 wblock->dev.dev.parent = wmi_bus_dev;
11071108
1108
- dev_set_name(&wblock->dev.dev, "%pUL", gblock->guid);
1109
+ dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid);
11091110
11101111 device_initialize(&wblock->dev.dev);
11111112
....@@ -1125,12 +1126,12 @@
11251126 }
11261127 }
11271128
1128
-static bool guid_already_parsed(struct acpi_device *device, const u8 *guid)
1129
+static bool guid_already_parsed(struct acpi_device *device, const guid_t *guid)
11291130 {
11301131 struct wmi_block *wblock;
11311132
11321133 list_for_each_entry(wblock, &wmi_block_list, list) {
1133
- if (memcmp(wblock->gblock.guid, guid, 16) == 0) {
1134
+ if (guid_equal(&wblock->gblock.guid, guid)) {
11341135 /*
11351136 * Because we historically didn't track the relationship
11361137 * between GUIDs and ACPI nodes, we don't know whether
....@@ -1185,7 +1186,7 @@
11851186 * case yet, so for now, we'll just ignore the duplicate
11861187 * for device creation.
11871188 */
1188
- if (guid_already_parsed(device, gblock[i].guid))
1189
+ if (guid_already_parsed(device, &gblock[i].guid))
11891190 continue;
11901191
11911192 wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
....@@ -1197,7 +1198,7 @@
11971198 wblock->acpi_device = device;
11981199 wblock->gblock = gblock[i];
11991200
1200
- retval = wmi_create_device(wmi_bus_dev, &gblock[i], wblock, device);
1201
+ retval = wmi_create_device(wmi_bus_dev, wblock, device);
12011202 if (retval) {
12021203 kfree(wblock);
12031204 continue;
....@@ -1222,7 +1223,7 @@
12221223 retval = device_add(&wblock->dev.dev);
12231224 if (retval) {
12241225 dev_err(wmi_bus_dev, "failed to register %pUL\n",
1225
- wblock->gblock.guid);
1226
+ &wblock->gblock.guid);
12261227 if (debug_event)
12271228 wmi_method_enable(wblock, 0);
12281229 list_del(&wblock->list);
....@@ -1282,12 +1283,11 @@
12821283 static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
12831284 void *context)
12841285 {
1285
- struct guid_block *block;
12861286 struct wmi_block *wblock;
12871287 bool found_it = false;
12881288
12891289 list_for_each_entry(wblock, &wmi_block_list, list) {
1290
- block = &wblock->gblock;
1290
+ struct guid_block *block = &wblock->gblock;
12911291
12921292 if (wblock->acpi_device->handle == handle &&
12931293 (block->flags & ACPI_WMI_EVENT) &&
....@@ -1336,7 +1336,7 @@
13361336 }
13371337
13381338 if (debug_event)
1339
- pr_info("DEBUG Event GUID: %pUL\n", wblock->gblock.guid);
1339
+ pr_info("DEBUG Event GUID: %pUL\n", &wblock->gblock.guid);
13401340
13411341 acpi_bus_generate_netlink_event(
13421342 wblock->acpi_device->pnp.device_class,