From patchwork Thu Oct 31 15:10:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 287514 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id A5E302C0393 for ; Fri, 1 Nov 2013 02:10:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755164Ab3JaPKo (ORCPT ); Thu, 31 Oct 2013 11:10:44 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:54653 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755052Ab3JaPKn (ORCPT ); Thu, 31 Oct 2013 11:10:43 -0400 Received: by mail-pa0-f47.google.com with SMTP id lf10so2644687pab.34 for ; Thu, 31 Oct 2013 08:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-type:content-transfer-encoding:mime-version; bh=8o9w2MHE9qg5efnBlVJWX+zmDQW4Vy1tiN+0N9EQTe4=; b=Zjokq9F3L4Mi7Ep1NvkOmssG2m262AK1b9oPMZ1tk6Grf4owJRM8oN3P/SZO1XNyHH 0ET0OdE6Fwsn8IFQshxgWwxkKSqTmi4k7YJEdSLJTuaRUCl/enUO6OfxbGzRJx+k+c33 g5SC8qEK9y+YCyjPlpez+BjPYux8sRLv+N9KreaqbW+eg5wgHv4c9qTlVDqA7f1Q5Pv3 SrLb47jtRfF1e5rhNMb7uz777InYDZ5HFDogB4htPOLE5sdcfiS48f5LNHVjQCGNurB3 hbgQ029dw5LDpzknmIPZTexue/bQNw4mIdo/f/+k1n9stKjzAFD4UFgwDpT81SQ/fW7g fX3w== X-Received: by 10.67.14.231 with SMTP id fj7mr2455755pad.115.1383232243244; Thu, 31 Oct 2013 08:10:43 -0700 (PDT) Received: from [172.26.48.183] ([172.26.48.183]) by mx.google.com with ESMTPSA id sg1sm4782765pbb.16.2013.10.31.08.10.41 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Thu, 31 Oct 2013 08:10:42 -0700 (PDT) Message-ID: <1383232241.4857.73.camel@edumazet-glaptop.roam.corp.google.com> Subject: Re: [net-next PATCH] net: codel: Avoid undefined behavior from signed overflow From: Eric Dumazet To: Jesper Dangaard Brouer Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, "Paul E. McKenney" , Dave Taht Date: Thu, 31 Oct 2013 08:10:41 -0700 In-Reply-To: <20131031151551.675ab908@redhat.com> References: <20131030172341.19203.93490.stgit@dragon> <1383156104.4857.49.camel@edumazet-glaptop.roam.corp.google.com> <20131031151551.675ab908@redhat.com> X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, 2013-10-31 at 15:15 +0100, Jesper Dangaard Brouer wrote: > Okay, I'll cook up another patch, after work. > > Adding all the typecheck() stuff, just bloats the code. > > Would it be better/okay just to do?: > (s32)((u32)(a) - (u32)(b)) > 0) > > What about using the existing codel types ? You need of course something similar for all variants. --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/net/codel.h b/include/net/codel.h index 389cf62..89a7781 100644 --- a/include/net/codel.h +++ b/include/net/codel.h @@ -72,7 +72,12 @@ static inline codel_time_t codel_get_time(void) return ns >> CODEL_SHIFT; } -#define codel_time_after(a, b) ((s32)(a) - (s32)(b) > 0) +static inline bool codel_time_after(codel_time_t a, codel_time_t b) +{ + codel_tdiff_t delta = a - b; + + return delta >= 0; +} #define codel_time_after_eq(a, b) ((s32)(a) - (s32)(b) >= 0) #define codel_time_before(a, b) ((s32)(a) - (s32)(b) < 0) #define codel_time_before_eq(a, b) ((s32)(a) - (s32)(b) <= 0)