Re: [PATCH] Fix display of Maximum Memory
From: Michael Bringmann
Date: Wed Jan 15 2020 - 09:30:42 EST
On 1/14/20 11:41 PM, Christophe Leroy wrote:
>
>
> Le 14/01/2020 Ã 22:07, Michael Bringmann a ÃcritÂ:
>> Correct overflow problem in calculation+display of Maximum Memory
>> value to syscfg where 32bits is insufficient.
>>
>> Signed-off-by: Michael Bringmann <mwb@xxxxxxxxxxxxx>
>> ---
>> Â arch/powerpc/platforms/pseries/lparcfg.c | 8 ++++----
>> Â 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c
>> index 4ee2594..183aeb7 100644
>> --- a/arch/powerpc/platforms/pseries/lparcfg.c
>> +++ b/arch/powerpc/platforms/pseries/lparcfg.c
>> @@ -435,12 +435,12 @@ static void parse_em_data(struct seq_file *m)
>>
>> Â static void maxmem_data(struct seq_file *m)
>> Â {
>> -ÂÂÂÂÂÂ unsigned long maxmem = 0;
>> +ÂÂÂÂÂÂ unsigned long long maxmem = 0;
>
> What about using u64 instead, for readability ?
Okay.
>
>>
>> -ÂÂÂÂÂÂ maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
>> -ÂÂÂÂÂÂ maxmem += hugetlb_total_pages() * PAGE_SIZE;
>> +ÂÂÂÂÂÂ maxmem += (unsigned long long)drmem_info->n_lmbs * (unsigned long long)drmem_info->lmb_size;
>
> This line is likely too long. You only need to cast one of the two operants to force a 64 bits multiply. And using u64 would shorten the line.
>
> Can both multiplications overflow ?
Yes.
>
> Christophe
>
>> +ÂÂÂÂÂÂ maxmem += (unsigned long long)hugetlb_total_pages() * (unsigned long long)PAGE_SIZE;
>>
>> -ÂÂÂÂÂÂ seq_printf(m, "MaxMem=%ld\n", maxmem);
>> +ÂÂÂÂÂÂ seq_printf(m, "MaxMem=%llu\n", maxmem);
>> Â }
>>
>> Â static int pseries_lparcfg_data(struct seq_file *m, void *v)
>>
>
Thanks.
--
Michael W. Bringmann
Linux Technology Center
IBM Corporation
Tie-Line 363-5196
External: (512) 286-5196
Cell: (512) 466-0650
mwb@xxxxxxxxxxxxx