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: 4553501 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 84EAAC0515 for ; Tue, 15 Jul 2014 12:25:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7B6320158 for ; Tue, 15 Jul 2014 12:25:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAD1520123 for ; Tue, 15 Jul 2014 12:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758898AbaGOMZy (ORCPT ); Tue, 15 Jul 2014 08:25:54 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:54383 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758849AbaGOMZw (ORCPT ); Tue, 15 Jul 2014 08:25:52 -0400 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>; 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 Cc: naveenkrishna.ch@gmail.com, broonie@kernel.org, grant.likely@secretlab.ca, jaswinder.singh@linaro.org, kgene.kim@samsung.com, cpgs@samsung.com, devicetree@vger.kernel.org, Javier Martinez Canillas , Doug Anderson 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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76o NCe1+BCjKdBJE5mlRJPzgYkjryTe0NjE3NTY1NLEwsTMUkmc90CrdaCQQHpiSWp2ampBahFM HxMHp1QD44xzYmw8My6oBvkeCxKW+LGoU9HpcmXDgo9fTBqOJsgusL93TfTMXe2fa35+2yr1 Xi1q+sWUGUobrFX8G+SrNDfoXJppvUAnl6f3DI+q8acze2Nf++7w1rocL3Vgz4pG6xvnp+pH m3EGCR98lVn5QU6suWBFWnBR6IbMqVVCjw7X9f5NkFLSUGIpzkg01GIuKk4EABor9jfkAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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);