From patchwork Mon Apr 3 06:21:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9658805 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 9C86860352 for ; Mon, 3 Apr 2017 06:21:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E02C28429 for ; Mon, 3 Apr 2017 06:21:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82E8A2843B; Mon, 3 Apr 2017 06:21:40 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 0552F28429 for ; Mon, 3 Apr 2017 06:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751406AbdDCGVj (ORCPT ); Mon, 3 Apr 2017 02:21:39 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:40939 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751136AbdDCGVX (ORCPT ); Mon, 3 Apr 2017 02:21:23 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ONT008BSLNL9700@mailout3.w1.samsung.com>; Mon, 03 Apr 2017 07:21:21 +0100 (BST) Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170403062120eucas1p14aa6f6d4336feadd243aa1a10490d6cd~xzu_z9dH41434314343eucas1p1J; Mon, 3 Apr 2017 06:21:20 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1.samsung.com (EUCPMTA) with SMTP id 63.3A.14140.2E9E1E85; Mon, 3 Apr 2017 07:21:23 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170403062119eucas1p1fb7d0ceba0bc104d5e78cbc3343cf9fe~xzu9-KOXW1435114351eucas1p1M; Mon, 3 Apr 2017 06:21:19 +0000 (GMT) X-AuditID: cbfec7ef-f796a6d00000373c-e9-58e1e9e2bd0b Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 7A.D6.20206.2F9E1E85; Mon, 3 Apr 2017 07:21:38 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ONT006EQLNBVO80@eusync2.samsung.com>; Mon, 03 Apr 2017 07:21:19 +0100 (BST) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-serial@vger.kernel.org Cc: Marek Szyprowski , Sylwester Nawrocki , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Greg Kroah-Hartman , Seung-Woo Kim , Joonyoung Shim , Inki Dae , stable@vger.kernel.org Subject: [PATCH v3 2/3] serial: samsung: Add missing checks for dma_map_single failure Date: Mon, 03 Apr 2017 08:21:00 +0200 Message-id: <1491200468-28463-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1491200468-28463-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGIsWRmVeSWpSXmKPExsWy7djP87qPXz6MMFjQxWSxccZ6Vovmx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sJK+XYJbxrvN75kK1qlU3F1zjbGBcaZ8FyMnh4SAicTdo7sY IWwxiQv31rOB2EICSxglDlzz7WLkArKbmCQ23X3LCpJgEzCU6HrbBVYkIuAsMfvsQiaQImaB ZmaJnXtfM4EkhAUiJI5MP8ICYrMIqErcuD+LGcTmFfCQaF3ymhVim5zEyWOTwWxOAU+Juftv MENs9pA419fDPoGRdwEjwypGkdTS4tz03GIjveLE3OLSvHS95PzcTYzAUN927OeWHYxd74IP MQpwMCrx8Go4P4wQYk0sK67MPcQowcGsJMIbD4wUId6UxMqq1KL8+KLSnNTiQ4ymQEdNZJYS Tc4HxmFeSbyhiaG5paGRsYWFuZGRkjjv1A9XwoUE0hNLUrNTUwtSi2D6mDg4pRoYD9+wqbPO Pf/Yi91u1o/X8+eqtt+//1VL57Q3r6qp8zvhn/e7OjJ5DNa2Tpfwll2wjMFz7ikDlbUOCjMd tFlUfis9Mwz6I3ok5ranzBv7jRLv7PUYPqptn97edKAx7dl9nc/vJXmb64x2Mm6fWWVsPStg /+9CNv8n3pvOFjNmm144x+rrlXdciaU4I9FQi7moOBEAfC2rsosCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170403062119eucas1p1fb7d0ceba0bc104d5e78cbc3343cf9fe X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170403062119eucas1p1fb7d0ceba0bc104d5e78cbc3343cf9fe X-RootMTR: 20170403062119eucas1p1fb7d0ceba0bc104d5e78cbc3343cf9fe References: <1491200468-28463-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds missing checks for dma_map_single() failure and proper error reporting. Although this issue was harmless on ARM architecture, it is always good to use the DMA mapping API in a proper way. This patch fixes the following DMA API debug warning: WARNING: CPU: 1 PID: 3785 at lib/dma-debug.c:1171 check_unmap+0x8a0/0xf28 dma-pl330 121a0000.pdma: DMA-API: device driver failed to check map error[device address=0x000000006e0f9000] [size=4096 bytes] [mapped as single] Modules linked in: CPU: 1 PID: 3785 Comm: (agetty) Tainted: G W 4.11.0-rc1-00137-g07ca963-dirty #59 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x20/0x24) [] (show_stack) from [] (dump_stack+0x84/0xa0) [] (dump_stack) from [] (__warn+0x14c/0x180) [] (__warn) from [] (warn_slowpath_fmt+0x48/0x50) [] (warn_slowpath_fmt) from [] (check_unmap+0x8a0/0xf28) [] (check_unmap) from [] (debug_dma_unmap_page+0x98/0xc8) [] (debug_dma_unmap_page) from [] (s3c24xx_serial_shutdown+0x314/0x52c) [] (s3c24xx_serial_shutdown) from [] (uart_port_shutdown+0x54/0x88) [] (uart_port_shutdown) from [] (uart_shutdown+0xd4/0x110) [] (uart_shutdown) from [] (uart_hangup+0x9c/0x208) [] (uart_hangup) from [] (__tty_hangup+0x49c/0x634) [] (__tty_hangup) from [] (tty_ioctl+0xc88/0x16e4) [] (tty_ioctl) from [] (do_vfs_ioctl+0xc4/0xd10) [] (do_vfs_ioctl) from [] (SyS_ioctl+0x7c/0x8c) [] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x3c) Reported-by: Seung-Woo Kim Fixes: 62c37eedb74c8 ("serial: samsung: add dma reqest/release functions") CC: stable@vger.kernel.org # v4.10+ Signed-off-by: Marek Szyprowski Reviewed-by: Bartlomiej Zolnierkiewicz Reviewed-by: shuahkh@osg.samsung.com Reviewed-by: Krzysztof Kozlowski --- This issue was there since adding DMA support, but this patch applies cleanly only to v4.10+ kernels due to other changes in the surrounding code. v3: - moved spinlock removal to separate patch, extended commit message v2: - fixed commit id in 'fixes' tag, added 'reviewed-by' tag --- drivers/tty/serial/samsung.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c index 9f3759bdb44f..ca0bcd7fd61f 100644 --- a/drivers/tty/serial/samsung.c +++ b/drivers/tty/serial/samsung.c @@ -859,7 +859,7 @@ static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state) static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) { struct s3c24xx_uart_dma *dma = p->dma; - unsigned long flags; + int ret; /* Default slave configuration parameters */ dma->rx_conf.direction = DMA_DEV_TO_MEM; @@ -884,8 +884,8 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) dma->tx_chan = dma_request_chan(p->port.dev, "tx"); if (IS_ERR(dma->tx_chan)) { - dma_release_channel(dma->rx_chan); - return PTR_ERR(dma->tx_chan); + ret = PTR_ERR(dma->tx_chan); + goto err_release_rx; } dmaengine_slave_config(dma->tx_chan, &dma->tx_conf); @@ -894,15 +894,17 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) dma->rx_size = PAGE_SIZE; dma->rx_buf = kmalloc(dma->rx_size, GFP_KERNEL); - if (!dma->rx_buf) { - dma_release_channel(dma->rx_chan); - dma_release_channel(dma->tx_chan); - return -ENOMEM; + ret = -ENOMEM; + goto err_release_tx; } dma->rx_addr = dma_map_single(p->port.dev, dma->rx_buf, dma->rx_size, DMA_FROM_DEVICE); + if (dma_mapping_error(p->port.dev, dma->rx_addr)) { + ret = -EIO; + goto err_free_rx; + } spin_lock_irqsave(&p->port.lock, flags); @@ -911,8 +913,23 @@ static int s3c24xx_serial_request_dma(struct s3c24xx_uart_port *p) UART_XMIT_SIZE, DMA_TO_DEVICE); spin_unlock_irqrestore(&p->port.lock, flags); + if (dma_mapping_error(p->port.dev, dma->tx_addr)) { + ret = -EIO; + goto err_unmap_rx; + } return 0; + +err_unmap_rx: + dma_unmap_single(p->port.dev, dma->rx_addr, dma->rx_size, + DMA_FROM_DEVICE); +err_free_rx: + kfree(dma->rx_buf); +err_release_tx: + dma_release_channel(dma->tx_chan); +err_release_rx: + dma_release_channel(dma->rx_chan); + return ret; } static void s3c24xx_serial_release_dma(struct s3c24xx_uart_port *p)