* [U-Boot] [PATCH v2] spi: soft_spi: Fix for soft_spi @ 2019-01-07 8:20 Horatiu Vultur 2019-01-07 8:20 ` Horatiu Vultur 2019-01-07 8:20 ` [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi Horatiu Vultur 0 siblings, 2 replies; 5+ messages in thread From: Horatiu Vultur @ 2019-01-07 8:20 UTC (permalink / raw) To: u-boot This patch series, fix a null ptr inside soft_spi. This version address comments from Jagan Teki <jagan@amarulasolutions.com> v2 changes: - update soft_spi_platdata inside .set_mode. Horatiu Vultur (1): spi: soft_spi: Fix null ptr when probing soft_spi. drivers/spi/soft_spi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v2] spi: soft_spi: Fix for soft_spi 2019-01-07 8:20 [U-Boot] [PATCH v2] spi: soft_spi: Fix for soft_spi Horatiu Vultur @ 2019-01-07 8:20 ` Horatiu Vultur 2019-01-07 8:20 ` [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi Horatiu Vultur 1 sibling, 0 replies; 5+ messages in thread From: Horatiu Vultur @ 2019-01-07 8:20 UTC (permalink / raw) To: u-boot This patch series, fix a null ptr inside soft_spi. This version address comments from Jagan Teki <jagan@amarulasolutions.com> v2 changes: - update soft_spi_platdata inside .set_mode. Horatiu Vultur (1): spi: soft_spi: Fix null ptr when probing soft_spi. drivers/spi/soft_spi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.7.4 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi. 2019-01-07 8:20 [U-Boot] [PATCH v2] spi: soft_spi: Fix for soft_spi Horatiu Vultur 2019-01-07 8:20 ` Horatiu Vultur @ 2019-01-07 8:20 ` Horatiu Vultur 2019-01-07 17:09 ` Daniel Schwierzeck 1 sibling, 1 reply; 5+ messages in thread From: Horatiu Vultur @ 2019-01-07 8:20 UTC (permalink / raw) To: u-boot When probing soft_spi the result of dev_get_parent_priv(dev) in probe function is null ptr because the spi is on the ahb bus which has per_child_auto_alloc_size set to 0. Therefore it would generate an Ooops messages when accessing spi_slave structure. The fix consist of updating the soft_spi_platdata flags inside the .set_mode. Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> --- drivers/spi/soft_spi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index b06883f..2c47577 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -183,9 +183,15 @@ static int soft_spi_set_speed(struct udevice *dev, unsigned int speed) static int soft_spi_set_mode(struct udevice *dev, unsigned int mode) { struct soft_spi_priv *priv = dev_get_priv(dev); + struct soft_spi_platdata *plat = dev->platdata; priv->mode = mode; + if (!(mode & SPI_CS_HIGH)) + plat->cs.flags |= GPIOD_ACTIVE_LOW; + if (mode & SPI_CPOL) + plat->sclk.flags |= GPIOD_ACTIVE_LOW; + return 0; } @@ -210,18 +216,13 @@ static int soft_spi_ofdata_to_platdata(struct udevice *dev) static int soft_spi_probe(struct udevice *dev) { - struct spi_slave *slave = dev_get_parent_priv(dev); struct soft_spi_platdata *plat = dev->platdata; - int cs_flags, clk_flags; int ret; - cs_flags = (slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW; - clk_flags = (slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0; - if (gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs, - GPIOD_IS_OUT | cs_flags) || + GPIOD_IS_OUT) || gpio_request_by_name(dev, "gpio-sck", 0, &plat->sclk, - GPIOD_IS_OUT | clk_flags)) + GPIOD_IS_OUT)) return -EINVAL; ret = gpio_request_by_name(dev, "gpio-mosi", 0, &plat->mosi, -- 2.7.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi. 2019-01-07 8:20 ` [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi Horatiu Vultur @ 2019-01-07 17:09 ` Daniel Schwierzeck 2019-01-07 19:29 ` Horatiu Vultur 0 siblings, 1 reply; 5+ messages in thread From: Daniel Schwierzeck @ 2019-01-07 17:09 UTC (permalink / raw) To: u-boot Am 07.01.19 um 09:20 schrieb Horatiu Vultur: > When probing soft_spi the result of dev_get_parent_priv(dev) in probe > function is null ptr because the spi is on the ahb bus which has > per_child_auto_alloc_size set to 0. Therefore it would generate an Ooops > messages when accessing spi_slave structure. > > The fix consist of updating the soft_spi_platdata flags inside the > .set_mode. > > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> > --- > drivers/spi/soft_spi.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) is this patch still required with https://patchwork.ozlabs.org/cover/1021335/ ? > > diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c > index b06883f..2c47577 100644 > --- a/drivers/spi/soft_spi.c > +++ b/drivers/spi/soft_spi.c > @@ -183,9 +183,15 @@ static int soft_spi_set_speed(struct udevice *dev, unsigned int speed) > static int soft_spi_set_mode(struct udevice *dev, unsigned int mode) > { > struct soft_spi_priv *priv = dev_get_priv(dev); > + struct soft_spi_platdata *plat = dev->platdata; > > priv->mode = mode; > > + if (!(mode & SPI_CS_HIGH)) > + plat->cs.flags |= GPIOD_ACTIVE_LOW; > + if (mode & SPI_CPOL) > + plat->sclk.flags |= GPIOD_ACTIVE_LOW; > + don't you need to manually set the initial state of CS and CLK now? This was previously done by gpio_request_by_name(). That's why the driver needed to know the low-active bits early. > return 0; > } > > @@ -210,18 +216,13 @@ static int soft_spi_ofdata_to_platdata(struct udevice *dev) > > static int soft_spi_probe(struct udevice *dev) > { > - struct spi_slave *slave = dev_get_parent_priv(dev); > struct soft_spi_platdata *plat = dev->platdata; > - int cs_flags, clk_flags; > int ret; > > - cs_flags = (slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW; > - clk_flags = (slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0; > - > if (gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs, > - GPIOD_IS_OUT | cs_flags) || > + GPIOD_IS_OUT) || > gpio_request_by_name(dev, "gpio-sck", 0, &plat->sclk, > - GPIOD_IS_OUT | clk_flags)) > + GPIOD_IS_OUT)) > return -EINVAL; > > ret = gpio_request_by_name(dev, "gpio-mosi", 0, &plat->mosi, > -- - Daniel ^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi. 2019-01-07 17:09 ` Daniel Schwierzeck @ 2019-01-07 19:29 ` Horatiu Vultur 0 siblings, 0 replies; 5+ messages in thread From: Horatiu Vultur @ 2019-01-07 19:29 UTC (permalink / raw) To: u-boot The 01/07/2019 18:09, Daniel Schwierzeck wrote: > > > Am 07.01.19 um 09:20 schrieb Horatiu Vultur: > > When probing soft_spi the result of dev_get_parent_priv(dev) in probe > > function is null ptr because the spi is on the ahb bus which has > > per_child_auto_alloc_size set to 0. Therefore it would generate an Ooops > > messages when accessing spi_slave structure. > > > > The fix consist of updating the soft_spi_platdata flags inside the > > .set_mode. > > > > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com> > > --- > > drivers/spi/soft_spi.c | 15 ++++++++------- > > 1 file changed, 8 insertions(+), 7 deletions(-) > > is this patch still required with https://patchwork.ozlabs.org/cover/1021335/ ? This patch is not required if you will take in https://patchwork.ozlabs.org/cover/1021335. > > > > > diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c > > index b06883f..2c47577 100644 > > --- a/drivers/spi/soft_spi.c > > +++ b/drivers/spi/soft_spi.c > > @@ -183,9 +183,15 @@ static int soft_spi_set_speed(struct udevice *dev, unsigned int speed) > > static int soft_spi_set_mode(struct udevice *dev, unsigned int mode) > > { > > struct soft_spi_priv *priv = dev_get_priv(dev); > > + struct soft_spi_platdata *plat = dev->platdata; > > > > priv->mode = mode; > > > > + if (!(mode & SPI_CS_HIGH)) > > + plat->cs.flags |= GPIOD_ACTIVE_LOW; > > + if (mode & SPI_CPOL) > > + plat->sclk.flags |= GPIOD_ACTIVE_LOW; > > + > > don't you need to manually set the initial state of CS and CLK now? This was previously done by > gpio_request_by_name(). That's why the driver needed to know the low-active bits early. No, because it is still using gpio_request_by_name() and that one will set the initial values for CS and CLK. And now in the .set_mode() we just update the CS and CLK, which is called before probing the spi. > > > return 0; > > } > > > > @@ -210,18 +216,13 @@ static int soft_spi_ofdata_to_platdata(struct udevice *dev) > > > > static int soft_spi_probe(struct udevice *dev) > > { > > - struct spi_slave *slave = dev_get_parent_priv(dev); > > struct soft_spi_platdata *plat = dev->platdata; > > - int cs_flags, clk_flags; > > int ret; > > > > - cs_flags = (slave->mode & SPI_CS_HIGH) ? 0 : GPIOD_ACTIVE_LOW; > > - clk_flags = (slave->mode & SPI_CPOL) ? GPIOD_ACTIVE_LOW : 0; > > - > > if (gpio_request_by_name(dev, "cs-gpios", 0, &plat->cs, > > - GPIOD_IS_OUT | cs_flags) || > > + GPIOD_IS_OUT) || > > gpio_request_by_name(dev, "gpio-sck", 0, &plat->sclk, > > - GPIOD_IS_OUT | clk_flags)) > > + GPIOD_IS_OUT)) > > return -EINVAL; > > > > ret = gpio_request_by_name(dev, "gpio-mosi", 0, &plat->mosi, > > > > -- > - Daniel -- /Horatiu ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-01-07 19:29 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-01-07 8:20 [U-Boot] [PATCH v2] spi: soft_spi: Fix for soft_spi Horatiu Vultur 2019-01-07 8:20 ` Horatiu Vultur 2019-01-07 8:20 ` [U-Boot] [PATCH v2] spi: soft_spi: Fix null ptr when probing soft_spi Horatiu Vultur 2019-01-07 17:09 ` Daniel Schwierzeck 2019-01-07 19:29 ` Horatiu Vultur
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox