Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp525018ybi; Fri, 7 Jun 2019 12:01:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQIjMO5SmHxsGE2085mRcI6WfrsKVuoxfmPaqaUks+g94Z6rNaFKZOXv1CQrl25zwvnggI X-Received: by 2002:a17:90a:480d:: with SMTP id a13mr7231273pjh.40.1559934106756; Fri, 07 Jun 2019 12:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559934106; cv=none; d=google.com; s=arc-20160816; b=YlYPsCBbJCSBJvIV7faS1jrPjmaZPUy10dW5d8+fOCctMYJemwa3KoJ5L81gyv4Ocq ufhlfkGA0GDMMYD5Ui3ugUOaRONV2gKFOGxfBWx7Q7XB7k288fZifSiMlQpGUToB16ge vKC8zIlzom0AAzp128T8D8kW9Uql/CFaRQk2amxUDXqCfqjEMUYZI55Er6bcIGBGJz+G vM1RgyZwbhWy3jbHx15r40I1V06KVo2c2NCsJyiYeztmLXBgpBPVK0Ur4CUVNRAjqHmn g/C3NLA7+LVntdImkSw01mxR5yMcRhtM16W7vrOxuPtKrb/dDQLHVwfYRtZ4wcN9sozg xS0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=mfjExvGDbVO3dPvtS5kHiM1tvI39gITxaUhxcKcPVsU=; b=pKf/CxdnW6nCmJEWMkE9EjCcdWrXVuz8jDo9OfDZPumyRQGW8XX/W6+VbTFv78x8ZQ ZyREo9tVMij1k/5z/0ET0sH2ny6jXFhL8Xt66Pkcnq3UG62h+x4tDNCSGBB2QArsX2aw 6d4rttYvs6tKIRgKmjEVS2VBzR5dAOSGWhUxgt0EXE0ZkTZjwD6mVnw7r4IuQKS/m5x8 rmnigwIfFeey9RjoOzbqX6Nd5r+V4xh9DTWjfxkKfzWbloLVTajdMLfETQ94YtnT5Cyc FN2DQ5PjsVyuFMperyKlqo+CDVTSmd2Ckm+7BVQ/KE0QMSArzoJVBdBLLT3a4bCIalkZ uhug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si2655375plt.101.2019.06.07.12.01.30; Fri, 07 Jun 2019 12:01:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731555AbfFGST2 (ORCPT + 99 others); Fri, 7 Jun 2019 14:19:28 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53227 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729817AbfFGST1 (ORCPT ); Fri, 7 Jun 2019 14:19:27 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hZJSS-0007zx-Mn; Fri, 07 Jun 2019 18:19:20 +0000 From: Colin King To: Jacob Keller , Jeff Kirsher , "David S . Miller" , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next][V2] ixgbe: fix potential u32 overflow on shift Date: Fri, 7 Jun 2019 19:19:20 +0100 Message-Id: <20190607181920.23339-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The u32 variable rem is being shifted using u32 arithmetic however it is being passed to div_u64 that expects the expression to be a u64. The 32 bit shift may potentially overflow, so cast rem to a u64 before shifting to avoid this. Also remove comment about overflow. Addresses-Coverity: ("Unintentional integer overflow") Fixes: cd4583206990 ("ixgbe: implement support for SDP/PPS output on X550 hardware") Fixes: 68d9676fc04e ("ixgbe: fix PTP SDP pin setup on X540 hardware") Signed-off-by: Colin Ian King --- V2: update comment --- drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c index 2c4d327fcc2e..0be13a90ff79 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c @@ -205,11 +205,8 @@ static void ixgbe_ptp_setup_sdp_X540(struct ixgbe_adapter *adapter) */ rem = (NS_PER_SEC - rem); - /* Adjust the clock edge to align with the next full second. This - * assumes that the cycle counter shift is small enough to avoid - * overflowing when shifting the remainder. - */ - clock_edge += div_u64((rem << cc->shift), cc->mult); + /* Adjust the clock edge to align with the next full second. */ + clock_edge += div_u64(((u64)rem << cc->shift), cc->mult); trgttiml = (u32)clock_edge; trgttimh = (u32)(clock_edge >> 32); @@ -291,11 +288,8 @@ static void ixgbe_ptp_setup_sdp_X550(struct ixgbe_adapter *adapter) */ rem = (NS_PER_SEC - rem); - /* Adjust the clock edge to align with the next full second. This - * assumes that the cycle counter shift is small enough to avoid - * overflowing when shifting the remainder. - */ - clock_edge += div_u64((rem << cc->shift), cc->mult); + /* Adjust the clock edge to align with the next full second. */ + clock_edge += div_u64(((u64)rem << cc->shift), cc->mult); /* X550 hardware stores the time in 32bits of 'billions of cycles' and * 32bits of 'cycles'. There's no guarantee that cycles represents -- 2.20.1