lkml.org 
[lkml]   [2015]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/1] kernel/fork.c: avoid division by zero
I am resending this mail because the linux-kernel list was not CCed.

On 16.02.2015 19:23, Guenter Roeck wrote:
> On Mon, Feb 16, 2015 at 07:00:44PM +0100, Heinrich Schuchardt wrote:
>> PAGE_SIZE is not guaranteed to be equal to or less than 8 times the
>> THREAD_SIZE.
>>
>> E.g. architecture hexagon may have page size 1M and thread size 4096.
>>
>> This would lead to a division by zero.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>> kernel/fork.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/fork.c b/kernel/fork.c
>> index cf65139..71e2583 100644
>> --- a/kernel/fork.c
>> +++ b/kernel/fork.c
>> @@ -273,7 +273,8 @@ void __init fork_init(unsigned long mempages)
>> * value: the thread structures can take up at most half
>> * of memory.
>> */
>> - max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
>> + max_threads = (u64) PAGE_SIZE * (u64) mempages
>> + / (u64) THREAD_SIZE / 8UL;
>
> How about
> max_threads = mempages / (8 * THREAD_SIZE) * PAGE_SIZE;
>
> instead ? That would avoid the u64.

We have to consider the case mempages < 8 * THREAD_SIZE.

Let
mempages = 1024
THREAD_SIZE = 4096
PAGE_SIZE = 1M

Your code gives 0.
Mine gives 8192.

Best regards

Heinrich




\
 
 \ /
  Last update: 2015-02-16 20:21    [W:0.533 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site