From patchwork Thu Mar 23 12:01:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 95905 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp637594obz; Thu, 23 Mar 2017 05:02:30 -0700 (PDT) X-Received: by 10.98.92.1 with SMTP id q1mr2519506pfb.209.1490270550240; Thu, 23 Mar 2017 05:02:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si5432201pld.54.2017.03.23.05.02.30; Thu, 23 Mar 2017 05:02:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932702AbdCWMCV (ORCPT + 2 others); Thu, 23 Mar 2017 08:02:21 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:56431 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932776AbdCWMCS (ORCPT ); Thu, 23 Mar 2017 08:02:18 -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 <0ON9006NAO3RNN20@mailout1.w1.samsung.com>; Thu, 23 Mar 2017 12:02:15 +0000 (GMT) Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170323120214eucas1p10a9a247feace6f700b8e87262fb08709~ugSez1YDh2700927009eucas1p1t; Thu, 23 Mar 2017 12:02:14 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1.samsung.com (EUCPMTA) with SMTP id 4D.F2.16908.849B3D85; Thu, 23 Mar 2017 12:02:16 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170323120213eucas1p2f288fa4f85c8d0db098d3ca2bf378b34~ugSd-3u8a2015020150eucas1p2s; Thu, 23 Mar 2017 12:02:13 +0000 (GMT) X-AuditID: cbfec7ef-f79d26d00000420c-eb-58d3b948fa30 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CF.EC.10233.459B3D85; Thu, 23 Mar 2017 12:02:28 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ON900MNEO3FD5A0@eusync3.samsung.com>; Thu, 23 Mar 2017 12:02:13 +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 v2 2/2] serial: samsung: Add missing checks for dma_map_single failure Date: Thu, 23 Mar 2017 13:01:53 +0100 Message-id: <1490270519-4046-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1490270519-4046-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsWy7djPc7oeOy9HGOz4omWxccZ6VovmxevZ LCbdn8Bi8eLeRRaL8+c3sFvMOL+PyeLM4l52i7VH7rJbHH7TzmqxYOMjRosZk1+yOXB7bFrV yeaxf+4ado++LasYPT5vkgtgieKySUnNySxLLdK3S+DKWNmwkrGgV6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5gtIuAsMfvsQiaQImaB ZmaJnXtfM4EkhAUiJG7/bgMbyyKgKnHhTTOYzSvgLnHszVFmiHVyEiePTWYFsTkFPCQe7YKw hYBqjl49xjiBkXcBI8MqRpHU0uLc9NxiI73ixNzi0rx0veT83E2MwGDfduznlh2MXe+CDzEK cDAq8fBuqLsUIcSaWFZcmXuIUYKDWUmE99H2yxFCvCmJlVWpRfnxRaU5qcWHGE2BjprILCWa nA+MxLySeEMTQ3NLQyNjCwtzIyMlcd6pH66ECwmkJ5akZqemFqQWwfQxcXBKNTB25t26pNBy 7s8FRbWKwpeczRM2T3425/GKxRmfme5GJ971t/y1YzfLsp7S3j2FRv9PB+7I+ql4NCrzS4dS YYiz3oVOpazsI503+3w2Jt81Kep+viGrbtIRwbgE3foZbtpKl/44Tz6g2iGo37zmiNzO+39/ a2yTs+BdNTGoSO7/v8bTQq3OTc+UWIozEg21mIuKEwEklbz3jAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170323120213eucas1p2f288fa4f85c8d0db098d3ca2bf378b34 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1B?= =?utf-8?b?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1BSam?= =?utf-8?q?sung_Electronics=1BSenior_Software_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BEHQ=1BC10CD02CD027392?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170323120213eucas1p2f288fa4f85c8d0db098d3ca2bf378b34 X-RootMTR: 20170323120213eucas1p2f288fa4f85c8d0db098d3ca2bf378b34 References: <1490270519-4046-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 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: 62c37eedb74c8 ("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. v2: - fixed commit id in 'fixes' tag, added 'reviewed-by' tag --- drivers/tty/serial/samsung.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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)