From: Zhen Lei <thunder.leizhen@huawei.com>
To: Oliver O'Halloran <oohall@gmail.com>,
Dan Williams <dan.j.williams@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
"Dave Jiang" <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Markus Elfring <Markus.Elfring@web.de>,
linux-nvdimm <linux-nvdimm@lists.01.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>,
Libin <huawei.libin@huawei.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH v2 1/2] libnvdimm/badrange: remove two redundant list_empty() branches
Date: Sat, 19 Sep 2020 18:45:45 +0800 [thread overview]
Message-ID: <20200919104546.3848-2-thunder.leizhen@huawei.com> (raw)
In-Reply-To: <20200919104546.3848-1-thunder.leizhen@huawei.com>
In add_badrange() or badblocks_populate(), the list_empty() branch does
the same things as the code after list_for_each_entry().
The pseudo code is as follows:
1) if (list_empty()) {
do things-A
return Y;
}
2) list_for_each_entry()
do things-B //can only be entered if !list_empty()
3) do things-A
return Y;
It's very clear that, the processing result after deleting 1) is the same
as that before deleting 1).
So delete 1) to simplify code.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
drivers/nvdimm/badrange.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c
index b9eeefa27e3a507..9fdba8c43e8605e 100644
--- a/drivers/nvdimm/badrange.c
+++ b/drivers/nvdimm/badrange.c
@@ -53,13 +53,6 @@ static int add_badrange(struct badrange *badrange, u64 addr, u64 length)
bre_new = kzalloc(sizeof(*bre_new), GFP_KERNEL);
spin_lock(&badrange->lock);
- if (list_empty(&badrange->list)) {
- if (!bre_new)
- return -ENOMEM;
- append_badrange_entry(badrange, bre_new, addr, length);
- return 0;
- }
-
/*
* There is a chance this is a duplicate, check for those first.
* This will be the common case as ARS_STATUS returns all known
@@ -215,9 +208,6 @@ static void badblocks_populate(struct badrange *badrange,
{
struct badrange_entry *bre;
- if (list_empty(&badrange->list))
- return;
-
list_for_each_entry(bre, &badrange->list, list) {
u64 bre_end = bre->start + bre->length - 1;
--
1.8.3
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-09-19 10:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-19 10:45 [PATCH v2 0/2] libnvdimm/badrange: simplify code Zhen Lei
2020-09-19 10:45 ` Zhen Lei [this message]
2020-09-19 10:45 ` [PATCH v2 2/2] libnvdimm/badrange: eliminate a meaningless spinlock operation Zhen Lei
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=20200919104546.3848-2-thunder.leizhen@huawei.com \
--to=thunder.leizhen@huawei.com \
--cc=Markus.Elfring@web.de \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=huawei.libin@huawei.com \
--cc=ira.weiny@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=oohall@gmail.com \
--cc=vishal.l.verma@intel.com \
--cc=wangkefeng.wang@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;
as well as URLs for NNTP newsgroup(s).