Offering HULK hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I67QNJ CVE: NA
------------------------------------------
Export the containers in the system, drivers can take the advantage of these containers to manipulate the devices in the container.
Signed-off-by: Zhang Zekun zhangzekun11@huawei.com --- drivers/acpi/container.c | 51 +++++++++++++++++++++++++++++++++++++++ include/linux/container.h | 8 ++++++ 2 files changed, 59 insertions(+)
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c index ccaa647ac3d4..fc9816b52537 100644 --- a/drivers/acpi/container.c +++ b/drivers/acpi/container.c @@ -11,6 +11,7 @@ */ #include <linux/acpi.h> #include <linux/container.h> +#include <linux/list.h>
#include "internal.h"
@@ -23,6 +24,52 @@ static const struct acpi_device_id container_device_ids[] = {
#ifdef CONFIG_ACPI_CONTAINER
+struct cdev_node *cdev_list; +EXPORT_SYMBOL_GPL(cdev_list); + +static void cdev_list_init(void) +{ + cdev_list = kmalloc(sizeof(struct cdev_node), GFP_KERNEL); + if (!cdev_list) { + pr_debug("container list init failed\n"); + return; + } + + INIT_LIST_HEAD(&cdev_list->clist); +} + +static void cdev_list_del_node(struct acpi_device *adev) +{ + struct cdev_node *cnode, *tmp; + + if (!cdev_list) + return; + + list_for_each_entry_safe(cnode, tmp, &cdev_list->clist, clist) { + if (cnode->dev == &adev->dev) { + list_del(&cnode->clist); + kfree(cnode); + } + } +} + +static void cdev_list_add_node(struct acpi_device *adev) +{ + struct cdev_node *cnode; + + if (!cdev_list) + return; + + cnode = kmalloc(sizeof(struct cdev_node), GFP_KERNEL); + if (!cnode) { + pr_debug("container list add cdev_node failed\n"); + return; + } + + cnode->dev = &adev->dev; + list_add_tail(&cnode->clist, &cdev_list->clist); +} + static int acpi_container_offline(struct container_dev *cdev) { struct acpi_device *adev = ACPI_COMPANION(&cdev->dev); @@ -67,6 +114,8 @@ static int container_device_attach(struct acpi_device *adev, return ret; } adev->driver_data = dev; + cdev_list_add_node(adev); + return 1; }
@@ -74,6 +123,7 @@ static void container_device_detach(struct acpi_device *adev) { struct device *dev = acpi_driver_data(adev);
+ cdev_list_del_node(adev); adev->driver_data = NULL; if (dev) device_unregister(dev); @@ -100,6 +150,7 @@ static struct acpi_scan_handler container_handler = { void __init acpi_container_init(void) { acpi_scan_add_handler(&container_handler); + cdev_list_init(); }
#else diff --git a/include/linux/container.h b/include/linux/container.h index 2566a1baa736..1f5fa722777f 100644 --- a/include/linux/container.h +++ b/include/linux/container.h @@ -24,4 +24,12 @@ static inline struct container_dev *to_container_dev(struct device *dev) return container_of(dev, struct container_dev, dev); }
+/* drivers/acpi/container.c */ +extern struct cdev_node *cdev_list; + +struct cdev_node { + struct device *dev; + struct list_head clist; +}; + #endif /* _LINUX_CONTAINER_H */