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@xxxxxxxxxxxxxx/ Signed-off-by: Jakob Koschel <jakobkoschel@xxxxxxxxx> --- drivers/acpi/nfit/mce.c | 11 +++++------ tools/testing/nvdimm/test/iomap.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/nfit/mce.c b/drivers/acpi/nfit/mce.c index ee8d9973f60b..6d11506e871e 100644 --- a/drivers/acpi/nfit/mce.c +++ b/drivers/acpi/nfit/mce.c @@ -15,7 +15,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val, { struct mce *mce = (struct mce *)data; struct acpi_nfit_desc *acpi_desc; - struct nfit_spa *nfit_spa; + struct nfit_spa *nfit_spa = NULL, *iter; /* We only care about uncorrectable memory errors */ if (!mce_is_memory_error(mce) || mce_is_correctable(mce)) @@ -33,11 +33,10 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val, mutex_lock(&acpi_desc_lock); list_for_each_entry(acpi_desc, &acpi_descs, list) { struct device *dev = acpi_desc->dev; - int found_match = 0; mutex_lock(&acpi_desc->init_mutex); - list_for_each_entry(nfit_spa, &acpi_desc->spas, list) { - struct acpi_nfit_system_address *spa = nfit_spa->spa; + list_for_each_entry(iter, &acpi_desc->spas, list) { + struct acpi_nfit_system_address *spa = iter->spa; if (nfit_spa_type(spa) != NFIT_SPA_PM) continue; @@ -46,7 +45,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val, continue; if ((spa->address + spa->length - 1) < mce->addr) continue; - found_match = 1; + nfit_spa = iter; dev_dbg(dev, "addr in SPA %d (0x%llx, 0x%llx)\n", spa->range_index, spa->address, spa->length); /* @@ -58,7 +57,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val, } mutex_unlock(&acpi_desc->init_mutex); - if (!found_match) + if (!nfit_spa) continue; /* If this fails due to an -ENOMEM, there is little we can do */ diff --git a/tools/testing/nvdimm/test/iomap.c b/tools/testing/nvdimm/test/iomap.c index b752ce47ead3..5d3d6b0fce2e 100644 --- a/tools/testing/nvdimm/test/iomap.c +++ b/tools/testing/nvdimm/test/iomap.c @@ -227,8 +227,8 @@ static bool nfit_test_release_region(struct device *dev, struct nfit_test_resource *nfit_res = get_nfit_res(start); if (nfit_res) { - struct nfit_test_request *req; - struct resource *res = NULL; + struct nfit_test_request *req = NULL; + struct nfit_test_request *iter; if (dev) { devres_release(dev, nfit_devres_release, match, @@ -237,18 +237,18 @@ static bool nfit_test_release_region(struct device *dev, } spin_lock(&nfit_res->lock); - list_for_each_entry(req, &nfit_res->requests, list) - if (req->res.start == start) { - res = &req->res; - list_del(&req->list); + list_for_each_entry(iter, &nfit_res->requests, list) + if (iter->res.start == start) { + list_del(&iter->list); + req = iter; break; } spin_unlock(&nfit_res->lock); - WARN(!res || resource_size(res) != n, + WARN(!req || resource_size(&req->res) != n, "%s: start: %llx n: %llx mismatch: %pr\n", - __func__, start, n, res); - if (res) + __func__, start, n, &req->res); + if (req) kfree(req); return true; } base-commit: f443e374ae131c168a065ea1748feac6b2e76613 -- 2.25.1