Skip to content

Commit 26de0ab

Browse files
Jakob-Koschelrafaeljw
authored andcommitted
ACPI: IPMI: replace usage of found with dedicated list iterator variable
To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 242ba66 commit 26de0ab

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

drivers/acpi/acpi_ipmi.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,29 +353,27 @@ static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
353353
static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi,
354354
struct acpi_ipmi_msg *msg)
355355
{
356-
struct acpi_ipmi_msg *tx_msg, *temp;
357-
bool msg_found = false;
356+
struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
358357
unsigned long flags;
359358

360359
spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
361-
list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
362-
if (msg == tx_msg) {
363-
msg_found = true;
364-
list_del(&tx_msg->head);
360+
list_for_each_entry_safe(iter, temp, &ipmi->tx_msg_list, head) {
361+
if (msg == iter) {
362+
tx_msg = iter;
363+
list_del(&iter->head);
365364
break;
366365
}
367366
}
368367
spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
369368

370-
if (msg_found)
369+
if (tx_msg)
371370
acpi_ipmi_msg_put(tx_msg);
372371
}
373372

374373
static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
375374
{
376375
struct acpi_ipmi_device *ipmi_device = user_msg_data;
377-
bool msg_found = false;
378-
struct acpi_ipmi_msg *tx_msg, *temp;
376+
struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
379377
struct device *dev = ipmi_device->dev;
380378
unsigned long flags;
381379

@@ -387,16 +385,16 @@ static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
387385
}
388386

389387
spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
390-
list_for_each_entry_safe(tx_msg, temp, &ipmi_device->tx_msg_list, head) {
391-
if (msg->msgid == tx_msg->tx_msgid) {
392-
msg_found = true;
393-
list_del(&tx_msg->head);
388+
list_for_each_entry_safe(iter, temp, &ipmi_device->tx_msg_list, head) {
389+
if (msg->msgid == iter->tx_msgid) {
390+
tx_msg = iter;
391+
list_del(&iter->head);
394392
break;
395393
}
396394
}
397395
spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
398396

399-
if (!msg_found) {
397+
if (!tx_msg) {
400398
dev_warn(dev,
401399
"Unexpected response (msg id %ld) is returned.\n",
402400
msg->msgid);
@@ -482,15 +480,14 @@ static void ipmi_register_bmc(int iface, struct device *dev)
482480

483481
static void ipmi_bmc_gone(int iface)
484482
{
485-
struct acpi_ipmi_device *ipmi_device, *temp;
486-
bool dev_found = false;
483+
struct acpi_ipmi_device *ipmi_device = NULL, *iter, *temp;
487484

488485
mutex_lock(&driver_data.ipmi_lock);
489-
list_for_each_entry_safe(ipmi_device, temp,
486+
list_for_each_entry_safe(iter, temp,
490487
&driver_data.ipmi_devices, head) {
491-
if (ipmi_device->ipmi_ifnum != iface) {
492-
dev_found = true;
493-
__ipmi_dev_kill(ipmi_device);
488+
if (iter->ipmi_ifnum != iface) {
489+
ipmi_device = iter;
490+
__ipmi_dev_kill(iter);
494491
break;
495492
}
496493
}
@@ -500,7 +497,7 @@ static void ipmi_bmc_gone(int iface)
500497
struct acpi_ipmi_device, head);
501498
mutex_unlock(&driver_data.ipmi_lock);
502499

503-
if (dev_found) {
500+
if (ipmi_device) {
504501
ipmi_flush_tx_msg(ipmi_device);
505502
acpi_ipmi_dev_put(ipmi_device);
506503
}

0 commit comments

Comments
 (0)