From: Jakob Koschel <jakobkoschel@gmail.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Zou Wei <zou_wei@huawei.com>,
Bjorn Helgaas <bhelgaas@google.com>,
nvdimm@lists.linux.dev, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org, Mike Rapoport <rppt@kernel.org>,
"Brian Johannesmeyer" <bjohannesmeyer@gmail.com>,
Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>,
Jakob Koschel <jakobkoschel@gmail.com>
Subject: [PATCH] tools/testing/nvdimm: replace usage of found with dedicated list iterator variable
Date: Thu, 24 Mar 2022 08:29:52 +0100 [thread overview]
Message-ID: <20220324072952.65489-1-jakobkoschel@gmail.com> (raw)
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>
---
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
reply other threads:[~2022-03-24 7:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220324072952.65489-1-jakobkoschel@gmail.com \
--to=jakobkoschel@gmail.com \
--cc=bhelgaas@google.com \
--cc=bjohannesmeyer@gmail.com \
--cc=c.giuffrida@vu.nl \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=h.j.bos@vu.nl \
--cc=ira.weiny@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=rafael@kernel.org \
--cc=rppt@kernel.org \
--cc=vishal.l.verma@intel.com \
--cc=zou_wei@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®