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: 142518 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5356992ljj; Sun, 22 Jul 2018 14:20:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpffHuPeB6UFJhz8CCLRIcQvxhDZCebut0+ANDl3zJGFjxQTAW98shddZBdSU8Ct/YRJcUjf X-Received: by 2002:a62:5ec3:: with SMTP id s186-v6mr10680427pfb.129.1532294454372; Sun, 22 Jul 2018 14:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532294454; cv=none; d=google.com; s=arc-20160816; b=MBgvVg5jLfXeTqpq0M0Qs4I88FLgFbXTqGS2n8TpHJzg3hXHChLVPaIcO+nDVgL9B6 0sP/aflthql+F3ya1jfgHvGCKEnLoddjEy4cus3Cx0T2F/3Ud/ZFNFxgS2FWFoVJ5zDW YBKVwsnJCfyIhEVOHqO4qkKFsAcLP2jOt62ZSe9fTJyqMTma6ucQ6xkCJ4cLRsjIOjRP SfFaTCbY8CmNNZeHkgiYJpmFxcq9jJXhznIGQnfKtpvzezmPY8jH5swCXtm4Kes49x6Y I77sQh3X2T00FT1O1GhIsWzykuRg/WHKElQhNPuIVdPmB+EZ9jzWwjMH8bwYFDLLCOr1 GfOw== 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 d2-v6si6672675plh.387.2018.07.22.14.20.54; Sun, 22 Jul 2018 14:20:54 -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 S2387817AbeGVWSZ (ORCPT + 31 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_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=A4?= =?utf-8?q?rber?= , 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: 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(-) -- 2.16.4 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);