Commit c7a9922e authored by Thomas Petazzoni's avatar Thomas Petazzoni Committed by Greg Kroah-Hartman

spi: orion: fix incorrect handling of cell-index DT property

commit e06871cd upstream.

In commit f814f9ac ("spi/orion: add device tree binding"), Device
Tree support was added to the spi-orion driver. However, this commit
reads the "cell-index" property, without taking into account the fact
that DT properties are big-endian encoded.

Since most of the platforms using spi-orion with DT have apparently
not used anything but cell-index = <0>, the problem was not
visible. But as soon as one starts using cell-index = <1>, the problem
becomes clearly visible, as the master->bus_num gets a wrong value
(actually it gets the value 0, which conflicts with the first bus that
has cell-index = <0>).

This commit fixes that by using of_property_read_u32() to read the
property value, which does the appropriate endianness conversion when
needed.

Fixes: f814f9ac ("spi/orion: add device tree binding")
Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Acked-by: default avatarSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 311aaa72
...@@ -346,8 +346,6 @@ static int orion_spi_probe(struct platform_device *pdev) ...@@ -346,8 +346,6 @@ static int orion_spi_probe(struct platform_device *pdev)
struct resource *r; struct resource *r;
unsigned long tclk_hz; unsigned long tclk_hz;
int status = 0; int status = 0;
const u32 *iprop;
int size;
master = spi_alloc_master(&pdev->dev, sizeof(*spi)); master = spi_alloc_master(&pdev->dev, sizeof(*spi));
if (master == NULL) { if (master == NULL) {
...@@ -358,10 +356,10 @@ static int orion_spi_probe(struct platform_device *pdev) ...@@ -358,10 +356,10 @@ static int orion_spi_probe(struct platform_device *pdev)
if (pdev->id != -1) if (pdev->id != -1)
master->bus_num = pdev->id; master->bus_num = pdev->id;
if (pdev->dev.of_node) { if (pdev->dev.of_node) {
iprop = of_get_property(pdev->dev.of_node, "cell-index", u32 cell_index;
&size); if (!of_property_read_u32(pdev->dev.of_node, "cell-index",
if (iprop && size == sizeof(*iprop)) &cell_index))
master->bus_num = *iprop; master->bus_num = cell_index;
} }
/* we support only mode 0, and no options */ /* we support only mode 0, and no options */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment