Commit 2aab4e18 authored by Thomas Petazzoni's avatar Thomas Petazzoni Committed by Vinod Koul

dmaengine: mv_xor_v2: properly handle wrapping in the array of HW descriptors

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: 19a340b1 ("dmaengine: mv_xor_v2: new driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
parent eb8df543
...@@ -560,7 +560,6 @@ static void mv_xor_v2_tasklet(unsigned long data) ...@@ -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; struct mv_xor_v2_device *xor_dev = (struct mv_xor_v2_device *) data;
int pending_ptr, num_of_pending, i; 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; struct mv_xor_v2_sw_desc *next_pending_sw_desc = NULL;
dev_dbg(xor_dev->dmadev.dev, "%s %d\n", __func__, __LINE__); dev_dbg(xor_dev->dmadev.dev, "%s %d\n", __func__, __LINE__);
...@@ -568,17 +567,10 @@ static void mv_xor_v2_tasklet(unsigned long data) ...@@ -568,17 +567,10 @@ static void mv_xor_v2_tasklet(unsigned long data)
/* get the pending descriptors parameters */ /* get the pending descriptors parameters */
num_of_pending = mv_xor_v2_get_pending_params(xor_dev, &pending_ptr); 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 */ /* loop over free descriptors */
for (i = 0; i < num_of_pending; i++) { for (i = 0; i < num_of_pending; i++) {
struct mv_xor_v2_descriptor *next_pending_hw_desc =
if (pending_ptr > MV_XOR_V2_DESC_NUM) xor_dev->hw_desq_virt + pending_ptr;
pending_ptr = 0;
if (next_pending_sw_desc != NULL)
next_pending_hw_desc++;
/* get the SW descriptor related to the HW descriptor */ /* get the SW descriptor related to the HW descriptor */
next_pending_sw_desc = next_pending_sw_desc =
...@@ -614,6 +606,8 @@ static void mv_xor_v2_tasklet(unsigned long data) ...@@ -614,6 +606,8 @@ static void mv_xor_v2_tasklet(unsigned long data)
/* increment the next descriptor */ /* increment the next descriptor */
pending_ptr++; pending_ptr++;
if (pending_ptr >= MV_XOR_V2_DESC_NUM)
pending_ptr = 0;
} }
if (num_of_pending != 0) { if (num_of_pending != 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment