From: Yuri Tikhonov <yur@emcraft.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>,
<linux-kernel@vger.kernel.org>, <linuxppc-dev@ozlabs.org>,
Detlev Zundel <dzu@denx.de>, Wolfgang Denk <wd@denx.de>,
Milton Miller <miltonm@bga.com>, Ilya Yanok <yanok@emcraft.com>
Subject: Re[2]: [PATCH] fork_init: fix division by zero
Date: Wed, 10 Dec 2008 13:29:12 +0300 [thread overview]
Message-ID: <1795455197.20081210132912@emcraft.com> (raw)
In-Reply-To: <20081210101745.GG28946@ZenIV.linux.org.uk>
Hello Al,
On Wednesday, December 10, 2008 you wrote:
> On Wed, Dec 10, 2008 at 01:01:13PM +0300, Yuri Tikhonov wrote:
>> >> + max_threads = mempages * PAGE_SIZE / (8 * THREAD_SIZE);
>> > ^^^^^^^^^^^^^^^^^^^^
>> >> +#endif
>>
>> > Can't this overflow, e.g. on 32-bit machines with HIGHMEM?
>>
>> The multiplier here is not PAGE_SIZE, but [PAGE_SIZE / (8 *
>> THREAD_SIZE)], and this value is expected to be rather small (2, 4, or
>> so).
> x * y / z is parsed as (x * y) / z, not x * (y / z).
Here we believe in preprocessor: since all PAGE_SIZE, 8, and
THREAD_SIZE are the constants we expect it will calculate this.
E.g. here is the result from this line as produced by cross-gcc
4.2.2:
lis r9,0
rlwinm r29,r29,2,16,29
stw r29,0(r9)
As you see - only rotate-left, i.e. multiplication to the constant.
In any case, adding braces as follows probably would be better:
+ max_threads = mempages * (PAGE_SIZE / (8 * THREAD_SIZE));
Right ?
> Only assignment operators (and ?:, in a sense that a ? b : c ? d : e is
> parsed as a ? b : (c ? d : e)) are right-to-left. The rest is left-to-right.
Regards, Yuri
--
Yuri Tikhonov, Senior Software Engineer
Emcraft Systems, www.emcraft.com
next prev parent reply other threads:[~2008-12-10 10:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-09 17:44 [PATCH] fork_init: fix division by zero Yuri Tikhonov
2008-12-10 8:44 ` Geert Uytterhoeven
2008-12-10 10:01 ` Re[2]: " Yuri Tikhonov
2008-12-10 10:17 ` Al Viro
2008-12-10 10:29 ` Yuri Tikhonov [this message]
2008-12-10 13:06 ` Re[2]: " David Howells
2008-12-10 13:09 ` David Howells
2008-12-10 13:15 ` Geert Uytterhoeven
2008-12-10 13:25 ` Re[4]: " Yuri Tikhonov
2008-12-10 21:50 ` Re[2]: " Paul Mackerras
2008-12-10 17:25 ` Scott Wood
2008-12-10 17:56 ` Re[2]: " Yuri Tikhonov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1795455197.20081210132912@emcraft.com \
--to=yur@emcraft.com \
--cc=Geert.Uytterhoeven@sonycom.com \
--cc=dzu@denx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=miltonm@bga.com \
--cc=viro@ZenIV.linux.org.uk \
--cc=wd@denx.de \
--cc=yanok@emcraft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox