From patchwork Fri May 5 09:57:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 9713401 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 F345D60362 for ; Fri, 5 May 2017 10:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF0ED26E54 for ; Fri, 5 May 2017 10:54:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D40F62869A; Fri, 5 May 2017 10:54:48 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6755526E54 for ; Fri, 5 May 2017 10:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TtfQt08tgHCbJs9PPQQ6E3t4+B68mI3oGwrKdGCGqGY=; b=nJD7eScBuFmoxjctL9rEMlzYIK KJV0u1X1pjJjtlEP5+wxJ5GvjJoK6liNwB7bg02Mgarwd96X2dHhVHYLj8GaaoIEDcozmH1M4R/kk uJx8MmsaWHmpYLb1pHAXQybE051FMW4YWYZqzI87yBKbSVCjWV1W0KqYnfaMCBT0YjoglNqnb0CWv WeQryKQcvuJsUiPQYAlagAu/r42g7QOTbz8WEas5Za6bVpokdqNm0qjkQDGxsSsT5cPB+seuukgP4 BoLDJR/HcOv7z+yVoy+/8kFQxpuCHsDPl1mLz2VHOL/Vhb0nvrzXI2f/rHXrvUgJbj1a2ypSptJiO jrgOmJAA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d6asp-0005b0-72; Fri, 05 May 2017 10:54:47 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d6asO-0004pM-Hl for linux-arm-kernel@bombadil.infradead.org; Fri, 05 May 2017 10:54:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iP7fDYSw7CbNgvYX7x+an/OwrAxfvX+rRWwu2fgnP0c=; b=J79USp7kfp+xhnojJzRsHLE3m y0/9qGPELka/jzYpPSHdx60sCBoJqFUPCe8cvXWmLajUwrZGIptGIRD/VH1fObUICbWlE17w8Xgxe QWfpQCp9eTkmjaYFas6a7TowDPJIEnsoU2RPQ2XRxZMS/J8QZk1CPrsrmnhKKpunqUMS3y7TP9wBj db+UBWQdkJvhkk06kpcQOX0cu4UJPxbe9t6rRCqTwO7MN6RcSTwmIx6Wp5+U2gtzLkd05oFofU/Fq Y34i8i9FNn35O9SaXpWSH21T44Kl4six8hamoR61W+u5XReFM6rMhHiyyWKtJBQan+vVxlz4v/qKy g47FsAT3Q==; Received: from mail.free-electrons.com ([62.4.15.54]) by merlin.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d6a0d-0003AE-9g for linux-arm-kernel@lists.infradead.org; Fri, 05 May 2017 09:58:47 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 2F8D1212E7; Fri, 5 May 2017 11:57:57 +0200 (CEST) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0A76A206EF; Fri, 5 May 2017 11:57:57 +0200 (CEST) From: Thomas Petazzoni To: Vinod Koul , dmaengine@vger.kernel.org Subject: [PATCH 02/10] dma: mv_xor_v2: properly handle wrapping in the array of HW descriptors Date: Fri, 5 May 2017 11:57:45 +0200 Message-Id: <1493978274-12805-3-git-send-email-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493978274-12805-1-git-send-email-thomas.petazzoni@free-electrons.com> References: <1493978274-12805-1-git-send-email-thomas.petazzoni@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170505_055847_522744_E696C7F9 X-CRM114-Status: GOOD ( 13.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Andrew Lunn , Yehuda Yitschak , Jason Cooper , Hanna Hawa , stable@vger.kernel.org, Nadav Haklai , Gregory Clement , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP mv_xor_v2_tasklet() is looping over completed HW descriptors. Before the loop, it initializes 'next_pending_hw_desc' to the first HW descriptor to handle, and then the loop simply increments this point, without taking care of wrapping when we reach the last HW descriptor. The 'pending_ptr' index was being wrapped back to 0 at the end, but it wasn't used in each iteration of the loop to calculate next_pending_hw_desc. This commit fixes that, and makes next_pending_hw_desc a variable local to the loop itself. Fixes: 19a340b1a820 ("dmaengine: mv_xor_v2: new driver") Cc: Signed-off-by: Thomas Petazzoni --- drivers/dma/mv_xor_v2.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/dma/mv_xor_v2.c b/drivers/dma/mv_xor_v2.c index e928020..bdfb36e 100644 --- a/drivers/dma/mv_xor_v2.c +++ b/drivers/dma/mv_xor_v2.c @@ -560,7 +560,6 @@ static void mv_xor_v2_tasklet(unsigned long data) { struct mv_xor_v2_device *xor_dev = (struct mv_xor_v2_device *) data; int pending_ptr, num_of_pending, i; - struct mv_xor_v2_descriptor *next_pending_hw_desc = NULL; struct mv_xor_v2_sw_desc *next_pending_sw_desc = NULL; dev_dbg(xor_dev->dmadev.dev, "%s %d\n", __func__, __LINE__); @@ -568,17 +567,10 @@ static void mv_xor_v2_tasklet(unsigned long data) /* get the pending descriptors parameters */ num_of_pending = mv_xor_v2_get_pending_params(xor_dev, &pending_ptr); - /* next HW descriptor */ - next_pending_hw_desc = xor_dev->hw_desq_virt + pending_ptr; - /* loop over free descriptors */ for (i = 0; i < num_of_pending; i++) { - - if (pending_ptr > MV_XOR_V2_DESC_NUM) - pending_ptr = 0; - - if (next_pending_sw_desc != NULL) - next_pending_hw_desc++; + struct mv_xor_v2_descriptor *next_pending_hw_desc = + xor_dev->hw_desq_virt + pending_ptr; /* get the SW descriptor related to the HW descriptor */ next_pending_sw_desc = @@ -614,6 +606,8 @@ static void mv_xor_v2_tasklet(unsigned long data) /* increment the next descriptor */ pending_ptr++; + if (pending_ptr >= MV_XOR_V2_DESC_NUM) + pending_ptr = 0; } if (num_of_pending != 0) {