From patchwork Tue Jul 15 12:20:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 4553581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5858D9F463 for ; Tue, 15 Jul 2014 12:28:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7C6D2012D for ; Tue, 15 Jul 2014 12:28:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7285520117 for ; Tue, 15 Jul 2014 12:28:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X71oI-0001oD-Ou; Tue, 15 Jul 2014 12:26:18 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X71oF-0001Pn-H1 for linux-arm-kernel@lists.infradead.org; Tue, 15 Jul 2014 12:26:16 +0000 Received: from epcpsbgr3.samsung.com (u143.gpu120.samsung.co.kr [203.254.230.143]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8R00G6A6J2RSD0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 15 Jul 2014 21:25:51 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.126]) by epcpsbgr3.samsung.com (EPCPMTA) with SMTP id 22.C4.14704.ECD15C35; Tue, 15 Jul 2014 21:25:50 +0900 (KST) X-AuditID: cbfee68f-b7fef6d000003970-d8-53c51dcea675 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 7F.2C.04943.ECD15C35; Tue, 15 Jul 2014 21:25:50 +0900 (KST) Received: from chnaveen-ubuntu.sisodomain.com ([107.108.83.161]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N8R00LER6GLGZB0@mmp1.samsung.com>; Tue, 15 Jul 2014 21:25:50 +0900 (KST) From: Naveen Krishna Chatradhi To: linux-arm-kernel@lists.infradead.org, spi-devel-general@lists.sourceforge.net, linux-samsung-soc@vger.kernel.org Subject: [PATCH 2/3] spi: s3c64xx: validate s3c64xx_spi_csinfo before using Date: Tue, 15 Jul 2014 17:50:59 +0530 Message-id: <1405426860-18404-3-git-send-email-ch.naveen@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1405426860-18404-1-git-send-email-ch.naveen@samsung.com> References: <1405426860-18404-1-git-send-email-ch.naveen@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrEIsWRmVeSWpSXmKPExsWyRsSkTvec7NFgg3cLTC2mPnzCZvHykKbF /CPnWC3OLjvIZvHqzEY2i8mb7jNaHP1dYNG74CqbxabH11gtZpzfx2SxaNt/ZosjUxrZHXg8 ZjdcZPH4+/w6i8fOWXfZPTat6mTzuHNtD5vH5iX1HrsXfGby6NuyitHj50sdj8+b5AK4orhs UlJzMstSi/TtErgyPn67wVbQL1Ax5/575gbGNbxdjJwcEgImEkdmXWWCsMUkLtxbz9bFyMUh JLCUUeJj+wQWmKIJiz4wQyQWMUrsXvaZCcLpZ5I4uLgFrJ1NwEzi4KLV7F2MHBwiAmUS8ybU gdQwC8xkkvh47g4bSI2wgLfE25sbmEFqWARUJV69ZwUJ8wq4Sty5tIQVJCwhoCAxZ5INiMkp 4CbR+tQbp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1+BCjKdBJE5mlRJPzgYkjryTe0NjE3NTY1NLEwsTMUkmc90CrdaCQQHpiSWp2ampBahFM HxMHp1QD44xzYmw8My6oBvkeCxKW+LGoU9HpcmXDgo9fTBqOJsgusL93TfTMXe2fa35+2yr1 Xi1q+sWUGUobrFX8G+SrNDfoXJppvUAnl6f3DI+q8acze2Nf++7w1rocL3Vgz4pG6xvnp+pH m3EGCR98lVn5QU6suWBFWnBR6IbMqVVCjw7X9f5NkFLSUGIpzkg01GIuKk4EABor9jfkAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140715_052615_759302_427AC865 X-CRM114-Status: GOOD ( 11.01 ) X-Spam-Score: -5.0 (-----) Cc: devicetree@vger.kernel.org, kgene.kim@samsung.com, Doug Anderson , grant.likely@secretlab.ca, jaswinder.singh@linaro.org, broonie@kernel.org, cpgs@samsung.com, naveenkrishna.ch@gmail.com, Javier Martinez Canillas X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch validates the cs->line (Chip select gpio) and struct s3c64xx_spi_csinfo *cs object for both DT and NON-DT platforms before using in .setup(). Also, check gpio_is_valid(spi->cs_gpio) in cleanup() before freeing up. Signed-off-by: Naveen Krishna Chatradhi Cc: Javier Martinez Canillas Cc: Doug Anderson --- drivers/spi/spi-s3c64xx.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 72bfba6..8971076 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -773,12 +773,6 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata( /* The CS line is asserted/deasserted by the gpio pin */ cs->line = spi->cs_gpio; - if (!gpio_is_valid(cs->line)) { - dev_err(&spi->dev, "chip select gpio is not specified or invalid\n"); - kfree(cs); - return ERR_PTR(-EINVAL); - } - data_np = of_get_child_by_name(slave_np, "controller-data"); if (!data_np) { dev_err(&spi->dev, "child node 'controller-data' not found\n"); @@ -805,15 +799,14 @@ static int s3c64xx_spi_setup(struct spi_device *spi) int err; sdd = spi_master_get_devdata(spi->master); - if (!cs && spi->dev.of_node) { + if (spi->dev.of_node) cs = s3c64xx_get_slave_ctrldata(spi); - spi->controller_data = cs; - } - if (IS_ERR_OR_NULL(cs)) { + if (IS_ERR_OR_NULL(cs) || !gpio_is_valid(cs->line)) { dev_err(&spi->dev, "No CS for SPI(%d)\n", spi->chip_select); return -ENODEV; } + spi->controller_data = cs; if (!spi_get_ctldata(spi)) { /* Request gpio only if cs line is asserted by gpio pins */ @@ -898,7 +891,7 @@ static void s3c64xx_spi_cleanup(struct spi_device *spi) struct s3c64xx_spi_driver_data *sdd; sdd = spi_master_get_devdata(spi->master); - if (spi->cs_gpio) { + if (gpio_is_valid(spi->cs_gpio)) { gpio_free(spi->cs_gpio); if (spi->dev.of_node) kfree(cs);