Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp990844yba; Thu, 4 Apr 2019 01:55:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRr2IrLycityHSooZDbKDykprzPNya2RF1lMMdoNboJ5UOFufNk8EWFs5uwjIUhkqFbHzG X-Received: by 2002:a65:430a:: with SMTP id j10mr4406264pgq.143.1554368101633; Thu, 04 Apr 2019 01:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368101; cv=none; d=google.com; s=arc-20160816; b=xO0mFJg/CxCD9tLB5PC0Hjq8fDew6p6OOU4fWyDa5IvexAosGXSZvb3tajtsJiUKbd bUjogtk09xfZgV2JKhuJ5DCoh+2HpqKDkKKqNYWUdWdKZpNn8/v5+R8sZ7Xo54Urkov/ jSNdY6ELSBQr153e67OpVJBcM6+QQ6Ibsl6uuaOTx/sjOjBmeJOkIrm0DWyqEySlQJEO 4gK3PRGd0juqUxhD/dWGBKduIHdPjbxnBEqe3clhSXUXBPwNTmNQ54Db7EqZ/6Ft9yAK B/mF3Q6wJeW/K3QBTfjVZxIJXUrL28WGQAO/W5VlRlbStq6rDt+bO8GX/gfUIGpG4PKL Xg+Q== 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=e1zem7RgHawVlTgwuzdnyzndF/4XWww3svy4sEFIJDs=; b=SO2+gvI0vrXuIwVUxAmFs8LIRc1aw98MJ5J91u5+WBoxKOsQORy23V39HTRt+SOC3P gupMqE6tEqN4oQ4NBURRl8pU/PYWxYxsGKu0MNj63h+7jzbUf4PhrxMXmIrJHyAZenBi DHvFmT+9G25LC9e8uzKzmk/hLpZzaKgzXhOufHeNrI2k29ruqru+04dXDNNbJuoyUQ9M iMIWp6NF3WJWtuqNZNKrwa/cykuQ+XaHMJDcsQwx9aP5oNb0kPozhHyw9hT/eUJWujjO ddXaTjzS2gwzrQBoGi1vhGCR+AcO3F8M9NuaWnUBi0jd9fPPn2Rduvzfbik00NEp6qcq CFhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wF5wvR5p; 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 62si69369pla.124.2019.04.04.01.54.45; Thu, 04 Apr 2019 01:55:01 -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=wF5wvR5p; 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 S1729855AbfDDIxf (ORCPT + 99 others); Thu, 4 Apr 2019 04:53:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:55956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729842AbfDDIxe (ORCPT ); Thu, 4 Apr 2019 04:53:34 -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 DAEA4217D7; Thu, 4 Apr 2019 08:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368013; bh=ruiPbK7gDiUpUUJzml5N4wCtDWjgvwPV21fzFeLvSCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wF5wvR5ph261uQb7DshTe35F/hVr/o5txKnTTbP1hNYf4btKIrrqpikHT6eCasSFI 0RxpH+7Z4q9EjFs8xoTnvrwvp0Vln5lz1QAu78Z8I/RAMH9xp1Jk5myZZ3m+SOgjYb x/7/DRrBNS2Pn70y8eAisrRIw02M6VtWZBfGaylM= 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.9 89/91] dmaengine: tegra: avoid overflow of byte tracking Date: Thu, 4 Apr 2019 10:48:13 +0200 Message-Id: <20190404084540.633923535@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084535.450029272@linuxfoundation.org> References: <20190404084535.450029272@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.9-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 3722b9d8d9fe..22f7f0c68a48 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -635,7 +635,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