Skip to content

Commit 07761a4

Browse files
qiwuchenrafaeljw
authored andcommitted
ACPI: list_for_each_safe() -> list_for_each_entry_safe()
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 <[email protected]> [ rjw: Subject & changelog ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 98d54f8 commit 07761a4

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

drivers/acpi/proc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ ACPI_MODULE_NAME("sleep")
2222
static int
2323
acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
2424
{
25-
struct list_head *node, *next;
25+
struct acpi_device *dev, *tmp;
2626

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

2929
mutex_lock(&acpi_device_lock);
30-
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
31-
struct acpi_device *dev =
32-
container_of(node, struct acpi_device, wakeup_list);
30+
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
31+
wakeup_list) {
3332
struct acpi_device_physical_node *entry;
3433

3534
if (!dev->wakeup.flags.valid)
@@ -96,7 +95,7 @@ acpi_system_write_wakeup_device(struct file *file,
9695
const char __user * buffer,
9796
size_t count, loff_t * ppos)
9897
{
99-
struct list_head *node, *next;
98+
struct acpi_device *dev, *tmp;
10099
char strbuf[5];
101100
char str[5] = "";
102101

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

111110
mutex_lock(&acpi_device_lock);
112-
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
113-
struct acpi_device *dev =
114-
container_of(node, struct acpi_device, wakeup_list);
111+
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
112+
wakeup_list) {
115113
if (!dev->wakeup.flags.valid)
116114
continue;
117115

drivers/acpi/wakeup.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ ACPI_MODULE_NAME("wakeup_devices")
3030
*/
3131
void acpi_enable_wakeup_devices(u8 sleep_state)
3232
{
33-
struct list_head *node, *next;
34-
35-
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
36-
struct acpi_device *dev =
37-
container_of(node, struct acpi_device, wakeup_list);
33+
struct acpi_device *dev, *tmp;
3834

35+
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
36+
wakeup_list) {
3937
if (!dev->wakeup.flags.valid
4038
|| sleep_state > (u32) dev->wakeup.sleep_state
4139
|| !(device_may_wakeup(&dev->dev)
@@ -57,12 +55,10 @@ void acpi_enable_wakeup_devices(u8 sleep_state)
5755
*/
5856
void acpi_disable_wakeup_devices(u8 sleep_state)
5957
{
60-
struct list_head *node, *next;
61-
62-
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
63-
struct acpi_device *dev =
64-
container_of(node, struct acpi_device, wakeup_list);
58+
struct acpi_device *dev, *tmp;
6559

60+
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
61+
wakeup_list) {
6662
if (!dev->wakeup.flags.valid
6763
|| sleep_state > (u32) dev->wakeup.sleep_state
6864
|| !(device_may_wakeup(&dev->dev)
@@ -79,13 +75,11 @@ void acpi_disable_wakeup_devices(u8 sleep_state)
7975

8076
int __init acpi_wakeup_device_init(void)
8177
{
82-
struct list_head *node, *next;
78+
struct acpi_device *dev, *tmp;
8379

8480
mutex_lock(&acpi_device_lock);
85-
list_for_each_safe(node, next, &acpi_wakeup_device_list) {
86-
struct acpi_device *dev = container_of(node,
87-
struct acpi_device,
88-
wakeup_list);
81+
list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
82+
wakeup_list) {
8983
if (device_can_wakeup(&dev->dev)) {
9084
/* Button GPEs are supposed to be always enabled. */
9185
acpi_enable_gpe(dev->wakeup.gpe_device,

0 commit comments

Comments
 (0)