From patchwork Sat Dec 28 20:46:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED2D214E3 for ; Sat, 28 Dec 2019 20:48:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCB2E21775 for ; Sat, 28 Dec 2019 20:48:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jioFFi89" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726860AbfL1Urf (ORCPT ); Sat, 28 Dec 2019 15:47:35 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33121 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbfL1Urf (ORCPT ); Sat, 28 Dec 2019 15:47:35 -0500 Received: by mail-lf1-f65.google.com with SMTP id n25so22936072lfl.0; Sat, 28 Dec 2019 12:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CDAf62ZTY71vcxUcl3aWo7Qq3pJ8TaeUpJZpeGFMx9A=; b=jioFFi89pBk9zb91Gbs374SGf0pLZAXb2FzjPMMg1+jG1GVqHFNKV+1o3i+80GrzGa 2ga1yijBlOP8tWQ65/cQECsC8B2/8LyYupM9mQBbs7jA2at7uZWjly/0S9N5sxacFl9O WuTbR/eQo3QayLtVrLhscPzFJwzumm+w1pfMDSvJwlPRpquu+XvdfjbvFVkDvAO5xQuM Y3QMZF5YJZHXF1KQwXfM+6O8pb4+P5L8EQQT/C0vDCxG/FDR1ensftjU71JHtBjstg4h lIi/5ehTDWcErlKKaR5KdwmrfjLHuim2Maq1F/BFC/uDCtDLyZZ0EYLGHXDCOV1H0bKQ jeBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CDAf62ZTY71vcxUcl3aWo7Qq3pJ8TaeUpJZpeGFMx9A=; b=Z4hCrE70DDVxbrLrnbNBJfYTbhoirwdVuH9//qSYJUbCgPf5WdkCbZSzM1cBo9WrB9 LBWLa3IAsRLJWHwzN95xze7BQcUFgLLVNS3bRS+V1AsCH3gsjlfSwfvLPiOZpqAXfLtQ WNTWMs48bEyQWRRDaIUkkvrtHbyV1cWBHKi4VMpxiBZFFTF3Z9sEH6aY8ztcvq/R24Ti t76XZa+rYAqFlcAqidgwj3md41lz////fY0ED8B+vn1fmsIV+BUoaJ+gsWrGZGuQkFlO xdPys1r1eYCoyd+rTAJ04JAl8zMeR/e56ZR5b4E4qUH4JFCbNKVThXXultZAYyZ9Hrvi WKEw== X-Gm-Message-State: APjAAAXKA01f8I8eHMcpt3TlbEMVko3HlwyiQ31dgLuSk2fm4RHUH2bu ha98/e65jH8BIqltVtIOJVw= X-Google-Smtp-Source: APXvYqw97z5b/W5LsK7Q5H8ywvRCnqNkQ85dYdx8D61oy9s3zvfu0sEUtmJpS+lVF2rMx4PpyShxgg== X-Received: by 2002:ac2:4add:: with SMTP id m29mr32108188lfp.190.1577566053115; Sat, 28 Dec 2019 12:47:33 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:32 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/7] dmaengine: tegra-apb: Fix use-after-free Date: Sat, 28 Dec 2019 23:46:34 +0300 Message-Id: <20191228204640.25163-2-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org I was doing some experiments with I2C and noticed that Tegra APB DMA driver crashes sometime after I2C DMA transfer termination. The crash happens because tegra_dma_terminate_all() bails out immediately if pending list is empty, thus it doesn't stop hardware and doesn't release the half-completed descriptors which are getting re-used before ISR tasklet kicks-in. tegra-i2c 7000c400.i2c: DMA transfer timeout elants_i2c 0-0010: elants_i2c_irq: failed to read data: -110 ------------[ cut here ]------------ WARNING: CPU: 0 PID: 142 at lib/list_debug.c:45 __list_del_entry_valid+0x45/0xac list_del corruption, ddbaac44->next is LIST_POISON1 (00000100) Modules linked in: CPU: 0 PID: 142 Comm: kworker/0:2 Not tainted 5.5.0-rc2-next-20191220-00175-gc3605715758d-dirty #538 Hardware name: NVIDIA Tegra SoC (Flattened Device Tree) Workqueue: events_freezable_power_ thermal_zone_device_check [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x85/0x94) [] (dump_stack) from [] (__warn+0xc1/0xc4) [] (__warn) from [] (warn_slowpath_fmt+0x61/0x78) [] (warn_slowpath_fmt) from [] (__list_del_entry_valid+0x45/0xac) [] (__list_del_entry_valid) from [] (tegra_dma_tasklet+0x5b/0x154) [] (tegra_dma_tasklet) from [] (tasklet_action_common.constprop.0+0x41/0x7c) [] (tasklet_action_common.constprop.0) from [] (__do_softirq+0xd3/0x2a8) [] (__do_softirq) from [] (irq_exit+0x7b/0x98) [] (irq_exit) from [] (__handle_domain_irq+0x45/0x80) [] (__handle_domain_irq) from [] (gic_handle_irq+0x45/0x7c) [] (gic_handle_irq) from [] (__irq_svc+0x65/0x94) Exception stack(0xde2ebb90 to 0xde2ebbd8) Cc: Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 3a45079d11ec..319f31d27014 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -756,10 +756,6 @@ static int tegra_dma_terminate_all(struct dma_chan *dc) bool was_busy; spin_lock_irqsave(&tdc->lock, flags); - if (list_empty(&tdc->pending_sg_req)) { - spin_unlock_irqrestore(&tdc->lock, flags); - return 0; - } if (!tdc->busy) goto skip_dma_stop; From patchwork Sat Dec 28 20:46:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97B9513A4 for ; Sat, 28 Dec 2019 20:47:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 783E021775 for ; Sat, 28 Dec 2019 20:47:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aQobqtgc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726923AbfL1Urh (ORCPT ); Sat, 28 Dec 2019 15:47:37 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40975 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbfL1Urg (ORCPT ); Sat, 28 Dec 2019 15:47:36 -0500 Received: by mail-lj1-f193.google.com with SMTP id h23so29878263ljc.8; Sat, 28 Dec 2019 12:47:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iSzNtTGK3mbZvFsWdibdEoWrg4nzIZ5PMxmWTFl+mGA=; b=aQobqtgc9qfZlmPXk8UOStRSUkmmwPp8tOLqOok9CH5lvlEgAIEA6eORSie2AELROd HpZWkaKM8qTqLFx6lN+8Ij4xCBeZp+pR3SP1NaM06AJM5CKr10Aro7t99IJCAA8qH4xO zfovOiDdoosbldJP+MWdO4bC0DpsfhEs0NR6J+Ot+iWbe67zJpmcnp/3tjcNogYxA7lI ZMT8Bq4qH8zhhHLg0PVQNyMAkHlkg3XO+cthBkTKL/nWZOloWzwIxIARoXFuyt90DPQZ B42FfiHiHvfVqCOBtuqcoH6ss2TuBJUJTyG6nAaOmm3IlC4+YQ0VNpuTADLQUXA+VZvK s06w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iSzNtTGK3mbZvFsWdibdEoWrg4nzIZ5PMxmWTFl+mGA=; b=oHKWgS7hdDLpEG3M7O0kch1hqAw/ApYc31eqN6w2jv7GpFSutz7Lq5E6KEkrHhMB/F m1m63JqISHmlx1n80uiPUXgTsus/VGS32sTBsHjrryGOpPZV1IDQuiLrqbwd/6F0Ktke U47WUlu/Ozfb1TVeVR9TexrxzL0NV7bFYIrQ0RXUwxfT4V4QfAZKRrxYMTi+gfs75fP7 DuMCY5oNUG0LVECr/htJ1f+Qhhe4ZlkGzioy00zhqa2o3ZLeHBTbqUKU94l+ef5Iso1N Bp8YD915wOpKyxImAm0wPe+ujyD1QAKf6k0HZ/qeM8wZ9ZMOZ4OqXNslFDVm4iH7yZ+r xdTA== X-Gm-Message-State: APjAAAWw2elLqVI1ejbk/+dKMtGY9UQb574dNiLj14YxIcLj7bTeMTZB qzlScz3S5jLFcp629nNZSqM= X-Google-Smtp-Source: APXvYqwvTuwFfA5xYeX0IUUhu0tlpFP6dPmn2gLahtb441Lto3fi3ieam7nB8EGvQhtKtttZEpQeCw== X-Received: by 2002:a2e:8954:: with SMTP id b20mr16119033ljk.27.1577566053945; Sat, 28 Dec 2019 12:47:33 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:33 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/7] dmaengine: tegra-apb: Implement synchronization callback Date: Sat, 28 Dec 2019 23:46:35 +0300 Message-Id: <20191228204640.25163-3-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org The ISR tasklet could be kept scheduled after DMA transfer termination, let's add synchronization callback which blocks until tasklet is finished. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 319f31d27014..664e9c5df3ba 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -798,6 +798,13 @@ static int tegra_dma_terminate_all(struct dma_chan *dc) return 0; } +static void tegra_dma_synchronize(struct dma_chan *dc) +{ + struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); + + tasklet_kill(&tdc->tasklet); +} + static unsigned int tegra_dma_sg_bytes_xferred(struct tegra_dma_channel *tdc, struct tegra_dma_sg_req *sg_req) { @@ -1506,6 +1513,7 @@ static int tegra_dma_probe(struct platform_device *pdev) tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; tdma->dma_dev.device_config = tegra_dma_slave_config; tdma->dma_dev.device_terminate_all = tegra_dma_terminate_all; + tdma->dma_dev.device_synchronize = tegra_dma_synchronize; tdma->dma_dev.device_tx_status = tegra_dma_tx_status; tdma->dma_dev.device_issue_pending = tegra_dma_issue_pending; From patchwork Sat Dec 28 20:46:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 564FF14F6 for ; Sat, 28 Dec 2019 20:48:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3421122522 for ; Sat, 28 Dec 2019 20:48:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DhcLEAjg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbfL1Uri (ORCPT ); Sat, 28 Dec 2019 15:47:38 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:32984 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726575AbfL1Urh (ORCPT ); Sat, 28 Dec 2019 15:47:37 -0500 Received: by mail-lj1-f194.google.com with SMTP id y6so21868187lji.0; Sat, 28 Dec 2019 12:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fLPm8kYY1aMbkcJ/I/yZlSuw3yqow+z5kIYMGPZJf+g=; b=DhcLEAjgQc+e+kejOgHEOasdw3svYPV7Y0HmjnfxXi3lqUPMqunzHIWTkaz5yWpfn8 m88ZSmIorpX/QQN40Anbfw+53ES/v8KWYZd4x18I4b38+UEnfx5yL6QvciIrvATeawOG gQlmj6Ep0Z2I/mU6fTY7RELCJWEAIC4KxTimJ8M4lyo5uOeAF9pKs6zp+l08EdJYyp5g Hu/0u37DttgBZY7SsdR3pzp8/a3HeWQBUYBwSUwnk2daPXbBS26aQdMXepu0L1E94C1A FpCtkpKqj43jCoehxyt8tIkBFWEVchkU4ELgI7kFKzsQoE1250WaTNNvGX6D0Zza9X7P Msaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fLPm8kYY1aMbkcJ/I/yZlSuw3yqow+z5kIYMGPZJf+g=; b=cN9X1SLIFCCEqe3FIXeE+oZXGm7sGmQe+stQjpCWUofOpYxLH8KKUargC6CnCG8XQ9 iNQ745xPqzJqL5bKFDWwJGb1RehvN5j+hvwTl6//zWiykBqav4liteUVn4/M5BxwxK16 L0oVVucpaYQEU8wMFR8zL8W9A65wBpCHipcX92bvQGP1eEhfVgqbKeV4wc1gnSjH578o 9cU//v37C26ykBsIFrksO0makLQZQIOt4JvOPT3yIEMWmjJzTfxDAlxMQm7xHnmwgD4w IyJK87pVSKt+xwhxgFJ8JvKA+scnVbKWNdBgjMH3fHb5Pn96p2cNRxU0FG4ilZG0mOcm OI/g== X-Gm-Message-State: APjAAAWxW7SL3WNHW4vo6oQ1sG+BaD6JCG6x8re1Hk3tp0dVHPzjG5cH xCJEj2MYrKGYTh4334RdxOk= X-Google-Smtp-Source: APXvYqwkrd2qAHBpXHL6S2DsvRKvIdpUjHngYf75N5aAJvkIP0DUqrZ2vWLREPyGCmS39AcXIRHwSQ== X-Received: by 2002:a2e:556:: with SMTP id 83mr33163294ljf.127.1577566054744; Sat, 28 Dec 2019 12:47:34 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:34 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/7] dmaengine: tegra-apb: Prevent race conditions on channel's freeing Date: Sat, 28 Dec 2019 23:46:36 +0300 Message-Id: <20191228204640.25163-4-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org It's unsafe to check the channel's "busy" state without taking a lock, it is also unsafe to assume that tasklet isn't in-fly. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 664e9c5df3ba..28aff0b9763e 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -1294,8 +1294,8 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc) dev_dbg(tdc2dev(tdc), "Freeing channel %d\n", tdc->id); - if (tdc->busy) - tegra_dma_terminate_all(dc); + tegra_dma_terminate_all(dc); + tasklet_kill(&tdc->tasklet); spin_lock_irqsave(&tdc->lock, flags); list_splice_init(&tdc->pending_sg_req, &sg_req_list); @@ -1543,7 +1543,6 @@ static int tegra_dma_probe(struct platform_device *pdev) struct tegra_dma_channel *tdc = &tdma->channels[i]; free_irq(tdc->irq, tdc); - tasklet_kill(&tdc->tasklet); } pm_runtime_disable(&pdev->dev); @@ -1563,7 +1562,6 @@ static int tegra_dma_remove(struct platform_device *pdev) for (i = 0; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; free_irq(tdc->irq, tdc); - tasklet_kill(&tdc->tasklet); } pm_runtime_disable(&pdev->dev); From patchwork Sat Dec 28 20:46:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AC7D13A4 for ; Sat, 28 Dec 2019 20:48:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08763208C4 for ; Sat, 28 Dec 2019 20:48:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AP8Exzoh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727003AbfL1Uri (ORCPT ); Sat, 28 Dec 2019 15:47:38 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40097 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbfL1Urh (ORCPT ); Sat, 28 Dec 2019 15:47:37 -0500 Received: by mail-lf1-f67.google.com with SMTP id i23so22919377lfo.7; Sat, 28 Dec 2019 12:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4rypt1/kYJGAf6C/Gog1EznwTiuR8sj2lcgKvtqgbT8=; b=AP8ExzohCEnt6ixOQz3oP0/J0CIopikiRt/lLzjGiBEEIu6fbUniS8K0NQUnVAzp+V LNmbKyZGOvRKgFKR/g3A3d1jOmunanQHiDGbTJ8VOP2bnsBdVd9RFFsLG0LPBN3OSgJA fGTS/IejndFLg0dt7b5pv3i7T2EfWLw7iFJ15vyWiA9IwAe4roxKRqAjuNdnroroT9vW 7o/E4G+qL9XR2jSROlut089gMLRQtRP1PQcMMPnmH1yJa34AApBP+bv6WncWuA6ocK0M ZR4/JyzRtGEd7Eqec13N5vc235QWP9pG1Z5julOQObnl2elpeckQphxLhEMTSFNBhdLO Vy2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4rypt1/kYJGAf6C/Gog1EznwTiuR8sj2lcgKvtqgbT8=; b=Rc3vYxXRKFSakIHyzmkvS1L9anIigbUz2GejZFp37sLGTC0qu1FotBlFGxGsSo1feL ahcRzPwx92QAu5l6muudrla1umWzjBdqMkK4iZPQdXfDEPkfykK69HVkvroQ3lSwdnum lYDc+u7sGlr9ijVHBYs3UyaTjVaLeFQOP0e7d45UM7XAOrZ1iN24x2nGHqJMdW8oZjyw u0hI3ZGJThUFFPyGRLrzdeBXJNNsbCv8FSmh3IbyBs+AZuEyNu+MfczNLHX5rfUJK+JE skvZ48ryR7+ZgFpQyQ/MvNId0B8BNs+w6x+UuDR1xX5QNSsoIYINiS1zZuBHA5/7qSSr 6Usw== X-Gm-Message-State: APjAAAVqpErvpEN4U/2WzvhJwU/U+/H/RLdJdoDrJyHuJsCH3yM2+RyS V9m9JbemezomTBo6q4i+1Fg= X-Google-Smtp-Source: APXvYqwDxEgv3gZMoxYttDIeu0SlE6IZqJdvibegz+aqs+kK9yabvUEsisYIaAUwGEvhDe9eUHj8uA== X-Received: by 2002:a19:5f58:: with SMTP id a24mr33623852lfj.9.1577566055538; Sat, 28 Dec 2019 12:47:35 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:35 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/7] dmaengine: tegra-apb: Prevent race conditions of tasklet vs free list Date: Sat, 28 Dec 2019 23:46:37 +0300 Message-Id: <20191228204640.25163-5-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org The interrupt handler puts a half-completed DMA descriptor on a free list and then schedules tasklet to process bottom half of the descriptor that executes client's callback, this creates possibility to pick up the busy descriptor from the free list. Thus let's disallow descriptor's re-use until it is fully processed. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 28aff0b9763e..740b0ceec7ec 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -281,7 +281,7 @@ static struct tegra_dma_desc *tegra_dma_desc_get( /* Do not allocate if desc are waiting for ack */ list_for_each_entry(dma_desc, &tdc->free_dma_desc, node) { - if (async_tx_test_ack(&dma_desc->txd)) { + if (async_tx_test_ack(&dma_desc->txd) && !dma_desc->cb_count) { list_del(&dma_desc->node); spin_unlock_irqrestore(&tdc->lock, flags); dma_desc->txd.flags = 0; From patchwork Sat Dec 28 20:46:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BF3113A4 for ; Sat, 28 Dec 2019 20:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A6932173E for ; Sat, 28 Dec 2019 20:47:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BmrmvnwR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbfL1Urj (ORCPT ); Sat, 28 Dec 2019 15:47:39 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43641 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbfL1Urj (ORCPT ); Sat, 28 Dec 2019 15:47:39 -0500 Received: by mail-lj1-f194.google.com with SMTP id a13so29878331ljm.10; Sat, 28 Dec 2019 12:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iZ3D39bl0eyByo7/hfV3v45VBZOWa7JfxNIxRNpu/N8=; b=BmrmvnwR3GOPQNeRWzfJ2QlcpbhMh0Qyb61SHXPdhESVag2N3vLPby7fSwv20xW6Dh H3YRT2KM0OU+OBfP34LxWZ96jcJAhYin7pWStBpzg9UJYnDBh0JknVx9S37y6oiZWh0x lQEdllzhB/XHrLF/3B6arW1psrYLUUGBe11QGWZLxUhJiqW10n+FD7dg32r+NNbnvj5/ 4OVxlb00LOw2qozR52ibezCFPjYDN1xB/NhIoUmgWlDTOLcN9vSX29fZpS7kzgShYRfn 7HHtG6Pl9Orn9WvZlQxnhNcEmiC/uQbQ1DuGcknaGStG1N6UXNgKpyvQArjrx5cH3KpJ F+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iZ3D39bl0eyByo7/hfV3v45VBZOWa7JfxNIxRNpu/N8=; b=n0ndDuQD2MTRWzHrsHu1Rcfrd4mLNu36G6mrmOfVB/tCUaYQQaj+7scD/Oewkpone5 thR2f34kpwOjX58d5ZNKUMwb8ieg1YySwArQx765bFA9iJrnuaXV6nzPJcQpmaHFz7xL pSgWIBeZ749vmL03Dz58Etlr6HOyf1EEWYoIxLyLOFXQ1yjqlPXV3GehYlDUoqFnu5JH awmfefz3HgGCjQ4KNyXSWgpUhI4d2+qXJ+GQORRccc+gb2NmSveF+SxrzoMA91LpFJ1h IlWKvxJliQuGSws+CTVs+9FsbWNLM1XihLWXu2hxwiuK1B+8sqbOKo1e6ONp/a1XvXCa LIYA== X-Gm-Message-State: APjAAAXi2wr6hw96x2oPW1OFYuvxuyKCI89McG+rfLgE39SzEkrcEkdm iDJm85o6JgUzzPoX3hNJm1k= X-Google-Smtp-Source: APXvYqwRFDWMCt+5WITO7u0D8AG40U1iA3Rkjy8bP/LOlJNsScDdPx0qJp4OQspninWhQEtnAITkUg== X-Received: by 2002:a2e:8119:: with SMTP id d25mr32134447ljg.76.1577566056359; Sat, 28 Dec 2019 12:47:36 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:35 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/7] dmaengine: tegra-apb: Use devm_platform_ioremap_resource Date: Sat, 28 Dec 2019 23:46:38 +0300 Message-Id: <20191228204640.25163-6-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Use devm_platform_ioremap_resource to keep code cleaner a tad. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 740b0ceec7ec..d2353f23b201 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -1405,8 +1405,7 @@ static int tegra_dma_probe(struct platform_device *pdev) tdma->chip_data = cdata; platform_set_drvdata(pdev, tdma); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - tdma->base_addr = devm_ioremap_resource(&pdev->dev, res); + tdma->base_addr = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(tdma->base_addr)) return PTR_ERR(tdma->base_addr); From patchwork Sat Dec 28 20:46:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAD7D14E3 for ; Sat, 28 Dec 2019 20:47:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F44021775 for ; Sat, 28 Dec 2019 20:47:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z4aLciAa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727018AbfL1Ur4 (ORCPT ); Sat, 28 Dec 2019 15:47:56 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36598 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbfL1Urj (ORCPT ); Sat, 28 Dec 2019 15:47:39 -0500 Received: by mail-lj1-f193.google.com with SMTP id r19so29879286ljg.3; Sat, 28 Dec 2019 12:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jIEJVFrrx4gky/ZOSTsCbKeEbeTJKbAx8QcAIMAQtco=; b=Z4aLciAa4SH3GG56GphUFmI5dvcpPOPdLZ2vY6B+ZTlLzIi/myT5WxIgydTE7FwEm7 N5jZNZurvRCXXJe+Y6WD7o7fJlUKeEK4tJjEAbbmiHrNbR5e62mLcDmORYPA81phwlxG kOvhXL2G3lWdXYiHU0F8JJs6BksLojoMXSsM+74XgAgB6eKyIAHSOSB316ibUnQzf6IL a8gsRIHMyQ3/c/oq18rR9uOtPSOL/7d7j+MboNC2VO5ML76NvnnoYmwtYCKAZJnlru1L muUycFZ2SHEk4FxmfrR3mvsBPFkf18Jjzegm2FWn00yS5lIbBWnUq9H7FjF+4kU6Xd0f CM0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jIEJVFrrx4gky/ZOSTsCbKeEbeTJKbAx8QcAIMAQtco=; b=JCwMVcG7OANIwicFVOuubmHr/5aBIN+FNnG41xVfVzMF71oYc9HfEnyULodZWgkpts /GE/XkPSk0EK3nVXxBkz0UBUECR4E39ZAGnu15ZLw+bT1vvq7WubhemoQME8Z2S++/XM +tICgerlM18SzBI5IL81Ng3R+rxSkPaNfpMIqBlyR21lzeiSy/A+7oKrx2AjojDrv63k UaXhjsJhuNmJ+Ay0PQkBXvav7qj18SeUyFgwwE/eXx8lUsdwKVtre2BFRxdy6z+EOUA3 PHUlq54aFm0SNOs3NEXQ9bD3dvfqWYI9vlR9uvOZc7JiiaKYYTZD8LSCsEQQYPUBvJ7p nIdg== X-Gm-Message-State: APjAAAV1NABO543ex+gXzlUvsLPnvE8o1e2qRIsGzLTI/kZuNTmncxxY Cc3lc/d3ocOUqMCHxU4Syoo+YBkf X-Google-Smtp-Source: APXvYqyEIX2Bqkh3D/lYkO4osanHP8eNOJOErqxIxITuHT47wuICMUHMUeaP6Xz35otnapNs6N/Oag== X-Received: by 2002:a2e:721a:: with SMTP id n26mr32498950ljc.128.1577566057155; Sat, 28 Dec 2019 12:47:37 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:36 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 6/7] dmaengine: tegra-apb: Use devm_request_irq Date: Sat, 28 Dec 2019 23:46:39 +0300 Message-Id: <20191228204640.25163-7-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Use resource-managed variant of request_irq for brevity. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index d2353f23b201..194a7faf12ba 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -182,7 +182,6 @@ struct tegra_dma_channel { char name[12]; bool config_init; int id; - int irq; void __iomem *chan_addr; spinlock_t lock; bool busy; @@ -1383,7 +1382,6 @@ static const struct tegra_dma_chip_data tegra148_dma_chip_data = { static int tegra_dma_probe(struct platform_device *pdev) { - struct resource *res; struct tegra_dma *tdma; int ret; int i; @@ -1449,25 +1447,27 @@ static int tegra_dma_probe(struct platform_device *pdev) INIT_LIST_HEAD(&tdma->dma_dev.channels); for (i = 0; i < cdata->nr_channels; i++) { struct tegra_dma_channel *tdc = &tdma->channels[i]; + int irq; tdc->chan_addr = tdma->base_addr + TEGRA_APBDMA_CHANNEL_BASE_ADD_OFFSET + (i * cdata->channel_reg_size); - res = platform_get_resource(pdev, IORESOURCE_IRQ, i); - if (!res) { - ret = -EINVAL; + irq = platform_get_irq(pdev, i); + if (irq < 0) { + ret = irq; dev_err(&pdev->dev, "No irq resource for chan %d\n", i); - goto err_irq; + goto err_pm_disable; } - tdc->irq = res->start; + snprintf(tdc->name, sizeof(tdc->name), "apbdma.%d", i); - ret = request_irq(tdc->irq, tegra_dma_isr, 0, tdc->name, tdc); + ret = devm_request_irq(&pdev->dev, irq, tegra_dma_isr, 0, + tdc->name, tdc); if (ret) { dev_err(&pdev->dev, "request_irq failed with err %d channel %d\n", ret, i); - goto err_irq; + goto err_pm_disable; } tdc->dma_chan.device = &tdma->dma_dev; @@ -1520,7 +1520,7 @@ static int tegra_dma_probe(struct platform_device *pdev) if (ret < 0) { dev_err(&pdev->dev, "Tegra20 APB DMA driver registration failed %d\n", ret); - goto err_irq; + goto err_pm_disable; } ret = of_dma_controller_register(pdev->dev.of_node, @@ -1537,13 +1537,7 @@ static int tegra_dma_probe(struct platform_device *pdev) err_unregister_dma_dev: dma_async_device_unregister(&tdma->dma_dev); -err_irq: - while (--i >= 0) { - struct tegra_dma_channel *tdc = &tdma->channels[i]; - - free_irq(tdc->irq, tdc); - } - +err_pm_disable: pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) tegra_dma_runtime_suspend(&pdev->dev); @@ -1553,16 +1547,9 @@ static int tegra_dma_probe(struct platform_device *pdev) static int tegra_dma_remove(struct platform_device *pdev) { struct tegra_dma *tdma = platform_get_drvdata(pdev); - int i; - struct tegra_dma_channel *tdc; dma_async_device_unregister(&tdma->dma_dev); - for (i = 0; i < tdma->chip_data->nr_channels; ++i) { - tdc = &tdma->channels[i]; - free_irq(tdc->irq, tdc); - } - pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) tegra_dma_runtime_suspend(&pdev->dev); From patchwork Sat Dec 28 20:46:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11311687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CB5314E3 for ; Sat, 28 Dec 2019 20:47:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0306C21744 for ; Sat, 28 Dec 2019 20:47:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kjsClrqc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727122AbfL1Urn (ORCPT ); Sat, 28 Dec 2019 15:47:43 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43642 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727018AbfL1Urm (ORCPT ); Sat, 28 Dec 2019 15:47:42 -0500 Received: by mail-lj1-f193.google.com with SMTP id a13so29878373ljm.10; Sat, 28 Dec 2019 12:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oKtk08sBwflKUyZQG2W3M/LoYTaaC/K8MlNHi+Vu9bc=; b=kjsClrqcs1gCdPuyyNC52GyJNin/pKyWMfllHfMFKVeZUh9TMaPUSX9E3bjfDJBjkz oCoGhgYxKQF0nnzqJXPXPxHJbfEtcS66FMprYo/0srUySnrrWwGeprG7e1zWE4a+mMnL 5louf5KcDhgJHvzORqJ5EzavT+zdrt236nXroeSjIFg4++3LVIEkYc31Q3etBoANLBE9 xst4+wDKfxICckbYyW3XFTMTQzyHdDYIdVe4DFC70aBOk/KzqwD7Q2/1zmMQHqxLlUV5 4X8UF26KQovDWwBoWiIyBpqAx4tgu6SBPZP5TObLvonMY3b/aXrTBfijtm11pS/BMn+F kUZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oKtk08sBwflKUyZQG2W3M/LoYTaaC/K8MlNHi+Vu9bc=; b=odD0yz9gbzfTXeMGVw48+Rl8ZUeREIEF4Tu6EPZjf042iMY6pJ7PXJkAlK+esfko/s ErnES4THy+Luu2dBS4YMJ3XVmnTmrgd/2YBsrQxcjbccKAAkL+7ZyGpmgANht3Td16Eu T/pBWECuVIA2IWUdqP/69g7Z+gnI+v09QyBjP8kEJxDr9GpDvLILv8fdwhRDfd9RGBZg AGds1RdJ6RjZwoXqsP/8AfYh0DF8ZN9Eah/f4DfrRle/NTa6W4BJsQj9XQqzIztlB3eP CXGv3Al7CJgVNXKK6CrwAyIJxwVExjzpForYuoMlQpE0vFG0VqVdlw2gLtMitzg0Ejht iQxw== X-Gm-Message-State: APjAAAUXMUGrkrzo8ytUzsC30MvzTDnarrfOJ2I4uOYz580dhsn14qSK YACD2p4dqhv7NrW908g4Z94= X-Google-Smtp-Source: APXvYqwE6KIvamX3Hfj64rQnbComBJLpPnyJOZomOTB4gsu0S0geP3rolpvOuiEhSC3swxikzf3GtA== X-Received: by 2002:a2e:814e:: with SMTP id t14mr31087914ljg.149.1577566058114; Sat, 28 Dec 2019 12:47:38 -0800 (PST) Received: from localhost.localdomain (79-139-233-37.dynamic.spd-mgts.ru. [79.139.233.37]) by smtp.gmail.com with ESMTPSA id g15sm10571219ljl.10.2019.12.28.12.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Dec 2019 12:47:37 -0800 (PST) From: Dmitry Osipenko To: Laxman Dewangan , Vinod Koul , Dan Williams , Thierry Reding , Jonathan Hunter Cc: dmaengine@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 7/7] dmaengine: tegra-apb: Fix coding style problems Date: Sat, 28 Dec 2019 23:46:40 +0300 Message-Id: <20191228204640.25163-8-digetx@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191228204640.25163-1-digetx@gmail.com> References: <20191228204640.25163-1-digetx@gmail.com> MIME-Version: 1.0 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org This patch fixes few dozens of coding style problems reported by checkpatch and prettifies code where makes sense. Signed-off-by: Dmitry Osipenko --- drivers/dma/tegra20-apb-dma.c | 273 ++++++++++++++++++---------------- 1 file changed, 142 insertions(+), 131 deletions(-) diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c index 194a7faf12ba..464d6f2a0924 100644 --- a/drivers/dma/tegra20-apb-dma.c +++ b/drivers/dma/tegra20-apb-dma.c @@ -59,7 +59,7 @@ #define TEGRA_APBDMA_STATUS_COUNT_MASK 0xFFFC #define TEGRA_APBDMA_CHAN_CSRE 0x00C -#define TEGRA_APBDMA_CHAN_CSRE_PAUSE (1 << 31) +#define TEGRA_APBDMA_CHAN_CSRE_PAUSE BIT(31) /* AHB memory address */ #define TEGRA_APBDMA_CHAN_AHBPTR 0x010 @@ -120,21 +120,21 @@ struct tegra_dma; * @support_separate_wcount_reg: Support separate word count register. */ struct tegra_dma_chip_data { - int nr_channels; - int channel_reg_size; - int max_dma_count; + unsigned int nr_channels; + unsigned int channel_reg_size; + unsigned int max_dma_count; bool support_channel_pause; bool support_separate_wcount_reg; }; /* DMA channel registers */ struct tegra_dma_channel_regs { - unsigned long csr; - unsigned long ahb_ptr; - unsigned long apb_ptr; - unsigned long ahb_seq; - unsigned long apb_seq; - unsigned long wcount; + u32 csr; + u32 ahb_ptr; + u32 apb_ptr; + u32 ahb_seq; + u32 apb_seq; + u32 wcount; }; /* @@ -168,7 +168,7 @@ struct tegra_dma_desc { struct list_head node; struct list_head tx_list; struct list_head cb_node; - int cb_count; + unsigned int cb_count; }; struct tegra_dma_channel; @@ -181,7 +181,7 @@ struct tegra_dma_channel { struct dma_chan dma_chan; char name[12]; bool config_init; - int id; + unsigned int id; void __iomem *chan_addr; spinlock_t lock; bool busy; @@ -201,7 +201,7 @@ struct tegra_dma_channel { /* Channel-slave specific configuration */ unsigned int slave_id; struct dma_slave_config dma_sconfig; - struct tegra_dma_channel_regs channel_reg; + struct tegra_dma_channel_regs channel_reg; }; /* tegra_dma: Tegra DMA specific information */ @@ -239,7 +239,7 @@ static inline u32 tdma_read(struct tegra_dma *tdma, u32 reg) } static inline void tdc_write(struct tegra_dma_channel *tdc, - u32 reg, u32 val) + u32 reg, u32 val) { writel(val, tdc->chan_addr + reg); } @@ -254,8 +254,8 @@ static inline struct tegra_dma_channel *to_tegra_dma_chan(struct dma_chan *dc) return container_of(dc, struct tegra_dma_channel, dma_chan); } -static inline struct tegra_dma_desc *txd_to_tegra_dma_desc( - struct dma_async_tx_descriptor *td) +static inline struct tegra_dma_desc * +txd_to_tegra_dma_desc(struct dma_async_tx_descriptor *td) { return container_of(td, struct tegra_dma_desc, txd); } @@ -270,8 +270,7 @@ static int tegra_dma_runtime_suspend(struct device *dev); static int tegra_dma_runtime_resume(struct device *dev); /* Get DMA desc from free list, if not there then allocate it. */ -static struct tegra_dma_desc *tegra_dma_desc_get( - struct tegra_dma_channel *tdc) +static struct tegra_dma_desc *tegra_dma_desc_get(struct tegra_dma_channel *tdc) { struct tegra_dma_desc *dma_desc; unsigned long flags; @@ -298,11 +297,12 @@ static struct tegra_dma_desc *tegra_dma_desc_get( dma_async_tx_descriptor_init(&dma_desc->txd, &tdc->dma_chan); dma_desc->txd.tx_submit = tegra_dma_tx_submit; dma_desc->txd.flags = 0; + return dma_desc; } static void tegra_dma_desc_put(struct tegra_dma_channel *tdc, - struct tegra_dma_desc *dma_desc) + struct tegra_dma_desc *dma_desc) { unsigned long flags; @@ -313,29 +313,29 @@ static void tegra_dma_desc_put(struct tegra_dma_channel *tdc, spin_unlock_irqrestore(&tdc->lock, flags); } -static struct tegra_dma_sg_req *tegra_dma_sg_req_get( - struct tegra_dma_channel *tdc) +static struct tegra_dma_sg_req * +tegra_dma_sg_req_get(struct tegra_dma_channel *tdc) { - struct tegra_dma_sg_req *sg_req = NULL; + struct tegra_dma_sg_req *sg_req; unsigned long flags; spin_lock_irqsave(&tdc->lock, flags); if (!list_empty(&tdc->free_sg_req)) { - sg_req = list_first_entry(&tdc->free_sg_req, - typeof(*sg_req), node); + sg_req = list_first_entry(&tdc->free_sg_req, typeof(*sg_req), + node); list_del(&sg_req->node); spin_unlock_irqrestore(&tdc->lock, flags); return sg_req; } spin_unlock_irqrestore(&tdc->lock, flags); - sg_req = kzalloc(sizeof(struct tegra_dma_sg_req), GFP_NOWAIT); + sg_req = kzalloc(sizeof(*sg_req), GFP_NOWAIT); return sg_req; } static int tegra_dma_slave_config(struct dma_chan *dc, - struct dma_slave_config *sconfig) + struct dma_slave_config *sconfig) { struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); @@ -352,11 +352,12 @@ static int tegra_dma_slave_config(struct dma_chan *dc, tdc->slave_id = sconfig->slave_id; } tdc->config_init = true; + return 0; } static void tegra_dma_global_pause(struct tegra_dma_channel *tdc, - bool wait_for_burst_complete) + bool wait_for_burst_complete) { struct tegra_dma *tdma = tdc->tdma; @@ -391,13 +392,13 @@ static void tegra_dma_global_resume(struct tegra_dma_channel *tdc) } static void tegra_dma_pause(struct tegra_dma_channel *tdc, - bool wait_for_burst_complete) + bool wait_for_burst_complete) { struct tegra_dma *tdma = tdc->tdma; if (tdma->chip_data->support_channel_pause) { tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE, - TEGRA_APBDMA_CHAN_CSRE_PAUSE); + TEGRA_APBDMA_CHAN_CSRE_PAUSE); if (wait_for_burst_complete) udelay(TEGRA_APBDMA_BURST_COMPLETE_TIME); } else { @@ -409,17 +410,15 @@ static void tegra_dma_resume(struct tegra_dma_channel *tdc) { struct tegra_dma *tdma = tdc->tdma; - if (tdma->chip_data->support_channel_pause) { + if (tdma->chip_data->support_channel_pause) tdc_write(tdc, TEGRA_APBDMA_CHAN_CSRE, 0); - } else { + else tegra_dma_global_resume(tdc); - } } static void tegra_dma_stop(struct tegra_dma_channel *tdc) { - u32 csr; - u32 status; + u32 csr, status; /* Disable interrupts */ csr = tdc_read(tdc, TEGRA_APBDMA_CHAN_CSR); @@ -440,7 +439,7 @@ static void tegra_dma_stop(struct tegra_dma_channel *tdc) } static void tegra_dma_start(struct tegra_dma_channel *tdc, - struct tegra_dma_sg_req *sg_req) + struct tegra_dma_sg_req *sg_req) { struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs; @@ -454,11 +453,11 @@ static void tegra_dma_start(struct tegra_dma_channel *tdc, /* Start DMA */ tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, - ch_regs->csr | TEGRA_APBDMA_CSR_ENB); + ch_regs->csr | TEGRA_APBDMA_CSR_ENB); } static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc, - struct tegra_dma_sg_req *nsg_req) + struct tegra_dma_sg_req *nsg_req) { unsigned long status; @@ -492,9 +491,9 @@ static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc, tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr); if (tdc->tdma->chip_data->support_separate_wcount_reg) tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT, - nsg_req->ch_regs.wcount); + nsg_req->ch_regs.wcount); tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, - nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB); + nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB); nsg_req->configured = true; nsg_req->words_xferred = 0; @@ -508,8 +507,7 @@ static void tdc_start_head_req(struct tegra_dma_channel *tdc) if (list_empty(&tdc->pending_sg_req)) return; - sg_req = list_first_entry(&tdc->pending_sg_req, - typeof(*sg_req), node); + sg_req = list_first_entry(&tdc->pending_sg_req, typeof(*sg_req), node); tegra_dma_start(tdc, sg_req); sg_req->configured = true; sg_req->words_xferred = 0; @@ -518,34 +516,35 @@ static void tdc_start_head_req(struct tegra_dma_channel *tdc) static void tdc_configure_next_head_desc(struct tegra_dma_channel *tdc) { - struct tegra_dma_sg_req *hsgreq; - struct tegra_dma_sg_req *hnsgreq; + struct tegra_dma_sg_req *hsgreq, *hnsgreq; if (list_empty(&tdc->pending_sg_req)) return; hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node); if (!list_is_last(&hsgreq->node, &tdc->pending_sg_req)) { - hnsgreq = list_first_entry(&hsgreq->node, - typeof(*hnsgreq), node); + hnsgreq = list_first_entry(&hsgreq->node, typeof(*hnsgreq), + node); tegra_dma_configure_for_next(tdc, hnsgreq); } } -static inline int get_current_xferred_count(struct tegra_dma_channel *tdc, - struct tegra_dma_sg_req *sg_req, unsigned long status) +static inline unsigned int +get_current_xferred_count(struct tegra_dma_channel *tdc, + struct tegra_dma_sg_req *sg_req, + unsigned long status) { return sg_req->req_len - (status & TEGRA_APBDMA_STATUS_COUNT_MASK) - 4; } static void tegra_dma_abort_all(struct tegra_dma_channel *tdc) { - struct tegra_dma_sg_req *sgreq; struct tegra_dma_desc *dma_desc; + struct tegra_dma_sg_req *sgreq; while (!list_empty(&tdc->pending_sg_req)) { - sgreq = list_first_entry(&tdc->pending_sg_req, - typeof(*sgreq), node); + sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), + node); list_move_tail(&sgreq->node, &tdc->free_sg_req); if (sgreq->last_sg) { dma_desc = sgreq->dma_desc; @@ -555,7 +554,7 @@ static void tegra_dma_abort_all(struct tegra_dma_channel *tdc) /* Add in cb list if it is not there. */ if (!dma_desc->cb_count) list_add_tail(&dma_desc->cb_node, - &tdc->cb_desc); + &tdc->cb_desc); dma_desc->cb_count++; } } @@ -563,9 +562,10 @@ static void tegra_dma_abort_all(struct tegra_dma_channel *tdc) } static bool handle_continuous_head_request(struct tegra_dma_channel *tdc, - struct tegra_dma_sg_req *last_sg_req, bool to_terminate) + struct tegra_dma_sg_req *last_sg_req, + bool to_terminate) { - struct tegra_dma_sg_req *hsgreq = NULL; + struct tegra_dma_sg_req *hsgreq; if (list_empty(&tdc->pending_sg_req)) { dev_err(tdc2dev(tdc), "DMA is running without req\n"); @@ -589,14 +589,15 @@ static bool handle_continuous_head_request(struct tegra_dma_channel *tdc, /* Configure next request */ if (!to_terminate) tdc_configure_next_head_desc(tdc); + return true; } static void handle_once_dma_done(struct tegra_dma_channel *tdc, - bool to_terminate) + bool to_terminate) { - struct tegra_dma_sg_req *sgreq; struct tegra_dma_desc *dma_desc; + struct tegra_dma_sg_req *sgreq; tdc->busy = false; sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node); @@ -622,10 +623,10 @@ static void handle_once_dma_done(struct tegra_dma_channel *tdc, } static void handle_cont_sngl_cycle_dma_done(struct tegra_dma_channel *tdc, - bool to_terminate) + bool to_terminate) { - struct tegra_dma_sg_req *sgreq; struct tegra_dma_desc *dma_desc; + struct tegra_dma_sg_req *sgreq; bool st; sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), node); @@ -657,13 +658,13 @@ static void tegra_dma_tasklet(unsigned long data) struct tegra_dma_channel *tdc = (struct tegra_dma_channel *)data; struct dmaengine_desc_callback cb; struct tegra_dma_desc *dma_desc; + unsigned int cb_count; unsigned long flags; - int cb_count; spin_lock_irqsave(&tdc->lock, flags); while (!list_empty(&tdc->cb_desc)) { - dma_desc = list_first_entry(&tdc->cb_desc, - typeof(*dma_desc), cb_node); + dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc), + cb_node); list_del(&dma_desc->cb_node); dmaengine_desc_get_callback(&dma_desc->txd, &cb); cb_count = dma_desc->cb_count; @@ -681,8 +682,8 @@ static void tegra_dma_tasklet(unsigned long data) static irqreturn_t tegra_dma_isr(int irq, void *dev_id) { struct tegra_dma_channel *tdc = dev_id; - unsigned long status; unsigned long flags; + u32 status; spin_lock_irqsave(&tdc->lock, flags); @@ -697,8 +698,9 @@ static irqreturn_t tegra_dma_isr(int irq, void *dev_id) } spin_unlock_irqrestore(&tdc->lock, flags); - dev_info(tdc2dev(tdc), - "Interrupt already served status 0x%08lx\n", status); + dev_info(tdc2dev(tdc), "Interrupt already served status 0x%08x\n", + status); + return IRQ_NONE; } @@ -714,6 +716,7 @@ static dma_cookie_t tegra_dma_tx_submit(struct dma_async_tx_descriptor *txd) cookie = dma_cookie_assign(&dma_desc->txd); list_splice_tail_init(&dma_desc->tx_list, &tdc->pending_sg_req); spin_unlock_irqrestore(&tdc->lock, flags); + return cookie; } @@ -747,11 +750,10 @@ static void tegra_dma_issue_pending(struct dma_chan *dc) static int tegra_dma_terminate_all(struct dma_chan *dc) { struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); - struct tegra_dma_sg_req *sgreq; struct tegra_dma_desc *dma_desc; + struct tegra_dma_sg_req *sgreq; unsigned long flags; - unsigned long status; - unsigned long wcount; + u32 status, wcount; bool was_busy; spin_lock_irqsave(&tdc->lock, flags); @@ -777,8 +779,8 @@ static int tegra_dma_terminate_all(struct dma_chan *dc) tegra_dma_stop(tdc); if (!list_empty(&tdc->pending_sg_req) && was_busy) { - sgreq = list_first_entry(&tdc->pending_sg_req, - typeof(*sgreq), node); + sgreq = list_first_entry(&tdc->pending_sg_req, typeof(*sgreq), + node); sgreq->dma_desc->bytes_transferred += get_current_xferred_count(tdc, sgreq, wcount); } @@ -788,12 +790,13 @@ static int tegra_dma_terminate_all(struct dma_chan *dc) tegra_dma_abort_all(tdc); while (!list_empty(&tdc->cb_desc)) { - dma_desc = list_first_entry(&tdc->cb_desc, - typeof(*dma_desc), cb_node); + dma_desc = list_first_entry(&tdc->cb_desc, typeof(*dma_desc), + cb_node); list_del(&dma_desc->cb_node); dma_desc->cb_count = 0; } spin_unlock_irqrestore(&tdc->lock, flags); + return 0; } @@ -807,7 +810,7 @@ static void tegra_dma_synchronize(struct dma_chan *dc) static unsigned int tegra_dma_sg_bytes_xferred(struct tegra_dma_channel *tdc, struct tegra_dma_sg_req *sg_req) { - unsigned long status, wcount = 0; + u32 status, wcount = 0; if (!list_is_first(&sg_req->node, &tdc->pending_sg_req)) return 0; @@ -864,7 +867,8 @@ static unsigned int tegra_dma_sg_bytes_xferred(struct tegra_dma_channel *tdc, } static enum dma_status tegra_dma_tx_status(struct dma_chan *dc, - dma_cookie_t cookie, struct dma_tx_state *txstate) + dma_cookie_t cookie, + struct dma_tx_state *txstate) { struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); struct tegra_dma_desc *dma_desc; @@ -911,11 +915,12 @@ static enum dma_status tegra_dma_tx_status(struct dma_chan *dc, trace_tegra_dma_tx_status(&tdc->dma_chan, cookie, txstate); spin_unlock_irqrestore(&tdc->lock, flags); + return ret; } -static inline int get_bus_width(struct tegra_dma_channel *tdc, - enum dma_slave_buswidth slave_bw) +static inline unsigned int get_bus_width(struct tegra_dma_channel *tdc, + enum dma_slave_buswidth slave_bw) { switch (slave_bw) { case DMA_SLAVE_BUSWIDTH_1_BYTE: @@ -928,16 +933,17 @@ static inline int get_bus_width(struct tegra_dma_channel *tdc, return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_64; default: dev_warn(tdc2dev(tdc), - "slave bw is not supported, using 32bits\n"); + "slave bw is not supported, using 32bits\n"); return TEGRA_APBDMA_APBSEQ_BUS_WIDTH_32; } } -static inline int get_burst_size(struct tegra_dma_channel *tdc, - u32 burst_size, enum dma_slave_buswidth slave_bw, int len) +static inline unsigned int get_burst_size(struct tegra_dma_channel *tdc, + u32 burst_size, + enum dma_slave_buswidth slave_bw, + u32 len) { - int burst_byte; - int burst_ahb_width; + unsigned int burst_byte, burst_ahb_width; /* * burst_size from client is in terms of the bus_width. @@ -964,9 +970,10 @@ static inline int get_burst_size(struct tegra_dma_channel *tdc, } static int get_transfer_param(struct tegra_dma_channel *tdc, - enum dma_transfer_direction direction, unsigned long *apb_addr, - unsigned long *apb_seq, unsigned long *csr, unsigned int *burst_size, - enum dma_slave_buswidth *slave_bw) + enum dma_transfer_direction direction, + u32 *apb_addr, u32 *apb_seq, u32 *csr, + unsigned int *burst_size, + enum dma_slave_buswidth *slave_bw) { switch (direction) { case DMA_MEM_TO_DEV: @@ -987,13 +994,15 @@ static int get_transfer_param(struct tegra_dma_channel *tdc, default: dev_err(tdc2dev(tdc), "DMA direction is not supported\n"); - return -EINVAL; + break; } + return -EINVAL; } static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc, - struct tegra_dma_channel_regs *ch_regs, u32 len) + struct tegra_dma_channel_regs *ch_regs, + u32 len) { u32 len_field = (len - 4) & 0xFFFC; @@ -1003,20 +1012,23 @@ static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc, ch_regs->csr |= len_field; } -static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( - struct dma_chan *dc, struct scatterlist *sgl, unsigned int sg_len, - enum dma_transfer_direction direction, unsigned long flags, - void *context) +static struct dma_async_tx_descriptor * +tegra_dma_prep_slave_sg(struct dma_chan *dc, + struct scatterlist *sgl, + unsigned int sg_len, + enum dma_transfer_direction direction, + unsigned long flags, + void *context) { struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); + struct tegra_dma_sg_req *sg_req = NULL; + u32 csr, ahb_seq, apb_ptr, apb_seq; + enum dma_slave_buswidth slave_bw; struct tegra_dma_desc *dma_desc; - unsigned int i; - struct scatterlist *sg; - unsigned long csr, ahb_seq, apb_ptr, apb_seq; struct list_head req_list; - struct tegra_dma_sg_req *sg_req = NULL; - u32 burst_size; - enum dma_slave_buswidth slave_bw; + struct scatterlist *sg; + unsigned int burst_size; + unsigned int i; if (!tdc->config_init) { dev_err(tdc2dev(tdc), "DMA channel is not configured\n"); @@ -1028,7 +1040,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( } if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr, - &burst_size, &slave_bw) < 0) + &burst_size, &slave_bw) < 0) return NULL; INIT_LIST_HEAD(&req_list); @@ -1074,7 +1086,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( len = sg_dma_len(sg); if ((len & 3) || (mem & 3) || - (len > tdc->tdma->chip_data->max_dma_count)) { + len > tdc->tdma->chip_data->max_dma_count) { dev_err(tdc2dev(tdc), "DMA length/memory address is not supported\n"); tegra_dma_desc_put(tdc, dma_desc); @@ -1126,20 +1138,21 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg( return &dma_desc->txd; } -static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic( - struct dma_chan *dc, dma_addr_t buf_addr, size_t buf_len, - size_t period_len, enum dma_transfer_direction direction, - unsigned long flags) +static struct dma_async_tx_descriptor * +tegra_dma_prep_dma_cyclic(struct dma_chan *dc, dma_addr_t buf_addr, + size_t buf_len, + size_t period_len, + enum dma_transfer_direction direction, + unsigned long flags) { struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); - struct tegra_dma_desc *dma_desc = NULL; struct tegra_dma_sg_req *sg_req = NULL; - unsigned long csr, ahb_seq, apb_ptr, apb_seq; - int len; - size_t remain_len; - dma_addr_t mem = buf_addr; - u32 burst_size; + u32 csr, ahb_seq, apb_ptr, apb_seq; enum dma_slave_buswidth slave_bw; + struct tegra_dma_desc *dma_desc; + dma_addr_t mem = buf_addr; + unsigned int burst_size; + size_t len, remain_len; if (!buf_len || !period_len) { dev_err(tdc2dev(tdc), "Invalid buffer/period len\n"); @@ -1173,13 +1186,13 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic( len = period_len; if ((len & 3) || (buf_addr & 3) || - (len > tdc->tdma->chip_data->max_dma_count)) { + len > tdc->tdma->chip_data->max_dma_count) { dev_err(tdc2dev(tdc), "Req len/mem address is not correct\n"); return NULL; } if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr, - &burst_size, &slave_bw) < 0) + &burst_size, &slave_bw) < 0) return NULL; ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB; @@ -1306,8 +1319,8 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc) spin_unlock_irqrestore(&tdc->lock, flags); while (!list_empty(&dma_desc_list)) { - dma_desc = list_first_entry(&dma_desc_list, - typeof(*dma_desc), node); + dma_desc = list_first_entry(&dma_desc_list, typeof(*dma_desc), + node); list_del(&dma_desc->node); kfree(dma_desc); } @@ -1326,8 +1339,8 @@ static struct dma_chan *tegra_dma_of_xlate(struct of_phandle_args *dma_spec, struct of_dma *ofdma) { struct tegra_dma *tdma = ofdma->of_dma_data; - struct dma_chan *chan; struct tegra_dma_channel *tdc; + struct dma_chan *chan; if (dma_spec->args[0] > TEGRA_APBDMA_CSR_REQ_SEL_MASK) { dev_err(tdma->dev, "Invalid slave id: %d\n", dma_spec->args[0]); @@ -1382,20 +1395,16 @@ static const struct tegra_dma_chip_data tegra148_dma_chip_data = { static int tegra_dma_probe(struct platform_device *pdev) { + const struct tegra_dma_chip_data *cdata; struct tegra_dma *tdma; + unsigned int i; + size_t size; int ret; - int i; - const struct tegra_dma_chip_data *cdata; cdata = of_device_get_match_data(&pdev->dev); - if (!cdata) { - dev_err(&pdev->dev, "Error: No device match data found\n"); - return -ENODEV; - } + size = struct_size(tdma, channels, cdata->nr_channels); - tdma = devm_kzalloc(&pdev->dev, - struct_size(tdma, channels, cdata->nr_channels), - GFP_KERNEL); + tdma = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); if (!tdma) return -ENOMEM; @@ -1427,10 +1436,8 @@ static int tegra_dma_probe(struct platform_device *pdev) else ret = pm_runtime_get_sync(&pdev->dev); - if (ret < 0) { - pm_runtime_disable(&pdev->dev); - return ret; - } + if (ret < 0) + goto err_pm_disable; /* Reset DMA controller */ reset_control_assert(tdma->rst); @@ -1473,13 +1480,13 @@ static int tegra_dma_probe(struct platform_device *pdev) tdc->dma_chan.device = &tdma->dma_dev; dma_cookie_init(&tdc->dma_chan); list_add_tail(&tdc->dma_chan.device_node, - &tdma->dma_dev.channels); + &tdma->dma_dev.channels); tdc->tdma = tdma; tdc->id = i; tdc->slave_id = TEGRA_APBDMA_SLAVE_ID_INVALID; tasklet_init(&tdc->tasklet, tegra_dma_tasklet, - (unsigned long)tdc); + (unsigned long)tdc); spin_lock_init(&tdc->lock); INIT_LIST_HEAD(&tdc->pending_sg_req); @@ -1531,16 +1538,19 @@ static int tegra_dma_probe(struct platform_device *pdev) goto err_unregister_dma_dev; } - dev_info(&pdev->dev, "Tegra20 APB DMA driver register %d channels\n", - cdata->nr_channels); + dev_info(&pdev->dev, "Tegra20 APB DMA driver registered %d channels\n", + cdata->nr_channels); + return 0; err_unregister_dma_dev: dma_async_device_unregister(&tdma->dma_dev); + err_pm_disable: pm_runtime_disable(&pdev->dev); if (!pm_runtime_status_suspended(&pdev->dev)) tegra_dma_runtime_suspend(&pdev->dev); + return ret; } @@ -1560,7 +1570,7 @@ static int tegra_dma_remove(struct platform_device *pdev) static int tegra_dma_runtime_suspend(struct device *dev) { struct tegra_dma *tdma = dev_get_drvdata(dev); - int i; + unsigned int i; tdma->reg_gen = tdma_read(tdma, TEGRA_APBDMA_GENERAL); for (i = 0; i < tdma->chip_data->nr_channels; i++) { @@ -1589,7 +1599,8 @@ static int tegra_dma_runtime_suspend(struct device *dev) static int tegra_dma_runtime_resume(struct device *dev) { struct tegra_dma *tdma = dev_get_drvdata(dev); - int i, ret; + unsigned int i; + int ret; ret = clk_prepare_enable(tdma->dma_clk); if (ret < 0) { @@ -1617,7 +1628,7 @@ static int tegra_dma_runtime_resume(struct device *dev) tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBSEQ, ch_reg->ahb_seq); tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, ch_reg->ahb_ptr); tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, - (ch_reg->csr & ~TEGRA_APBDMA_CSR_ENB)); + ch_reg->csr & ~TEGRA_APBDMA_CSR_ENB); } return 0;