Skip to content

Commit

Permalink
ACPI: list_for_each_safe() -> list_for_each_entry_safe()
Browse files Browse the repository at this point in the history
Replace list_for_each_safe() and open-coded list entry address
computations with list_for_each_entry_safe() in several places to
simplify code.

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
[ rjw: Subject & changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
chenqiwu authored and Rafael J. Wysocki committed Mar 4, 2020
1 parent 98d54f8 commit 07761a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
14 changes: 6 additions & 8 deletions drivers/acpi/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ ACPI_MODULE_NAME("sleep")
static int
acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
{
struct list_head *node, *next;
struct acpi_device *dev, *tmp;

seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");

mutex_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device *dev =
container_of(node, struct acpi_device, wakeup_list);
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
wakeup_list) {
struct acpi_device_physical_node *entry;

if (!dev->wakeup.flags.valid)
Expand Down Expand Up @@ -96,7 +95,7 @@ acpi_system_write_wakeup_device(struct file *file,
const char __user * buffer,
size_t count, loff_t * ppos)
{
struct list_head *node, *next;
struct acpi_device *dev, *tmp;
char strbuf[5];
char str[5] = "";

Expand All @@ -109,9 +108,8 @@ acpi_system_write_wakeup_device(struct file *file,
sscanf(strbuf, "%s", str);

mutex_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device *dev =
container_of(node, struct acpi_device, wakeup_list);
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
wakeup_list) {
if (!dev->wakeup.flags.valid)
continue;

Expand Down
24 changes: 9 additions & 15 deletions drivers/acpi/wakeup.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ ACPI_MODULE_NAME("wakeup_devices")
*/
void acpi_enable_wakeup_devices(u8 sleep_state)
{
struct list_head *node, *next;

list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device *dev =
container_of(node, struct acpi_device, wakeup_list);
struct acpi_device *dev, *tmp;

list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
wakeup_list) {
if (!dev->wakeup.flags.valid
|| sleep_state > (u32) dev->wakeup.sleep_state
|| !(device_may_wakeup(&dev->dev)
Expand All @@ -57,12 +55,10 @@ void acpi_enable_wakeup_devices(u8 sleep_state)
*/
void acpi_disable_wakeup_devices(u8 sleep_state)
{
struct list_head *node, *next;

list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device *dev =
container_of(node, struct acpi_device, wakeup_list);
struct acpi_device *dev, *tmp;

list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
wakeup_list) {
if (!dev->wakeup.flags.valid
|| sleep_state > (u32) dev->wakeup.sleep_state
|| !(device_may_wakeup(&dev->dev)
Expand All @@ -79,13 +75,11 @@ void acpi_disable_wakeup_devices(u8 sleep_state)

int __init acpi_wakeup_device_init(void)
{
struct list_head *node, *next;
struct acpi_device *dev, *tmp;

mutex_lock(&acpi_device_lock);
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
struct acpi_device *dev = container_of(node,
struct acpi_device,
wakeup_list);
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
wakeup_list) {
if (device_can_wakeup(&dev->dev)) {
/* Button GPEs are supposed to be always enabled. */
acpi_enable_gpe(dev->wakeup.gpe_device,
Expand Down

0 comments on commit 07761a4

Please sign in to comment.