From patchwork Tue May 17 03:47:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Jiada" X-Patchwork-Id: 9108711 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E317FBF29F for ; Tue, 17 May 2016 03:51:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1EB2120268 for ; Tue, 17 May 2016 03:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31B66201B9 for ; Tue, 17 May 2016 03:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932076AbcEQDsL (ORCPT ); Mon, 16 May 2016 23:48:11 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:38162 "EHLO relay1.mentorg.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932068AbcEQDsJ (ORCPT ); Mon, 16 May 2016 23:48:09 -0400 Received: from svr-orw-fem-05.mgc.mentorg.com ([147.34.97.43]) by relay1.mentorg.com with esmtp id 1b2VzM-0004rl-7u from Jiada_Wang@mentor.com ; Mon, 16 May 2016 20:48:08 -0700 Received: from jiwang-OptiPlex-980.tokyo.mentorg.com (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.3.224.2; Mon, 16 May 2016 20:48:08 -0700 From: Jiada Wang To: , CC: , , , , , Subject: [PATCH 08/10] dma: imx-sdma: abort updating channel when it has been terminated Date: Tue, 17 May 2016 12:47:54 +0900 Message-ID: <1463456876-10580-9-git-send-email-jiada_wang@mentor.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: <1463456876-10580-1-git-send-email-jiada_wang@mentor.com> References: <1463456876-10580-1-git-send-email-jiada_wang@mentor.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case the corresponding channel has already been terminated, then instead of go on updating channel status, driver should abort from sdma_handle_channel_loop(), otherwise channel status will be updated incorrecly. This patch also adds lock to avoid race between terminate of channel, and updaing of channel status in sdma_handle_channel_loop(). Signed-off-by: Jiada Wang --- drivers/dma/imx-sdma.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index 0b23407..bc867e5 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -664,16 +664,25 @@ static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event) static void sdma_handle_channel_loop(struct sdma_channel *sdmac) { struct sdma_buffer_descriptor *bd; + unsigned long flags; /* * loop mode. Iterate over descriptors, re-setup them and * call callback function. */ while (1) { + spin_lock_irqsave(&sdmac->lock, flags); + if (!sdmac->enabled) { + spin_unlock_irqrestore(&sdmac->lock, flags); + break; + } + bd = &sdmac->bd[sdmac->buf_tail]; - if (bd->mode.status & BD_DONE) + if (bd->mode.status & BD_DONE) { + spin_unlock_irqrestore(&sdmac->lock, flags); break; + } if (bd->mode.status & BD_RROR) sdmac->status = DMA_ERROR; @@ -690,6 +699,7 @@ static void sdma_handle_channel_loop(struct sdma_channel *sdmac) bd->mode.count = sdmac->chn_count; } + spin_unlock_irqrestore(&sdmac->lock, flags); if (sdmac->desc.callback) sdmac->desc.callback(sdmac->desc.callback_param); }