From patchwork Fri Oct 14 14:20:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denys Vlasenko X-Patchwork-Id: 9376907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A80160779 for ; Fri, 14 Oct 2016 14:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C98A209CD for ; Fri, 14 Oct 2016 14:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 114FC2A70F; Fri, 14 Oct 2016 14:20:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FFCE209CD for ; Fri, 14 Oct 2016 14:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754900AbcJNOUG (ORCPT ); Fri, 14 Oct 2016 10:20:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57208 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754307AbcJNOUF (ORCPT ); Fri, 14 Oct 2016 10:20:05 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBD2031B30B; Fri, 14 Oct 2016 14:20:04 +0000 (UTC) Received: from localhost.localdomain (dhcp-1-129.brq.redhat.com [10.34.1.129]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9EEK3HU027253; Fri, 14 Oct 2016 10:20:03 -0400 From: Denys Vlasenko To: James Bottomley Cc: Denys Vlasenko , Hannes Reinicke , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: aic7xxx: fix ahc_delay and ahd_delay Date: Fri, 14 Oct 2016 16:20:00 +0200 Message-Id: <20161014142000.18833-1-dvlasenk@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 14 Oct 2016 14:20:05 +0000 (UTC) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP They are buggy: while (usec > 0) udelay(usec % 1024); usec -= 1024; For example, for usec = 100*1024 + 1, old code will udelay(1) 101 times, i.e. it will be approximately equivalent to udelay(101), not the expected udelay(102400). This did not bite because all callers use values far from "pathological" ones, such as 500 and 1000 - these work fine with buggy code. This was reported in 2006 but was missed. Signed-off-by: Denys Vlasenko CC: James Bottomley CC: Hannes Reinicke CC: linux-scsi@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/scsi/aic7xxx/aic79xx_osm.c | 7 ++++--- drivers/scsi/aic7xxx/aic7xxx_osm.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c index 2588b8f..e7a7838 100644 --- a/drivers/scsi/aic7xxx/aic79xx_osm.c +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c @@ -380,9 +380,10 @@ ahd_delay(long usec) * multi-millisecond waits. Wait at most * 1024us per call. */ - while (usec > 0) { - udelay(usec % 1024); - usec -= 1024; + udelay(usec & 1023); + usec >>= 10; + while (--usec >= 0) { + udelay(1024); } } diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c index fc6a831..c81798e 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_osm.c +++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c @@ -388,9 +388,10 @@ ahc_delay(long usec) * multi-millisecond waits. Wait at most * 1024us per call. */ - while (usec > 0) { - udelay(usec % 1024); - usec -= 1024; + udelay(usec & 1023); + usec >>= 10; + while (--usec >= 0) { + udelay(1024); } }