From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161519AbbKFP2o (ORCPT ); Fri, 6 Nov 2015 10:28:44 -0500 Received: from smtp-out6.electric.net ([192.162.217.186]:50889 "EHLO smtp-out6.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbbKFP2m (ORCPT ); Fri, 6 Nov 2015 10:28:42 -0500 From: David Laight To: "'Linus Torvalds'" , Hannes Frederic Sowa CC: Andy Lutomirski , Benjamin Herrenschmidt , Andy Lutomirski , David Miller , Andrew Morton , "Network Development" , Linux Kernel Mailing List , Sasha Levin Subject: RE: [GIT] Networking Thread-Topic: [GIT] Networking Thread-Index: AQHRFnhhSFJg3DXI5Uy7wzsVPU+1wp6PH7+A Date: Fri, 6 Nov 2015 15:27:25 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1CBCD4A0@AcuExch.aculab.com> References: <20151027.233235.1641084823622810663.davem@davemloft.net> <5637C8DF.800@kernel.org> <1446512176.17404.30.camel@kernel.crashing.org> <1446555200.1870849.427743457.63139285@webmail.messagingengine.com> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-Outbound-IP: 213.249.233.130 X-Env-From: David.Laight@ACULAB.COM X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id tA6FSoqX028501 > From: Linus Torvalds > Sent: 03 November 2015 20:45 > On Tue, Nov 3, 2015 at 12:05 PM, Linus Torvalds > wrote: > > result = add_overflow( > > mul_overflow(sec, SEC_CONVERSION, &overflow), > > mul_overflow(nsec, NSEC_CONVERSION, &overflow), > > &overflow); > > > > return overflow ? MAX_JIFFIES : result; > > Thinking more about this example, I think the gcc interface for > multiplication overflow is fine. > > It would end up something like > > if (mul_overflow(sec, SEC_CONVERSION, &sec)) > return MAX_JIFFY_OFFSET; > if (mul_overflow(nsec, NSEC_CONVERSION, &nsec)) > return MAX_JIFFY_OFFSET; > sum = sec + nsec; > if (sum < sec || sum > MAX_JIFFY_OFFSET) > return MAX_JIFFY_OFFSET; > return sum; > > and that doesn't look horribly ugly to me. If mul_overflow() is a real function you've just forced some of the values out to memory, generating a 'clobber' for all memory (unless 'strict-aliasing' is enabled) and making a mess of other optimisations. (If it is a static inline that might not happen.) If you assume that no one is stupid enough to multiply very large values by 1 and not get an error you could have mul_overflow() return the largest prime if the multiply overflowed. David {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I