mm, sparse: remove check with __highest_present_section_nr in for_each_present_section_nr()
Subsystems (2)
PATCH 1/1 mm, sparse: remove check with __highest_present_section_nr in for_each_present_section_nr()
A valid present section number is in [0, __highest_present_section_nr]. And the return value of next_present_section_nr() meets this requirement. This means it is not necessary to check it with __highest_present_section_nr again in for_each_present_section_nr().
Since we pass an unsigned long *section_nr* to for_each_present_section_nr(), we need to cast it to int before comparing.
--- mm/sparse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/sparse.c +1 -2
@@ -197,8 +197,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)); \ + (int)section_nr >= 0; \ section_nr = next_present_section_nr(section_nr))static inline unsigned long first_present_section_nr (void )
Signature · 1 line
2.15.1
Quoted 3 lines · Wei Yang
A valid present section number is in [0,
__highest_present_section_nr]. And the return value ofnext_present_section_nr()meets this requirement. This means it is not necessary to check it with
^ , if it is not (-1)
Would like to add this to be more exact.
Quoted 27 lines
__highest_present_section_nragain infor_each_present_section_nr().Since we pass an unsigned long *section_nr* to
for_each_present_section_nr(), we need to cast it to int before comparing.Signed-off-by Wei Yang <[email protected]>---
mm/sparse.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)mm/sparse.c +1
-2@@ -197,8 +197,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)); \ + (int)section_nr >= 0; \ section_nr = next_present_section_nr(section_nr))static inline unsigned long first_present_section_nr (void )Signature · 1 line
2.15.1
Signature · 2 lines
Wei Yang Help you, Help me
Michal Hocko
reviewerQuoted 8 lines · Wei Yang
A valid present section number is in [0,
__highest_present_section_nr]. And the return value ofnext_present_section_nr()meets this requirement. This means it is not necessary to check it with__highest_present_section_nragain infor_each_present_section_nr().Since we pass an unsigned long *section_nr* to
for_each_present_section_nr(), we need to cast it to int before comparing.
Why do we want this patch? Is it an improvement? If yes, it is performance visible change or does it make the code easier to maintain?
To me at least the later seems dubious to be honest because it adds a non-obvious dependency of the terminal condition to the next_present_section_nr implementation and that might turn out error prone.
Quoted 22 lines
Signed-off-by Wei Yang <[email protected]>--- mm/sparse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/sparse.c +1
-2@@ -197,8 +197,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)); \ + (int)section_nr >= 0; \ section_nr = next_present_section_nr(section_nr))static inline unsigned long first_present_section_nr (void )Signature · 1 line
2.15.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 6 lines · Michal Hocko
Quoted 5 lines · Wei Yang
A valid present section number is in [0,
__highest_present_section_nr]. And the return value ofnext_present_section_nr()meets this requirement. This means it is not necessary to check it with__highest_present_section_nragain infor_each_present_section_nr().
Quoted 7 lines
Quoted 3 lines
Since we pass an unsigned long *section_nr* to
for_each_present_section_nr(), we need to cast it to int before comparing.Why do we want this patch? Is it an improvement? If yes, it is performance visible change or does it make the code easier to maintain?
Michal
I know you concern, maintainance is a very critical part of review.
Quoted 5 lines
To me at least the later seems dubious to be honest because it adds a non-obvious dependency of the terminal condition to the
next_present_section_nrimplementation and that might turn out error prone.
While I think the original code is not that clear about the syntax.
When we look at the next_present_section_nr(section_nr), the return value falls into two categories:
-1 : no more present section after section_nr
other: the next present section number after section_nr
Based on this syntax, the iteration could be simpler to terminate when the return value is less than 0. This is what the patch tries to do.
Maybe I could do more to help the maintainance:
* add some comment about the return value of next_present_section_nr
* terminate the loop when section_nr == -1
Hope this would help a little.
Signature · 2 lines
Wei Yang Help you, Help me
Michal Hocko
reviewerQuoted 37 lines · Wei Yang
Quoted 6 lines · Michal Hocko
Quoted 5 lines · Wei Yang
A valid present section number is in [0,
__highest_present_section_nr]. And the return value ofnext_present_section_nr()meets this requirement. This means it is not necessary to check it with__highest_present_section_nragain infor_each_present_section_nr().Quoted 7 lines
Quoted 3 lines
Since we pass an unsigned long *section_nr* to
for_each_present_section_nr(), we need to cast it to int before comparing.Why do we want this patch? Is it an improvement? If yes, it is performance visible change or does it make the code easier to maintain?
Michal
I know you concern, maintainance is a very critical part of review.
Quoted 5 lines
To me at least the later seems dubious to be honest because it adds a non-obvious dependency of the terminal condition to the
next_present_section_nrimplementation and that might turn out error prone.While I think the original code is not that clear about the syntax.
When we look at the
next_present_section_nr(section_nr), the return value falls into two categories:-1 : no more present section after
section_nr
other: the next present section number aftersection_nrBased on this syntax, the iteration could be simpler to terminate when the return value is less than 0. This is what the patch tries to do.
Quoted 6 lines
Maybe I could do more to help the maintainance:
* add some comment about the return value of
next_present_section_nr
* terminate the loop whensection_nr== -1Hope this would help a little.
Well, not really. Nothing of the above seems to matter to callers of the code. So I do not see this as a general improvement and as such no strong reason to merge it. It is basicly polishing a code without any obvious issues.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 43 lines · Michal Hocko
Quoted 42 lines · Wei Yang
Quoted 6 lines · Michal Hocko
Quoted 5 lines · Wei Yang
A valid present section number is in [0,
__highest_present_section_nr]. And the return value ofnext_present_section_nr()meets this requirement. This means it is not necessary to check it with__highest_present_section_nragain infor_each_present_section_nr().Quoted 7 lines
Quoted 3 lines
Since we pass an unsigned long *section_nr* to
for_each_present_section_nr(), we need to cast it to int before comparing.Why do we want this patch? Is it an improvement? If yes, it is performance visible change or does it make the code easier to maintain?
Michal
I know you concern, maintainance is a very critical part of review.
Quoted 5 lines
To me at least the later seems dubious to be honest because it adds a non-obvious dependency of the terminal condition to the
next_present_section_nrimplementation and that might turn out error prone.While I think the original code is not that clear about the syntax.
When we look at the
next_present_section_nr(section_nr), the return value falls into two categories:-1 : no more present section after
section_nr
other: the next present section number aftersection_nrBased on this syntax, the iteration could be simpler to terminate when the return value is less than 0. This is what the patch tries to do.
Maybe I could do more to help the maintainance:
* add some comment about the return value of
next_present_section_nr
* terminate the loop whensection_nr== -1
Quoted 6 lines
Quoted 1 line
Hope this would help a little.
Well, not really. Nothing of the above seems to matter to callers of the code. So I do not see this as a general improvement and as such no strong reason to merge it. It is basicly polishing a code without any obvious issues.
Er... but I don't see the reason to keep a redundant check in the code.
Even this is an internal function, it would be better to make it clean and neat. Would you mind sharing your concern about this polishing? If there is no issue, we would prefer no polishing of the code?
Quoted 3 lines
Signature · 2 lines
Michal Hocko SUSE Labs
Signature · 2 lines
Wei Yang Help you, Help me