From patchwork Mon Aug 21 06:31:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 9911629 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CBE43602D8 for ; Mon, 21 Aug 2017 06:32:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B47BC28735 for ; Mon, 21 Aug 2017 06:32:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A90372873F; Mon, 21 Aug 2017 06:32:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF7E528745 for ; Mon, 21 Aug 2017 06:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751058AbdHUGcF (ORCPT ); Mon, 21 Aug 2017 02:32:05 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:62255 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751010AbdHUGcD (ORCPT ); Mon, 21 Aug 2017 02:32:03 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 21 Aug 2017 15:32:01 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 2871968969; Mon, 21 Aug 2017 15:32:02 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.41,407,1498489200"; d="scan'208";a="254079738" Received: from mail-hk2apc01lp0208.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.208]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 21 Aug 2017 15:32:00 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=U8lhTMjnEbz53MnOxMuD+yqoIjb6awc8qtUCgw/pw0M=; b=alu9WpqTFmWoJRC/r7dGsyLQ6oGRH83Ts5lEp4GaCQK0DIJeMPg39BozefU0LkgLq9NvuEhqFfvxcDovGJMAhbBthjNn9jvq/wK1OF+MPoWBTEoCepwN0ifHIPNsGsNZUgTjUbL5S+n45Zs0z9kJZoSmQDT1YLJzb0a7FmvthYc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.138) by KL1PR0601MB1878.apcprd06.prod.outlook.com (2603:1096:802:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1362.18; Mon, 21 Aug 2017 06:31:57 +0000 Message-ID: <877exxcu9q.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2] rcar-dmac: initialize all data before registering IRQ handler User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Vinod Koul , Laurent Pinchart Cc: Niklas =?ISO-8859-1?Q?S=F6derlund?= , Dan Williams , Linux-Renesas , Linux-Kernel , Arnd Bergmann , Anton Volkov , Alexey Khoroshilov , ldv-project@linuxtesting.org, dmaengine@vger.kernel.org, geert+renesas@glider.be MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Mon, 21 Aug 2017 06:31:57 +0000 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: KL1PR0601CA0008.apcprd06.prod.outlook.com (2603:1096:802:1::18) To KL1PR0601MB1878.apcprd06.prod.outlook.com (2603:1096:802:7::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eaf36af6-e696-4d32-8811-08d4e85e5321 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:KL1PR0601MB1878; X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1878; 3:rbFVrFB7P0hk1EdvvAxYYvl8GwmpF/L8kJgvZDuyZ8US+ZTUsa1QWf09anzK0kal/rvb/j7dL7x49vm4Igl2uup/ARZ+E1huDMkU05T884PGRXqKTXXPQjwZKQSDVgUEn5Cz8gaM0jRX2iL8cV4z+EYcpMmz5UF1p1TzzhG6WzRL9OBYYtqXl2u0BjUozxz8T4EmVDaL6MO/VtS0SrrHDRPn0dqqwMuB8t93CTSw/wicP6LTzPVEf9hblwMA120A; 25:vY7VS0RktxErGRdQ9motPG1QbQK4/J6hrXBajle5RaQ0a4Aa6aqKxVHU/l+lewyhke0WYYyxKEsUXFRgjyS8LxbyJV4GQaVcjVzJR4eskx2OiT3x+xC+vvcLRCGRd3cWzfiS5VHGGLKEp1t2XzVDEZeAoc7GAg02HZpTGhmib4oEdlDi+TJzp2oAmhZPbWat4hhXcVTDgs3U0e5AL3MM2ixGEVoLcnI24ARDk4h7OjiXgEN4nX6lrAsI0sLrsdvmhHsQq6N5gxNvlWMTcI2wXbQ2+K4I9uuFGl0Slhl0SD40iYqW2XJ7CNoBBsKpEYOd1pOyLiwswZ1jRKKfVz/b1w==; 31:Je9hyYwN3nx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antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6041248)(20161123555025)(20161123558100)(20161123560025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:KL1PR0601MB1878; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:KL1PR0601MB1878; X-Forefront-PRVS: 040655413E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(7370300001)(6009001)(39860400002)(189002)(199003)(81156014)(86362001)(53416004)(2906002)(83506001)(42186005)(189998001)(478600001)(6486002)(54906002)(53936002)(69596002)(8676002)(81166006)(68736007)(7736002)(50466002)(50986999)(54356999)(36756003)(47776003)(4326008)(7416002)(25786009)(105586002)(3846002)(5660300001)(106356001)(7350300001)(4001350100001)(101416001)(97736004)(4477795004)(23726003)(6116002)(33646002)(66066001)(305945005)(21314002)(16060500001); DIR:OUT; SFP:1102; SCL:1; SRVR:KL1PR0601MB1878; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: renesas.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; KL1PR0601MB1878; 23:nWBiJw5jBUA+PuNGrogkNdPdK/mVWYIb6yX0wRW?= =?us-ascii?Q?38VdhbHiVQxuljMa2n+dTD7KQ/bWlOYbScatC9J7pqntcM+9e3Fy01Ezh1h/?= =?us-ascii?Q?4Kj343d60q6j4Omp6VOu3QoaTLy5NexHRyPxGEVY5hX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: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1878; 20:D3iZbSJd9OK6rCP5XIzmNjHlmgOa7RHMMpC83UMfWnuqzh3e7ub1JGRe5RAXVOnsZ56syxa45VlBG1bGwQO6KvwIGPDF9UyM4ZQPQeWJv5617hQr4AfywxArNr/9K6JWOY5CKWixLPX0zWJrW6ZrvXO4i53D4nBq2edD0BAzSoQ= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2017 06:31:57.2390 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB1878 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto Anton Volkov noticed that engine->dev is NULL before of_dma_controller_register() in probe. Thus there might be a NULL pointer dereference in rcar_dmac_chan_start_xfer while accessing chan->chan.device->dev which is equal to (&dmac->engine)->dev. On same reason, same and similar things will happen if we didn't initialize all necessary data before calling register irq function. To be more safety code, this patch initialize all necessary data before calling register irq function. Reported-by: Anton Volkov Signed-off-by: Kuninori Morimoto --- v1 -> v2 - care devm_request_threaded_irq(xxx) on rcar_dmac_chan_probe() - care devm_request_irq(xx) on rcar_dmac_probe() drivers/dma/sh/rcar-dmac.c | 85 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index ffcadca..2b2c7db 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1690,6 +1690,15 @@ static int rcar_dmac_chan_probe(struct rcar_dmac *dmac, if (!irqname) return -ENOMEM; + /* + * Initialize the DMA engine channel and add it to the DMA engine + * channels list. + */ + chan->device = &dmac->engine; + dma_cookie_init(chan); + + list_add_tail(&chan->device_node, &dmac->engine.channels); + ret = devm_request_threaded_irq(dmac->dev, rchan->irq, rcar_dmac_isr_channel, rcar_dmac_isr_channel_thread, 0, @@ -1700,15 +1709,6 @@ static int rcar_dmac_chan_probe(struct rcar_dmac *dmac, return ret; } - /* - * Initialize the DMA engine channel and add it to the DMA engine - * channels list. - */ - chan->device = &dmac->engine; - dma_cookie_init(chan); - - list_add_tail(&chan->device_node, &dmac->engine.channels); - return 0; } @@ -1794,14 +1794,6 @@ static int rcar_dmac_probe(struct platform_device *pdev) if (!irqname) return -ENOMEM; - ret = devm_request_irq(&pdev->dev, irq, rcar_dmac_isr_error, 0, - irqname, dmac); - if (ret) { - dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", - irq, ret); - return ret; - } - /* Enable runtime PM and initialize the device. */ pm_runtime_enable(&pdev->dev); ret = pm_runtime_get_sync(&pdev->dev); @@ -1818,8 +1810,32 @@ static int rcar_dmac_probe(struct platform_device *pdev) goto error; } - /* Initialize the channels. */ - INIT_LIST_HEAD(&dmac->engine.channels); + /* Initialize engine */ + engine = &dmac->engine; + + dma_cap_set(DMA_MEMCPY, engine->cap_mask); + dma_cap_set(DMA_SLAVE, engine->cap_mask); + + engine->dev = &pdev->dev; + engine->copy_align = ilog2(RCAR_DMAC_MEMCPY_XFER_SIZE); + + engine->src_addr_widths = widths; + engine->dst_addr_widths = widths; + engine->directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM); + engine->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; + + engine->device_alloc_chan_resources = rcar_dmac_alloc_chan_resources; + engine->device_free_chan_resources = rcar_dmac_free_chan_resources; + engine->device_prep_dma_memcpy = rcar_dmac_prep_dma_memcpy; + engine->device_prep_slave_sg = rcar_dmac_prep_slave_sg; + engine->device_prep_dma_cyclic = rcar_dmac_prep_dma_cyclic; + engine->device_config = rcar_dmac_device_config; + engine->device_terminate_all = rcar_dmac_chan_terminate_all; + engine->device_tx_status = rcar_dmac_tx_status; + engine->device_issue_pending = rcar_dmac_issue_pending; + engine->device_synchronize = rcar_dmac_device_synchronize; + + INIT_LIST_HEAD(&engine->channels); for (i = 0; i < dmac->n_channels; ++i) { ret = rcar_dmac_chan_probe(dmac, &dmac->channels[i], @@ -1828,6 +1844,14 @@ static int rcar_dmac_probe(struct platform_device *pdev) goto error; } + ret = devm_request_irq(&pdev->dev, irq, rcar_dmac_isr_error, 0, + irqname, dmac); + if (ret) { + dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n", + irq, ret); + return ret; + } + /* Register the DMAC as a DMA provider for DT. */ ret = of_dma_controller_register(pdev->dev.of_node, rcar_dmac_of_xlate, NULL); @@ -1839,29 +1863,6 @@ static int rcar_dmac_probe(struct platform_device *pdev) * * Default transfer size of 32 bytes requires 32-byte alignment. */ - engine = &dmac->engine; - dma_cap_set(DMA_MEMCPY, engine->cap_mask); - dma_cap_set(DMA_SLAVE, engine->cap_mask); - - engine->dev = &pdev->dev; - engine->copy_align = ilog2(RCAR_DMAC_MEMCPY_XFER_SIZE); - - engine->src_addr_widths = widths; - engine->dst_addr_widths = widths; - engine->directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM); - engine->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; - - engine->device_alloc_chan_resources = rcar_dmac_alloc_chan_resources; - engine->device_free_chan_resources = rcar_dmac_free_chan_resources; - engine->device_prep_dma_memcpy = rcar_dmac_prep_dma_memcpy; - engine->device_prep_slave_sg = rcar_dmac_prep_slave_sg; - engine->device_prep_dma_cyclic = rcar_dmac_prep_dma_cyclic; - engine->device_config = rcar_dmac_device_config; - engine->device_terminate_all = rcar_dmac_chan_terminate_all; - engine->device_tx_status = rcar_dmac_tx_status; - engine->device_issue_pending = rcar_dmac_issue_pending; - engine->device_synchronize = rcar_dmac_device_synchronize; - ret = dma_async_device_register(engine); if (ret < 0) goto error;