Re: [RESEND#2 PATCH] mm/compaction: fix an undefined behaviour
From: Qian Cai
Date: Wed Mar 20 2019 - 18:12:45 EST
On 3/20/19 5:58 PM, Andrew Morton wrote:
>> ---
>> mm/compaction.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/compaction.c b/mm/compaction.c
>> index e1a08fc92353..0d1156578114 100644
>> --- a/mm/compaction.c
>> +++ b/mm/compaction.c
>> @@ -1157,7 +1157,9 @@ static bool suitable_migration_target(struct compact_control *cc,
>> static inline unsigned int
>> freelist_scan_limit(struct compact_control *cc)
>> {
>> - return (COMPACT_CLUSTER_MAX >> cc->fast_search_fail) + 1;
>> + return (COMPACT_CLUSTER_MAX >>
>> + min((unsigned short)(BITS_PER_LONG - 1), cc->fast_search_fail))
>> + + 1;
>> }
>
> That's rather an eyesore. How about
>
> static inline unsigned int
> freelist_scan_limit(struct compact_control *cc)
> {
> unsigned short shift = BITS_PER_LONG - 1;
>
> return (COMPACT_CLUSTER_MAX >> min(shift, cc->fast_search_fail)) + 1;
> }
Agree. It looks better.