tools/testing/nvdimm: replace usage of found with dedicated list iterator variable
Subsystems (2)
PATCH 1/1 tools/testing/nvdimm: 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/ open here
Signed-off-by Jakob Koschel <[email protected]>
--- drivers/acpi/nfit/mce.c | 11 +++++------ tools/testing/nvdimm/test/iomap.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-)
drivers/acpi/nfit/mce.c +5 -6
@@ -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 */
tools/testing/nvdimm/test/iomap.c +9 -9
@@ -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
Signature · 1 line
2.25.1