Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1021693yba; Thu, 4 Apr 2019 02:37:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzR56VjeChFtudOW1XuKU0TygPCtICCwcBwaLMN01933zHJOIau6V7N2az1SCjOXoEIP2ds X-Received: by 2002:a62:1d90:: with SMTP id d138mr4691266pfd.232.1554370625671; Thu, 04 Apr 2019 02:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370625; cv=none; d=google.com; s=arc-20160816; b=rCJ4rZ/hb9Yml8ueYKHnJvfjbjuEXzf7wEmrYcQSEvxNvFoCWseswMdsZ3IkkSzKPt TEdoSTOMJqUrtz/Yz/PHiF9N/Fn/Qj4sxoFb0lwNenpqWEVXV4IFoueT3Ti7JFD2KmcA 1YzrjTRVM+Ve6rVTJcc5X1oA5JBCUZgIexPmHJtlZt7s3BumpnFpLC7iuRuienw4e/cC f3vQmukcy2FwF+T7A97jObbvq1cYTLDsXimhN5gDvGhvw4fJI3PHzIxdT6ms2/zOlG2k x7tmD3A5HM+qsaD9thrg7ku9QAYE7StEWM4uO85OAPSFvV+B+k86NHXrdTo6wiMvdX0U MYhg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Rqvg18lxAfB9hxqXtAvafi9fT6uuFybTy/IWPwn5J+A=; b=tVPnEO80oqG/CrQOQeWCKWoAV5GjtT+8P0M5kDKgqlrLLpb6CRKiWzqMSlSdK+fSC1 xa0cdbn96oynF6bxIZHby9i6z43U9MaXnpMfu0fkAZXOcki8s6R9YjzgDjTx6Dy36fkA plF1WziEIJd/iUWZNj1ChwoYmCnc+NaYUW1II5tFY7IgKOwjfkElYjxO9rqsYUa1RXyY WXXFVAEe6JdLeIfQCRQoWwD3kR8+cv84HdCB5FwDB4+QJXecg4zpBIttx/hWhqkGITH3 PkINbYp5Ru/PS05vXpkKMIDobt6JlVaACACs7DcdSeLR6vXmsPvCppLxSaavsNrwV3Of qLow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GRpjIg12; 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 h185si15504062pfc.241.2019.04.04.02.36.50; Thu, 04 Apr 2019 02:37:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GRpjIg12; 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 S1732500AbfDDJHX (ORCPT + 99 others); Thu, 4 Apr 2019 05:07:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:46120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732485AbfDDJHU (ORCPT ); Thu, 4 Apr 2019 05:07:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4E252183E; Thu, 4 Apr 2019 09:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368839; bh=/n3CilU3J04TV2dZ6/tGDdZ2xh1ITRtX9ypyEVjD3PY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GRpjIg12+cNBipXW5BTlgV86YwWCKaG1gLoWHzoHcaO4ga5Qr8Lc6koRAbhNUOvNB eRhgK4XkI//0emUlkskbBrFR9IPZGg/O5UTyaiyNtZ4MMHIJq73SFeVt8Pa5u6opnI 2z7ZjY1XK3Mm/dI6N17UgIFGajxrOWdPQOdlBHQM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Osipenko , Ben Dooks , Jon Hunter , Vinod Koul , Sasha Levin Subject: [PATCH 4.19 181/187] dmaengine: tegra: avoid overflow of byte tracking Date: Thu, 4 Apr 2019 10:48:38 +0200 Message-Id: <20190404084611.652835657@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit e486df39305864604b7e25f2a95d51039517ac57 ] The dma_desc->bytes_transferred counter tracks the number of bytes moved by the DMA channel. This is then used to calculate the information passed back in the in the tegra_dma_tx_status callback, which is usually fine. When the DMA channel is configured as continous, then the bytes_transferred counter will increase over time and eventually overflow to become negative so the residue count will become invalid and the ALSA sound-dma code will report invalid hardware pointer values to the application. This results in some users becoming confused about the playout position and putting audio data in the wrong place. To fix this issue, always ensure the bytes_transferred field is modulo the size of the request. We only do this for the case of the cyclic transfer done ISR as anyone attempting to move 2GiB of DMA data in one transfer is unlikely. Note, we don't fix the issue that we should /never/ transfer a negative number of bytes so we could make those fields unsigned. Reviewed-by: Dmitry Osipenko Signed-off-by: Ben Dooks Acked-by: Jon Hunter Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/tegra20-apb-dma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 9a558e30c461..8219ab88a507 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -636,7 +636,10 @@ static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc, sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node); dma_desc = sgreq->dma_desc; - dma_desc->bytes_transferred += sgreq->req_len; + /* if we dma for long enough the transfer count will wrap */ + dma_desc->bytes_transferred = + (dma_desc->bytes_transferred + sgreq->req_len) % + dma_desc->bytes_requested; /* Callback need to be call */ if (!dma_desc->cb_count) -- 2.19.1