Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5142929imm; Sun, 22 Jul 2018 14:22:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf4JijsRM8imCiwJVsfNUaFgIy6gAJESX13SGaHbWjR3obdCoGbPdyjFBqU1Qg0y8om2Xd9 X-Received: by 2002:a63:ed56:: with SMTP id m22-v6mr9808854pgk.148.1532294532966; Sun, 22 Jul 2018 14:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532294532; cv=none; d=google.com; s=arc-20160816; b=tAHTPPum/m3yR2CnLshh00EzPKCTLUyW6XJ6LRIldy56fnt86LTMW9zBCtvTbGB+ff +oG/E6Tm2uB7N8sS9eH+GbiPEBJfgmL9UYNpUZGMqK9NOpojpz9pd6U86WT5/RbdSz6H /JkjQa3+n7Yl/Ak01TWq/akai4mQvGbuJZz8h7J/gEJYuyk7Ay+m7YqFILytDHLmdMfb OyNv2GgIb4V8pZXPqe/ssHdc462JRRIbOdh0CNTQ6+cp/ZJaiVPnuT3loW9oge10lyYT XXiERg/bx6iBnR8nulkXNIlCd6+JT+viK5Teevi0BEDGCYQW8fu4BJc5B46oDf9LXRXv 0jTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=l+D7DaE2CqZ26AYpsTQra/AI+RpmCkOh/xNip0yizVM=; b=t3M9bc7vTz3juCNA8lnaGBPt1JCaDYaDnsEF1FVfv/tn65MzNhmHu/p0YeUCxuNgqj DIdViG5pHTtnQTRo6lGPMoTNnk4kcvzpodQ/HW4kUugXgQjxO9SuXXo6iHRl6DAx1LU0 Z0uUrBbybuE9Zo/Cxt7jYjsuU+D6gSy/JfjsFFwEA8zcNYcLRllyItlEeFgNaE/oWhiJ 3n7SYrFB/8ZCb3DMs7mpXUH692lAwDDoWipoovT8pKB2yLL8TgxXfarwe4WOaFeAEl8n qvsTffJ1QmzjwKtHokRfdgU58tegY+mXODz2VAeSUz+m0hLJsHgbaSJ+R1Q7maa2XohU cpvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d128-v6si7163394pfc.211.2018.07.22.14.21.58; Sun, 22 Jul 2018 14:22:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387813AbeGVWSZ (ORCPT + 99 others); Sun, 22 Jul 2018 18:18:25 -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=20F=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=20F=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.16.4