All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/sparse: remove a check that compare if unsigned variable is negative
@ 2018-10-13 16:15 Peng Hao
  2018-10-13 17:04 ` Pavel Tatashin
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Hao @ 2018-10-13 16:15 UTC (permalink / raw)
  To: linux-mm; +Cc: akpm, pasha.tatashin, osalvador, linux-kernel, Peng Hao


From: Peng Hao <peng.hao2@zte.com.cn>

In all use locations for for_each_present_section_nr, variable
section_nr is unsigned. It is unnecessary to test if it is negative.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
---
 mm/sparse.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 10b07ee..a6f9f22 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -196,8 +196,7 @@ static inline int next_present_section_nr(int section_nr)
 }
 #define for_each_present_section_nr(start, section_nr)		\
 	for (section_nr = next_present_section_nr(start-1);	\
-	     ((section_nr >= 0) &&				\
-	      (section_nr <= __highest_present_section_nr));	\
+	     section_nr <= __highest_present_section_nr;	\
 	     section_nr = next_present_section_nr(section_nr))
 
 static inline unsigned long first_present_section_nr(void)
-- 
1.8.3.1



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

* Re: [PATCH] mm/sparse: remove a check that compare if unsigned variable is negative
  2018-10-13 16:15 [PATCH] mm/sparse: remove a check that compare if unsigned variable is negative Peng Hao
@ 2018-10-13 17:04 ` Pavel Tatashin
  2018-10-15  1:08   ` [PATCH] mm/sparse: remove a check that compare if unsignedvariable " peng.hao2
  2018-10-19  8:28   ` [PATCH] mm/sparse: remove a check that compare if unsigned variable " Wei Yang
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Tatashin @ 2018-10-13 17:04 UTC (permalink / raw)
  To: penghao122
  Cc: Linux Memory Management List, Andrew Morton, pasha.tatashin,
	osalvador, LKML, peng.hao2

This is incorrect: next_present_section_nr() returns "int" and -1 no
next section, this change would lead to infinite loop.
On Sat, Oct 13, 2018 at 12:16 PM Peng Hao <penghao122@sina.com.cn> wrote:
>
>
> From: Peng Hao <peng.hao2@zte.com.cn>
>
> In all use locations for for_each_present_section_nr, variable
> section_nr is unsigned. It is unnecessary to test if it is negative.
>
> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
> ---
>  mm/sparse.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 10b07ee..a6f9f22 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -196,8 +196,7 @@ static inline int next_present_section_nr(int section_nr)
>  }
>  #define for_each_present_section_nr(start, section_nr)         \
>         for (section_nr = next_present_section_nr(start-1);     \
> -            ((section_nr >= 0) &&                              \
> -             (section_nr <= __highest_present_section_nr));    \
> +            section_nr <= __highest_present_section_nr;        \
>              section_nr = next_present_section_nr(section_nr))
>
>  static inline unsigned long first_present_section_nr(void)
> --
> 1.8.3.1
>
>

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

* Re: [PATCH] mm/sparse: remove a check that compare if unsignedvariable is negative
  2018-10-13 17:04 ` Pavel Tatashin
@ 2018-10-15  1:08   ` peng.hao2
  2018-10-19  8:28   ` [PATCH] mm/sparse: remove a check that compare if unsigned variable " Wei Yang
  1 sibling, 0 replies; 4+ messages in thread
From: peng.hao2 @ 2018-10-15  1:08 UTC (permalink / raw)
  To: pasha.tatashin
  Cc: penghao122, linux-mm, akpm, pasha.tatashin, osalvador, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 1321 bytes --]

>This is incorrect: next_present_section_nr() returns "int" and -1 no
>next section, this change would lead to infinite loop.
int x = -1;
unsigned long y = x;
y  is never less than 0 . But y is a large  positive number.
>On Sat, Oct 13, 2018 at 12:16 PM Peng Hao <penghao122@sina.com.cn> wrote:
>>
>> From: Peng Hao <peng.hao2@zte.com.cn>
>>
>> In all use locations for for_each_present_section_nr, variable
>> section_nr is unsigned. It is unnecessary to test if it is negative.
>>
>> Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
>> ---
>>  mm/sparse.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/sparse.c b/mm/sparse.c
>> index 10b07ee..a6f9f22 100644
>> --- a/mm/sparse.c
>> +++ b/mm/sparse.c
>> @@ -196,8 +196,7 @@ static inline int next_present_section_nr(int section_nr)
>>  }
>>  #define for_each_present_section_nr(start, section_nr)         \
>>         for (section_nr = next_present_section_nr(start-1);     \
>> -            ((section_nr >= 0) &&                              \
>> -             (section_nr <= __highest_present_section_nr));    \
>> +            section_nr <= __highest_present_section_nr;        \
>>              section_nr = next_present_section_nr(section_nr))
>>
>>  static inline unsigned long first_present_section_nr(void)
>> --
>> 1.8.3.1
>>
>>

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

* Re: [PATCH] mm/sparse: remove a check that compare if unsigned variable is negative
  2018-10-13 17:04 ` Pavel Tatashin
  2018-10-15  1:08   ` [PATCH] mm/sparse: remove a check that compare if unsignedvariable " peng.hao2
@ 2018-10-19  8:28   ` Wei Yang
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Yang @ 2018-10-19  8:28 UTC (permalink / raw)
  To: Pavel Tatashin
  Cc: penghao122, Linux Memory Management List, Andrew Morton,
	pasha.tatashin, osalvador, LKML, peng.hao2

On Sat, Oct 13, 2018 at 01:04:45PM -0400, Pavel Tatashin wrote:
>This is incorrect: next_present_section_nr() returns "int" and -1 no
>next section, this change would lead to infinite loop.

Yes, the -1 is a very special value.

-- 
Wei Yang
Help you, Help me

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

end of thread, other threads:[~2018-10-19  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-13 16:15 [PATCH] mm/sparse: remove a check that compare if unsigned variable is negative Peng Hao
2018-10-13 17:04 ` Pavel Tatashin
2018-10-15  1:08   ` [PATCH] mm/sparse: remove a check that compare if unsignedvariable " peng.hao2
2018-10-19  8:28   ` [PATCH] mm/sparse: remove a check that compare if unsigned variable " Wei Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.