[PATCH -next] kcov: Switch to use list_for_each_entry() helper

2 views
Skip to first unread message

Chen Zhongjin

unread,
Sep 22, 2022, 6:54:10 AM9/22/22
to linux-...@vger.kernel.org, kasa...@googlegroups.com, liu...@purdue.edu, big...@linutronix.de, nog...@google.com, el...@google.com, ak...@linux-foundation.org, andre...@gmail.com, dvy...@google.com, chenzh...@huawei.com
Use list_for_each_entry() helper instead of list_for_each() and
list_entry() to simplify code a bit.

Signed-off-by: Chen Zhongjin <chenzh...@huawei.com>
---
kernel/kcov.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/kcov.c b/kernel/kcov.c
index e19c84b02452..466d7689de5b 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -133,10 +133,8 @@ static struct kcov_remote *kcov_remote_add(struct kcov *kcov, u64 handle)
static struct kcov_remote_area *kcov_remote_area_get(unsigned int size)
{
struct kcov_remote_area *area;
- struct list_head *pos;

- list_for_each(pos, &kcov_remote_areas) {
- area = list_entry(pos, struct kcov_remote_area, list);
+ list_for_each_entry(pos, &kcov_remote_areas, list) {
if (area->size == size) {
list_del(&area->list);
return area;
--
2.17.1

Sebastian Andrzej Siewior

unread,
Sep 22, 2022, 8:15:23 AM9/22/22
to Chen Zhongjin, linux-...@vger.kernel.org, kasa...@googlegroups.com, liu...@purdue.edu, nog...@google.com, el...@google.com, ak...@linux-foundation.org, andre...@gmail.com, dvy...@google.com
On 2022-09-22 18:50:25 [+0800], Chen Zhongjin wrote:
> --- a/kernel/kcov.c
> +++ b/kernel/kcov.c
> @@ -133,10 +133,8 @@ static struct kcov_remote *kcov_remote_add(struct kcov *kcov, u64 handle)
> static struct kcov_remote_area *kcov_remote_area_get(unsigned int size)
> {
> struct kcov_remote_area *area;
> - struct list_head *pos;
>
> - list_for_each(pos, &kcov_remote_areas) {
> - area = list_entry(pos, struct kcov_remote_area, list);
> + list_for_each_entry(pos, &kcov_remote_areas, list) {

so how does this work if you remove pos?

> if (area->size == size) {
> list_del(&area->list);
> return area;

Sebastian

Chen Zhongjin

unread,
Sep 22, 2022, 8:22:23 AM9/22/22
to Sebastian Andrzej Siewior, linux-...@vger.kernel.org, kasa...@googlegroups.com, liu...@purdue.edu, nog...@google.com, el...@google.com, ak...@linux-foundation.org, andre...@gmail.com, dvy...@google.com

On 2022/9/22 20:15, Sebastian Andrzej Siewior wrote:
> On 2022-09-22 18:50:25 [+0800], Chen Zhongjin wrote:
>> --- a/kernel/kcov.c
>> +++ b/kernel/kcov.c
>> @@ -133,10 +133,8 @@ static struct kcov_remote *kcov_remote_add(struct kcov *kcov, u64 handle)
>> static struct kcov_remote_area *kcov_remote_area_get(unsigned int size)
>> {
>> struct kcov_remote_area *area;
>> - struct list_head *pos;
>>
>> - list_for_each(pos, &kcov_remote_areas) {
>> - area = list_entry(pos, struct kcov_remote_area, list);
>> + list_for_each_entry(pos, &kcov_remote_areas, list) {
> so how does this work if you remove pos?

Oops... will fix that.


Thanks so much!

Chen Zhongjin

unread,
Sep 22, 2022, 8:41:55 AM9/22/22
to linux-...@vger.kernel.org, kasa...@googlegroups.com, dvy...@google.com, andre...@gmail.com, ak...@linux-foundation.org, el...@google.com, big...@linutronix.de, nog...@google.com, liu...@purdue.edu, chenzh...@huawei.com
Use list_for_each_entry() helper instead of list_for_each() and
list_entry() to simplify code a bit.

Signed-off-by: Chen Zhongjin <chenzh...@huawei.com>
---
v1 -> v2:
- Forgot to change pos as area, fix it.
---
kernel/kcov.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/kcov.c b/kernel/kcov.c
index e19c84b02452..6c94913dc3a6 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -133,10 +133,8 @@ static struct kcov_remote *kcov_remote_add(struct kcov *kcov, u64 handle)
static struct kcov_remote_area *kcov_remote_area_get(unsigned int size)
{
struct kcov_remote_area *area;
- struct list_head *pos;

- list_for_each(pos, &kcov_remote_areas) {
- area = list_entry(pos, struct kcov_remote_area, list);
+ list_for_each_entry(area, &kcov_remote_areas, list) {
if (area->size == size) {
list_del(&area->list);
return area;
--
2.17.1

Sebastian Andrzej Siewior

unread,
Sep 22, 2022, 9:11:00 AM9/22/22
to Chen Zhongjin, linux-...@vger.kernel.org, kasa...@googlegroups.com, liu...@purdue.edu, nog...@google.com, el...@google.com, ak...@linux-foundation.org, andre...@gmail.com, dvy...@google.com
On 2022-09-22 20:22:19 [+0800], Chen Zhongjin wrote:
> Oops... will fix that.

Please _never_ again post patches without testing them first.

Sebastian
Reply all
Reply to author
Forward
0 new messages