Skip to content

Commit

Permalink
spi: Return error from of_spi_register_master on bad "cs-gpios" property
Browse files Browse the repository at this point in the history
This makes sure that an error is returned on an incorrectly formed
"cs-gpios" property, but reports success when the "cs-gpios" property is
well formed or missing.

When holes in the cs-gpios property phandle list is used to indicate
that some other form of chipselect is to be used it is important that
failure to read a broken "cs-gpios" property does not silently fail
leading to the spi controller to use an unintended chipselect.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Andreas Larsson authored and Grant Likely committed Apr 7, 2013
1 parent 446411e commit 8ec5d84
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,11 @@ static int of_spi_register_master(struct spi_master *master)
nb = of_gpio_named_count(np, "cs-gpios");
master->num_chipselect = max(nb, (int)master->num_chipselect);

if (nb < 1)
/* Return error only for an incorrectly formed cs-gpios property */
if (nb == 0 || nb == -ENOENT)
return 0;
else if (nb < 0)
return nb;

cs = devm_kzalloc(&master->dev,
sizeof(int) * master->num_chipselect,
Expand Down

0 comments on commit 8ec5d84

Please sign in to comment.