linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix display of Maximum Memory
@ 2020-01-14 21:07 Michael Bringmann
  2020-01-15  5:41 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Bringmann @ 2020-01-14 21:07 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel
  Cc: Michael Ellerman, Gustavo Walbon, Paul Mackerras

Correct overflow problem in calculation+display of Maximum Memory
value to syscfg where 32bits is insufficient.

Signed-off-by: Michael Bringmann <mwb@linux.ibm.com>
---
 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;

-       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;
+       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)
-- 
1.8.3.1

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

* Re: [PATCH] Fix display of Maximum Memory
  2020-01-14 21:07 [PATCH] Fix display of Maximum Memory Michael Bringmann
@ 2020-01-15  5:41 ` Christophe Leroy
  2020-01-15 14:30   ` Michael Bringmann
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2020-01-15  5:41 UTC (permalink / raw)
  To: Michael Bringmann, linuxppc-dev, linux-kernel
  Cc: Gustavo Walbon, Paul Mackerras



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@linux.ibm.com>
> ---
>   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 ?

> 
> -       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 ?

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)
> 

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

* Re: [PATCH] Fix display of Maximum Memory
  2020-01-15  5:41 ` Christophe Leroy
@ 2020-01-15 14:30   ` Michael Bringmann
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Bringmann @ 2020-01-15 14:30 UTC (permalink / raw)
  To: Christophe Leroy, linuxppc-dev, linux-kernel
  Cc: Gustavo Walbon, Paul Mackerras

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@linux.ibm.com>
>> ---
>>   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@linux.ibm.com

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

end of thread, other threads:[~2020-01-15 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 21:07 [PATCH] Fix display of Maximum Memory Michael Bringmann
2020-01-15  5:41 ` Christophe Leroy
2020-01-15 14:30   ` Michael Bringmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).