From owner-svn-src-all@freebsd.org Sun Oct 9 04:29:44 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1298CC076A4; Sun, 9 Oct 2016 04:29:44 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C7A89FE7; Sun, 9 Oct 2016 04:29:43 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u994TgPY031695; Sun, 9 Oct 2016 04:29:42 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u994TgoR031694; Sun, 9 Oct 2016 04:29:42 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <201610090429.u994TgoR031694@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Sun, 9 Oct 2016 04:29:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306897 - head/sys/arm/nvidia X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Oct 2016 04:29:44 -0000 Author: gonzo Date: Sun Oct 9 04:29:42 2016 New Revision: 306897 URL: https://svnweb.freebsd.org/changeset/base/306897 Log: Fix MSI allocation for NVidia Tegra - Fix range check - Due to checking found value in for(;;) condition irq after loop was always + 1 from actually found slot and wrong entry was marked as used which lead to returning slot 0 for all requests. Modified: head/sys/arm/nvidia/tegra_pcie.c Modified: head/sys/arm/nvidia/tegra_pcie.c ============================================================================== --- head/sys/arm/nvidia/tegra_pcie.c Sun Oct 9 03:20:58 2016 (r306896) +++ head/sys/arm/nvidia/tegra_pcie.c Sun Oct 9 04:29:42 2016 (r306897) @@ -710,7 +710,7 @@ tegra_pcib_msi_alloc_msi(device_t dev, d mtx_lock(&sc->mtx); found = false; - for (irq = 0; irq < TEGRA_PCIB_MAX_MSI && !found; irq++) { + for (irq = 0; (irq + count - 1) < TEGRA_PCIB_MAX_MSI; irq++) { /* Start on an aligned interrupt */ if ((irq & (maxcount - 1)) != 0) continue; @@ -719,20 +719,17 @@ tegra_pcib_msi_alloc_msi(device_t dev, d found = true; /* Check this range is valid */ - for (end_irq = irq; end_irq != irq + count - 1; end_irq++) { - /* No free interrupts */ - if (end_irq == (TEGRA_PCIB_MAX_MSI - 1)) { - found = false; - break; - } - + for (end_irq = irq; end_irq < irq + count; end_irq++) { /* This is already used */ - if ((sc->isrcs[irq].flags & TEGRA_FLAG_MSI_USED) == + if ((sc->isrcs[end_irq].flags & TEGRA_FLAG_MSI_USED) == TEGRA_FLAG_MSI_USED) { found = false; break; } } + + if (found) + break; } /* Not enough interrupts were found */