platform/x86: wmi: use guid_t and guid_equal()
[ Upstream commit67f472fdac
] Instead of hard-coding a 16 long byte array, use the available `guid_t` type and related methods. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Link: https://lore.kernel.org/r/20210904175450.156801-15-pobrn@protonmail.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Stable-dep-of:028e6e204a
("platform/x86: wmi: Break possible infinite loop when parsing GUID") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
3b6fef4110
commit
f3583db898
@ -39,7 +39,7 @@ MODULE_LICENSE("GPL");
|
|||||||
static LIST_HEAD(wmi_block_list);
|
static LIST_HEAD(wmi_block_list);
|
||||||
|
|
||||||
struct guid_block {
|
struct guid_block {
|
||||||
char guid[16];
|
guid_t guid;
|
||||||
union {
|
union {
|
||||||
char object_id[2];
|
char object_id[2];
|
||||||
struct {
|
struct {
|
||||||
@ -124,7 +124,7 @@ static bool find_guid(const char *guid_string, struct wmi_block **out)
|
|||||||
list_for_each_entry(wblock, &wmi_block_list, list) {
|
list_for_each_entry(wblock, &wmi_block_list, list) {
|
||||||
block = &wblock->gblock;
|
block = &wblock->gblock;
|
||||||
|
|
||||||
if (memcmp(block->guid, &guid_input, 16) == 0) {
|
if (guid_equal(&block->guid, &guid_input)) {
|
||||||
if (out)
|
if (out)
|
||||||
*out = wblock;
|
*out = wblock;
|
||||||
return true;
|
return true;
|
||||||
@ -148,7 +148,7 @@ static const void *find_guid_context(struct wmi_block *wblock,
|
|||||||
while (*id->guid_string) {
|
while (*id->guid_string) {
|
||||||
if (guid_parse(id->guid_string, &guid_input))
|
if (guid_parse(id->guid_string, &guid_input))
|
||||||
continue;
|
continue;
|
||||||
if (!memcmp(wblock->gblock.guid, &guid_input, 16))
|
if (guid_equal(&wblock->gblock.guid, &guid_input))
|
||||||
return id->context;
|
return id->context;
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
@ -460,7 +460,7 @@ EXPORT_SYMBOL_GPL(wmi_set_block);
|
|||||||
|
|
||||||
static void wmi_dump_wdg(const struct guid_block *g)
|
static void wmi_dump_wdg(const struct guid_block *g)
|
||||||
{
|
{
|
||||||
pr_info("%pUL:\n", g->guid);
|
pr_info("%pUL:\n", &g->guid);
|
||||||
if (g->flags & ACPI_WMI_EVENT)
|
if (g->flags & ACPI_WMI_EVENT)
|
||||||
pr_info("\tnotify_id: 0x%02X\n", g->notify_id);
|
pr_info("\tnotify_id: 0x%02X\n", g->notify_id);
|
||||||
else
|
else
|
||||||
@ -542,7 +542,7 @@ wmi_notify_handler handler, void *data)
|
|||||||
list_for_each_entry(block, &wmi_block_list, list) {
|
list_for_each_entry(block, &wmi_block_list, list) {
|
||||||
acpi_status wmi_status;
|
acpi_status wmi_status;
|
||||||
|
|
||||||
if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
|
if (guid_equal(&block->gblock.guid, &guid_input)) {
|
||||||
if (block->handler &&
|
if (block->handler &&
|
||||||
block->handler != wmi_notify_debug)
|
block->handler != wmi_notify_debug)
|
||||||
return AE_ALREADY_ACQUIRED;
|
return AE_ALREADY_ACQUIRED;
|
||||||
@ -582,7 +582,7 @@ acpi_status wmi_remove_notify_handler(const char *guid)
|
|||||||
list_for_each_entry(block, &wmi_block_list, list) {
|
list_for_each_entry(block, &wmi_block_list, list) {
|
||||||
acpi_status wmi_status;
|
acpi_status wmi_status;
|
||||||
|
|
||||||
if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
|
if (guid_equal(&block->gblock.guid, &guid_input)) {
|
||||||
if (!block->handler ||
|
if (!block->handler ||
|
||||||
block->handler == wmi_notify_debug)
|
block->handler == wmi_notify_debug)
|
||||||
return AE_NULL_ENTRY;
|
return AE_NULL_ENTRY;
|
||||||
@ -693,7 +693,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
|
|||||||
{
|
{
|
||||||
struct wmi_block *wblock = dev_to_wblock(dev);
|
struct wmi_block *wblock = dev_to_wblock(dev);
|
||||||
|
|
||||||
return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid);
|
return sprintf(buf, "wmi:%pUL\n", &wblock->gblock.guid);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(modalias);
|
static DEVICE_ATTR_RO(modalias);
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
|
|||||||
{
|
{
|
||||||
struct wmi_block *wblock = dev_to_wblock(dev);
|
struct wmi_block *wblock = dev_to_wblock(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%pUL\n", wblock->gblock.guid);
|
return sprintf(buf, "%pUL\n", &wblock->gblock.guid);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(guid);
|
static DEVICE_ATTR_RO(guid);
|
||||||
|
|
||||||
@ -785,10 +785,10 @@ static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
|
|||||||
{
|
{
|
||||||
struct wmi_block *wblock = dev_to_wblock(dev);
|
struct wmi_block *wblock = dev_to_wblock(dev);
|
||||||
|
|
||||||
if (add_uevent_var(env, "MODALIAS=wmi:%pUL", wblock->gblock.guid))
|
if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (add_uevent_var(env, "WMI_GUID=%pUL", wblock->gblock.guid))
|
if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -815,7 +815,7 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
|
|||||||
|
|
||||||
if (WARN_ON(guid_parse(id->guid_string, &driver_guid)))
|
if (WARN_ON(guid_parse(id->guid_string, &driver_guid)))
|
||||||
continue;
|
continue;
|
||||||
if (!memcmp(&driver_guid, wblock->gblock.guid, 16))
|
if (guid_equal(&driver_guid, &wblock->gblock.guid))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
@ -1108,7 +1108,7 @@ static int wmi_create_device(struct device *wmi_bus_dev,
|
|||||||
wblock->dev.dev.bus = &wmi_bus_type;
|
wblock->dev.dev.bus = &wmi_bus_type;
|
||||||
wblock->dev.dev.parent = wmi_bus_dev;
|
wblock->dev.dev.parent = wmi_bus_dev;
|
||||||
|
|
||||||
dev_set_name(&wblock->dev.dev, "%pUL", wblock->gblock.guid);
|
dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid);
|
||||||
|
|
||||||
device_initialize(&wblock->dev.dev);
|
device_initialize(&wblock->dev.dev);
|
||||||
|
|
||||||
@ -1128,12 +1128,12 @@ static void wmi_free_devices(struct acpi_device *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool guid_already_parsed(struct acpi_device *device, const u8 *guid)
|
static bool guid_already_parsed(struct acpi_device *device, const guid_t *guid)
|
||||||
{
|
{
|
||||||
struct wmi_block *wblock;
|
struct wmi_block *wblock;
|
||||||
|
|
||||||
list_for_each_entry(wblock, &wmi_block_list, list) {
|
list_for_each_entry(wblock, &wmi_block_list, list) {
|
||||||
if (memcmp(wblock->gblock.guid, guid, 16) == 0) {
|
if (guid_equal(&wblock->gblock.guid, guid)) {
|
||||||
/*
|
/*
|
||||||
* Because we historically didn't track the relationship
|
* Because we historically didn't track the relationship
|
||||||
* between GUIDs and ACPI nodes, we don't know whether
|
* between GUIDs and ACPI nodes, we don't know whether
|
||||||
@ -1188,7 +1188,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
|
|||||||
* case yet, so for now, we'll just ignore the duplicate
|
* case yet, so for now, we'll just ignore the duplicate
|
||||||
* for device creation.
|
* for device creation.
|
||||||
*/
|
*/
|
||||||
if (guid_already_parsed(device, gblock[i].guid))
|
if (guid_already_parsed(device, &gblock[i].guid))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
|
wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
|
||||||
@ -1225,7 +1225,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
|
|||||||
retval = device_add(&wblock->dev.dev);
|
retval = device_add(&wblock->dev.dev);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
dev_err(wmi_bus_dev, "failed to register %pUL\n",
|
dev_err(wmi_bus_dev, "failed to register %pUL\n",
|
||||||
wblock->gblock.guid);
|
&wblock->gblock.guid);
|
||||||
if (debug_event)
|
if (debug_event)
|
||||||
wmi_method_enable(wblock, 0);
|
wmi_method_enable(wblock, 0);
|
||||||
list_del(&wblock->list);
|
list_del(&wblock->list);
|
||||||
@ -1333,7 +1333,7 @@ static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (debug_event)
|
if (debug_event)
|
||||||
pr_info("DEBUG Event GUID: %pUL\n", wblock->gblock.guid);
|
pr_info("DEBUG Event GUID: %pUL\n", &wblock->gblock.guid);
|
||||||
|
|
||||||
acpi_bus_generate_netlink_event(
|
acpi_bus_generate_netlink_event(
|
||||||
wblock->acpi_device->pnp.device_class,
|
wblock->acpi_device->pnp.device_class,
|
||||||
|
Reference in New Issue
Block a user