From patchwork Sun Jul 22 21:20:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 10539425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F5B914BC for ; Sun, 22 Jul 2018 21:20:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CE5A2843B for ; Sun, 22 Jul 2018 21:20:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3096428449; Sun, 22 Jul 2018 21:20:58 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 CCC592843B for ; Sun, 22 Jul 2018 21:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387796AbeGVWSY (ORCPT ); Sun, 22 Jul 2018 18:18:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:38830 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387732AbeGVWSY (ORCPT ); Sun, 22 Jul 2018 18:18:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2715DAFCE; Sun, 22 Jul 2018 21:20:22 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: linux-mips@linux-mips.org Cc: Ralf Baechle , Paul Burton , James Hogan , linux-kernel@vger.kernel.org, Damien Horsley , =?utf-8?q?Andreas_F=C3=A4rber?= , Vinod Koul , Dan Williams , dmaengine@vger.kernel.org Subject: [PATCH 09/15] dmaengine: img-mdc: Handle early status read Date: Sun, 22 Jul 2018 23:20:04 +0200 Message-Id: <20180722212010.3979-10-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180722212010.3979-1-afaerber@suse.de> References: <20180722212010.3979-1-afaerber@suse.de> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Damien Horsley It is possible that mdc_tx_status may be called before the first node has been read from memory. In this case, the residue value stored in the register is undefined. Return the transfer size instead. Signed-off-by: Damien Horsley Signed-off-by: Andreas Färber --- drivers/dma/img-mdc-dma.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/dma/img-mdc-dma.c b/drivers/dma/img-mdc-dma.c index 25cec9c243e1..0f2f0f52d83a 100644 --- a/drivers/dma/img-mdc-dma.c +++ b/drivers/dma/img-mdc-dma.c @@ -621,25 +621,33 @@ static enum dma_status mdc_tx_status(struct dma_chan *chan, (MDC_CMDS_PROCESSED_CMDS_DONE_MASK + 1); /* - * If the command loaded event hasn't been processed yet, then - * the difference above includes an extra command. + * If the first node has not yet been read from memory, + * the residue register value is undefined */ - if (!mdesc->cmd_loaded) - cmds--; - else - cmds += mdesc->list_cmds_done; - - bytes = mdesc->list_xfer_size; - ldesc = mdesc->list; - for (i = 0; i < cmds; i++) { - bytes -= ldesc->xfer_size + 1; - ldesc = ldesc->next_desc; - } - if (ldesc) { - if (residue != MDC_TRANSFER_SIZE_MASK) - bytes -= ldesc->xfer_size - residue; + if (!mdesc->cmd_loaded && !cmds) { + bytes = mdesc->list_xfer_size; + } else { + /* + * If the command loaded event hasn't been processed yet, then + * the difference above includes an extra command. + */ + if (!mdesc->cmd_loaded) + cmds--; else + cmds += mdesc->list_cmds_done; + + bytes = mdesc->list_xfer_size; + ldesc = mdesc->list; + for (i = 0; i < cmds; i++) { bytes -= ldesc->xfer_size + 1; + ldesc = ldesc->next_desc; + } + if (ldesc) { + if (residue != MDC_TRANSFER_SIZE_MASK) + bytes -= ldesc->xfer_size - residue; + else + bytes -= ldesc->xfer_size + 1; + } } } spin_unlock_irqrestore(&mchan->vc.lock, flags);