public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] kcov: Switch to use list_for_each_entry() helper
@ 2022-09-22 10:50 Chen Zhongjin
  2022-09-22 12:15 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Zhongjin @ 2022-09-22 10:50 UTC (permalink / raw)
  To: linux-kernel, kasan-dev
  Cc: liu3101, bigeasy, nogikh, elver, akpm, andreyknvl, dvyukov,
	chenzhongjin

Use list_for_each_entry() helper instead of list_for_each() and
list_entry() to simplify code a bit.

Signed-off-by: Chen Zhongjin <chenzhongjin@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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] kcov: Switch to use list_for_each_entry() helper
  2022-09-22 10:50 [PATCH -next] kcov: Switch to use list_for_each_entry() helper Chen Zhongjin
@ 2022-09-22 12:15 ` Sebastian Andrzej Siewior
  2022-09-22 12:22   ` Chen Zhongjin
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-09-22 12:15 UTC (permalink / raw)
  To: Chen Zhongjin
  Cc: linux-kernel, kasan-dev, liu3101, nogikh, elver, akpm, andreyknvl,
	dvyukov

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] kcov: Switch to use list_for_each_entry() helper
  2022-09-22 12:15 ` Sebastian Andrzej Siewior
@ 2022-09-22 12:22   ` Chen Zhongjin
  2022-09-22 13:10     ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Zhongjin @ 2022-09-22 12:22 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, kasan-dev, liu3101, nogikh, elver, akpm, andreyknvl,
	dvyukov


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!

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] kcov: Switch to use list_for_each_entry() helper
  2022-09-22 12:22   ` Chen Zhongjin
@ 2022-09-22 13:10     ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-09-22 13:10 UTC (permalink / raw)
  To: Chen Zhongjin
  Cc: linux-kernel, kasan-dev, liu3101, nogikh, elver, akpm, andreyknvl,
	dvyukov

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-22 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-22 10:50 [PATCH -next] kcov: Switch to use list_for_each_entry() helper Chen Zhongjin
2022-09-22 12:15 ` Sebastian Andrzej Siewior
2022-09-22 12:22   ` Chen Zhongjin
2022-09-22 13:10     ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox