Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5586090img; Wed, 27 Mar 2019 11:11:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuzdrrz5/EZ0AAa32zQq2tfWXWOcltR+ijVDmZTvWpcfVBDLrmA2YYF+dfqbuNT+RXQatN X-Received: by 2002:a17:902:788d:: with SMTP id q13mr39223891pll.154.1553710265149; Wed, 27 Mar 2019 11:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553710265; cv=none; d=google.com; s=arc-20160816; b=C9mTPF4d5tSS+RB4xXsYqhXb9qwFI3Ne+QTU/lVLa+tHG1gWOKMm1CK7pj55qXXQvc ln/2bE8JiU6XyTJaUlBXTls8aBJJOTS1dhyhyk1hdE6gOmU0TXKAI8plbMY/ja16VV0j xOXBegPdLF/hPVXy5afGHF7HeDLnj7ooIJfelOmvZQrbgCMpudK6zZ4Ig1XUnLQA7/c9 mlk+UokbAy6/Bu7UIsnVM/oHERhodx7ewNU0DIzQUPlX3uNnDhYrpa3TPjaPn2DZkDk/ FIvdqn4FDeYu/X0gBcT8x59cHQzj5QXZLwAwvJXcLPnl8yB8MFVHrytlfYjuWZzUk7E+ yl1w== 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 :dkim-signature; bh=ZCQpPivlhCg/o8gl3zQdwZhkzU5H9YwuE35pKOZ+aoU=; b=kDCfAraC1F9lZ4tn5hnwGW1D0R2yUSEud+Atpz7IkGNFgPWZ17g2uHGTCJ/E2l+60H 8oLLdXo/h6CUtrHsoC+A1lEoa6MJ4QnyGPAb9OZdZWnFLARqdR8UrR3ZsQR5/fwgcqgv U7jERLFjYs6ar+3ulP8wzMGGUeHt36uEwF/28jLpMJL3pZu+H6K7UJc+07zKQJ5M2LlG 2eJtpexNwPS4FQyb0sTo5KJPeOeNvfJFQD9d/ovbtEQVxKSaQdX6udq12+ZSF7m2x7ai qpa45QObVPIEbGTuRUIV76IxOv0nNWvCp7u2bWaGzhnztuQzZNz6/eF4Amb74Vhb2p0o BO1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="TfVQbr/L"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si18561653pgv.340.2019.03.27.11.10.49; Wed, 27 Mar 2019 11:11: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="TfVQbr/L"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388754AbfC0SKK (ORCPT + 99 others); Wed, 27 Mar 2019 14:10:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:52112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388741AbfC0SKI (ORCPT ); Wed, 27 Mar 2019 14:10:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 23865218AC; Wed, 27 Mar 2019 18:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710207; bh=UZYtGBwLlAtlVhpWS6zCDUYUv2qfEbVZk7YavJ5pYPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TfVQbr/LAhtuStpyxhCqyDBuzFr7WlH09evMQeHOHv2szzb6GtzOdqib4DTKewV6q w0TBckyMTAlp+DH8NT0v5svf+A0ScnyzQhePa/52mndcuvtF5OURwLyhfELu151Ft5 DRYjDCZmN9NQxQc0sdbRFxBaa/d9GFNOWGFoGWL8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ben Dooks , Vinod Koul , Sasha Levin , dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 252/262] dmaengine: tegra: avoid overflow of byte tracking Date: Wed, 27 Mar 2019 14:01:47 -0400 Message-Id: <20190327180158.10245-252-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ben Dooks [ 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