From: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
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 <javier.martinez@collabora.co.uk>,
Doug Anderson <dianders@chromium.org>
Subject: [PATCH 2/3] spi: s3c64xx: validate s3c64xx_spi_csinfo before using
Date: Tue, 15 Jul 2014 17:50:59 +0530 [thread overview]
Message-ID: <1405426860-18404-3-git-send-email-ch.naveen@samsung.com> (raw)
In-Reply-To: <1405426860-18404-1-git-send-email-ch.naveen@samsung.com>
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 <ch.naveen@samsung.com>
Cc: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Cc: Doug Anderson <dianders@chromium.org>
---
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);
--
1.7.9.5
next prev parent reply other threads:[~2014-07-15 12:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 12:20 [PATCH 0/3] spi: s3c64xx: fix the driver to use "cs-gpios" property Naveen Krishna Chatradhi
2014-07-15 12:20 ` [PATCH 1/3] spi: s3c64xx: move "cs-gpio" from subnode to SPI DT node Naveen Krishna Chatradhi
2014-07-15 17:30 ` Tomasz Figa
2014-07-16 17:09 ` Mark Brown
2014-07-15 12:20 ` Naveen Krishna Chatradhi [this message]
2014-07-15 17:49 ` [PATCH 2/3] spi: s3c64xx: validate s3c64xx_spi_csinfo before using Tomasz Figa
2014-07-15 20:00 ` Javier Martinez Canillas
2014-07-15 12:21 ` [PATCH 3/3] ARM: DTS: fix the chip select gpios definition in the SPI nodes Naveen Krishna Chatradhi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405426860-18404-3-git-send-email-ch.naveen@samsung.com \
--to=ch.naveen@samsung.com \
--cc=broonie@kernel.org \
--cc=cpgs@samsung.com \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=grant.likely@secretlab.ca \
--cc=jaswinder.singh@linaro.org \
--cc=javier.martinez@collabora.co.uk \
--cc=kgene.kim@samsung.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=naveenkrishna.ch@gmail.com \
--cc=spi-devel-general@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).