Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755875AbYLJK30 (ORCPT ); Wed, 10 Dec 2008 05:29:26 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754804AbYLJK3S (ORCPT ); Wed, 10 Dec 2008 05:29:18 -0500 Received: from ocean.emcraft.com ([213.221.7.182]:38002 "EHLO ocean.emcraft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754706AbYLJK3S convert rfc822-to-8bit (ORCPT ); Wed, 10 Dec 2008 05:29:18 -0500 Date: Wed, 10 Dec 2008 13:29:12 +0300 From: Yuri Tikhonov Organization: EmCraft X-Priority: 3 (Normal) Message-ID: <1795455197.20081210132912@emcraft.com> To: Al Viro CC: Geert Uytterhoeven , , , Detlev Zundel , Wolfgang Denk , Milton Miller , Ilya Yanok Subject: Re[2]: [PATCH] fork_init: fix division by zero In-Reply-To: <20081210101745.GG28946@ZenIV.linux.org.uk> References: <200812092044.40649.yur@emcraft.com> <503391615.20081210130113@emcraft.com> <20081210101745.GG28946@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1521 Lines: 53 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/