From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: torvalds@linux-foundation.org
Cc: arnd@arndb.de, jakobkoschel@gmail.com,
linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
keescook@chromium.org, jannh@google.com,
linux-kbuild@vger.kernel.org, linux-mm@kvack.org,
netdev@vger.kernel.org, Xiaomeng Tong <xiam0nd.tong@gmail.com>
Subject: [PATCH 3/6] kernel: remove iterator use outside the loop
Date: Tue, 1 Mar 2022 15:58:36 +0800 [thread overview]
Message-ID: <20220301075839.4156-4-xiam0nd.tong@gmail.com> (raw)
In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com>
Demonstrations for:
- list_for_each_entry_inside
- list_for_each_entry_continue_inside
- list_for_each_entry_safe_continue_inside
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
kernel/power/snapshot.c | 28 ++++++++++++++++------------
kernel/signal.c | 6 +++---
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 330d49937..75958b5fa 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -625,16 +625,18 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask)
for_each_populated_zone(zone) {
unsigned long zone_start, zone_end;
- struct mem_extent *ext, *cur, *aux;
+ struct mem_extent *me = NULL;
zone_start = zone->zone_start_pfn;
zone_end = zone_end_pfn(zone);
- list_for_each_entry(ext, list, hook)
- if (zone_start <= ext->end)
+ list_for_each_entry_inside(ext, struct mem_extent, list, hook)
+ if (zone_start <= ext->end) {
+ me = ext;
break;
+ }
- if (&ext->hook == list || zone_end < ext->start) {
+ if (!me || zone_end < me->start) {
/* New extent is necessary */
struct mem_extent *new_ext;
@@ -645,23 +647,25 @@ static int create_mem_extents(struct list_head *list, gfp_t gfp_mask)
}
new_ext->start = zone_start;
new_ext->end = zone_end;
- list_add_tail(&new_ext->hook, &ext->hook);
+ if (!me)
+ list_add_tail(&new_ext->hook, list);
+ else
+ list_add_tail(&new_ext->hook, &me->hook);
continue;
}
/* Merge this zone's range of PFNs with the existing one */
- if (zone_start < ext->start)
- ext->start = zone_start;
- if (zone_end > ext->end)
- ext->end = zone_end;
+ if (zone_start < me->start)
+ me->start = zone_start;
+ if (zone_end > me->end)
+ me->end = zone_end;
/* More merging may be possible */
- cur = ext;
- list_for_each_entry_safe_continue(cur, aux, list, hook) {
+ list_for_each_entry_safe_continue_inside(cur, aux, me, list, hook) {
if (zone_end < cur->start)
break;
if (zone_end < cur->end)
- ext->end = cur->end;
+ me->end = cur->end;
list_del(&cur->hook);
kfree(cur);
}
diff --git a/kernel/signal.c b/kernel/signal.c
index 9b04631ac..da2c20de1 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -711,7 +711,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info)
{
struct task_struct *tsk = current;
struct sigpending *pending = &tsk->pending;
- struct sigqueue *q, *sync = NULL;
+ struct sigqueue *sync = NULL;
/*
* Might a synchronous signal be in the queue?
@@ -722,7 +722,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info)
/*
* Return the first synchronous signal in the queue.
*/
- list_for_each_entry(q, &pending->list, list) {
+ list_for_each_entry_inside(q, struct sigqueue, &pending->list, list) {
/* Synchronous signals have a positive si_code */
if ((q->info.si_code > SI_USER) &&
(sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) {
@@ -735,7 +735,7 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info)
/*
* Check if there is another siginfo for the same signal.
*/
- list_for_each_entry_continue(q, &pending->list, list) {
+ list_for_each_entry_continue_inside(q, sync, &pending->list, list) {
if (q->info.si_signo == sync->info.si_signo)
goto still_pending;
}
--
2.17.1
next prev parent reply other threads:[~2022-03-01 7:59 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 7:58 [PATCH 0/6] list_for_each_entry*: make iterator invisiable " Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 1/6] Kbuild: compile kernel with gnu11 std Xiaomeng Tong
2022-03-01 17:59 ` kernel test robot
2022-03-01 20:16 ` Linus Torvalds
2022-03-01 20:54 ` Arnd Bergmann
2022-03-01 21:04 ` Linus Torvalds
2022-03-01 21:15 ` Linus Torvalds
2022-03-01 21:43 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Xiaomeng Tong
2022-03-02 2:52 ` kernel test robot
2022-03-02 13:02 ` James Bottomley
2022-03-03 3:31 ` Xiaomeng Tong
2022-03-06 14:33 ` James Bottomley
2022-03-03 20:02 ` Linus Torvalds
2022-03-04 2:51 ` Xiaomeng Tong
2022-03-05 21:09 ` Linus Torvalds
2022-03-06 0:35 ` Linus Torvalds
2022-03-06 12:19 ` Jakob Koschel
2022-03-06 18:57 ` Linus Torvalds
2022-03-06 14:06 ` Xiaomeng Tong
2022-03-10 23:54 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable Michał Mirosław
2022-03-11 0:46 ` Linus Torvalds
2022-03-12 10:24 ` Michał Mirosław
2022-03-12 21:43 ` Linus Torvalds
2022-03-11 7:15 ` [RFC PATCH] list: test: Add a test for list_traverse David Gow
2022-03-11 14:27 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Daniel Thompson
2022-03-11 18:41 ` Linus Torvalds
2022-03-16 15:45 ` Daniel Thompson
2022-03-01 7:58 ` Xiaomeng Tong [this message]
2022-03-01 10:41 ` [PATCH 3/6] kernel: remove iterator use " Greg KH
2022-03-01 11:34 ` Xiaomeng Tong
2022-03-01 11:48 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 4/6] mm: " Xiaomeng Tong
2022-03-01 12:19 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 5/6] net/core: " Xiaomeng Tong
2022-03-01 12:23 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 6/6] drivers/dma: " Xiaomeng Tong
2022-03-01 12:25 ` Xiaomeng Tong
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=20220301075839.4156-4-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jakobkoschel@gmail.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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