From patchwork Thu Mar 23 07:45:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9640481 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 18DFE602CA for ; Thu, 23 Mar 2017 07:46:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06C3D27B13 for ; Thu, 23 Mar 2017 07:46:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF5AB27CF9; Thu, 23 Mar 2017 07:46: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.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 5DBC3284E9 for ; Thu, 23 Mar 2017 07:46:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752224AbdCWHqA (ORCPT ); Thu, 23 Mar 2017 03:46:00 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:41015 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752435AbdCWHp5 (ORCPT ); Thu, 23 Mar 2017 03:45:57 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON900800C8IKD50@mailout1.w1.samsung.com>; Thu, 23 Mar 2017 07:45:54 +0000 (GMT) Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170323074553eucas1p19a09e6447e650590e3bf2460c136c4b8~ucyqyrEDt0878108781eucas1p1y; Thu, 23 Mar 2017 07:45:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2.samsung.com (EUCPMTA) with SMTP id E2.DA.30614.13D73D85; Thu, 23 Mar 2017 07:45:53 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170323074553eucas1p110829c4ad1570104297df39c02cc59e5~ucyqCK9BG0879408794eucas1p1y; Thu, 23 Mar 2017 07:45:53 +0000 (GMT) X-AuditID: cbfec7f1-f793f6d000007796-43-58d37d31ee53 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 21.33.06687.C9D73D85; Thu, 23 Mar 2017 07:47:40 +0000 (GMT) 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 <0ON9006HQC88AT50@eusync2.samsung.com>; Thu, 23 Mar 2017 07:45:52 +0000 (GMT) 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 2/2] serial: samsung: Add missing checks for dma_map_single failure Date: Thu, 23 Mar 2017 08:45:22 +0100 Message-id: <1490255131-9597-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1490255131-9597-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOIsWRmVeSWpSXmKPExsWy7djPc7qGtZcjDJ4v0LDYOGM9q0Xz4vVs FpPu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VVitD1 DQlSUihLzCkF8owM0ICDc4B7sJK+XYJbxvcv51kL2sUreqdPZm5g3CjcxcjJISFgIvF60lw2 CFtM4sK99UA2F4eQwBJGidcfbjOCJIQEmpgkZv4PArHZBAwlut52gTWICDhLzD67kAmkgVmg mVli597XTCAJYYFQiftrl4A1swioSpz+8YIVxOYVcJf4/mw7M8Q2OYmTxyaDxTkFPCSOfljL BLHMXeLly3PsExh5FzAyrGIUSS0tzk3PLTbUK07MLS7NS9dLzs/dxAgM9W3Hfm7ewXhpY/Ah RgEORiUe3oiaSxFCrIllxZW5hxglOJiVRHhtCy9HCPGmJFZWpRblxxeV5qQWH2I0BTpqIrOU aHI+MA7zSuINTQzNLQ2NjC0szI2MlMR5Sz5cCRcSSE8sSc1OTS1ILYLpY+LglGpg9BK3WrWB 41Le1u0Vlb3OyX9XFEedeWCRfSe16N0v/WUZR33UPDJbjjmmsbXt3P7aq/r58szaj8fP917z uuP3w3X6eu4fp/44HHsptq5i6SPfO0VfDr46vTnk6pdUx+AN0jnua22mS86Ocf3Oz+XbIJXl Uhsruv/qtbuOq//NvRfma3X6RWXeaSWW4oxEQy3mouJEALXMpgaLAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170323074553eucas1p110829c4ad1570104297df39c02cc59e5 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 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: 20170323074553eucas1p110829c4ad1570104297df39c02cc59e5 X-RootMTR: 20170323074553eucas1p110829c4ad1570104297df39c02cc59e5 References: <1490255131-9597-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. While touching this part of the code, it also removes unnecessary spinlock calls around dma_map_single() for TX buffer. This finally solves all the issues reported by DMA API debug framework. Reported-by: Seung-Woo Kim Fixes: 2c37eedb74c8 ("serial: samsung: add dma reqest/release functions") CC: stable@vger.kernel.org # v4.10+ Signed-off-by: Marek Szyprowski Reviewed-by: Bartlomiej Zolnierkiewicz --- 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. --- drivers/tty/serial/samsung.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c index 9f3759bdb44f..8aca18c4cdea 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,25 +894,38 @@ 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); - - spin_lock_irqsave(&p->port.lock, flags); + if (dma_mapping_error(p->port.dev, dma->rx_addr)) { + ret = -EIO; + goto err_free_rx; + } /* TX buffer */ dma->tx_addr = dma_map_single(p->port.dev, p->port.state->xmit.buf, 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)