Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754125AbcDSMfF (ORCPT ); Tue, 19 Apr 2016 08:35:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42547 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753716AbcDSMfA (ORCPT ); Tue, 19 Apr 2016 08:35:00 -0400 From: Denys Vlasenko To: Jeff Kirsher Cc: Denys Vlasenko , Jesse Brandeburg , Shannon Nelson , Carolyn Wyborny , Don Skidmore , Bruce Allan , John Ronciak , Mitch Williams , "David S. Miller" , LKML , netdev@vger.kernel.org Subject: [PATCH 2/3] e1000e: e1000e_cyclecounter_read(): fix er32(SYSTIML) overflow check Date: Tue, 19 Apr 2016 14:34:45 +0200 Message-Id: <1461069286-31946-2-git-send-email-dvlasenk@redhat.com> In-Reply-To: <1461069286-31946-1-git-send-email-dvlasenk@redhat.com> References: <1461069286-31946-1-git-send-email-dvlasenk@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1712 Lines: 41 If two consecutive reads of the counter are the same, it is also not an overflow. "systimel_1 < systimel_2" should be "systimel_1 <= systimel_2". Before the patch, we could perform an *erroneous* correction: Let's say that systimel_1 == systimel_2 == 0xffffffff. "systimel_1 < systimel_2" is false, we think it's an overflow, we read "systimeh = er32(SYSTIMH)" which meanwhile had incremented, and use "(systimeh << 32) + systimel_2" value which is 2^32 too large. Signed-off-by: Denys Vlasenko CC: Jeff Kirsher CC: Jesse Brandeburg CC: Shannon Nelson CC: Carolyn Wyborny CC: Don Skidmore CC: Bruce Allan CC: John Ronciak CC: Mitch Williams CC: David S. Miller CC: LKML CC: netdev@vger.kernel.org --- drivers/net/ethernet/intel/e1000e/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c b/drivers/net/ethernet/intel/e1000e/netdev.c index 967311b..99d0e6e 100644 --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -4287,7 +4287,7 @@ static cycle_t e1000e_cyclecounter_read(const struct cyclecounter *cc) systimeh = er32(SYSTIMH); systimel_2 = er32(SYSTIML); /* Check for overflow. If there was no overflow, use the values */ - if (systimel_1 < systimel_2) { + if (systimel_1 <= systimel_2) { systim = (cycle_t)systimel_1; systim |= (cycle_t)systimeh << 32; } else { -- 1.8.1.4