* [PATCH 0/2] staging: fbtft: Avoid calling SPI master setup directly
@ 2015-08-25 21:04 Stefan Wahren
2015-08-25 21:04 ` [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection Stefan Wahren
2015-08-25 21:04 ` [PATCH 2/2] staging: fbtft: replace master->setup() with spi_setup() Stefan Wahren
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Wahren @ 2015-08-25 21:04 UTC (permalink / raw)
To: Noralf Trønnes, Thomas Petazzoni
Cc: Greg Kroah-Hartman, Henri Chain, linux-kernel, devel,
Stefan Wahren
This patch series fixes issues caused by calling SPI master setup function
directly.
Changes since RFC:
* use only bits_per_word_mask for 9-bit support detection
(suggested by Noralf Trønnes)
* change patch order
Stefan Wahren (2):
staging: fbtft: fix 9-bit SPI support detection
staging: fbtft: replace master->setup() with spi_setup()
drivers/staging/fbtft/fb_uc1611.c | 2 +-
drivers/staging/fbtft/fb_watterott.c | 4 ++--
drivers/staging/fbtft/fbtft-core.c | 10 +++-------
drivers/staging/fbtft/flexfb.c | 11 ++++-------
4 files changed, 10 insertions(+), 17 deletions(-)
--
1.7.9.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection
2015-08-25 21:04 [PATCH 0/2] staging: fbtft: Avoid calling SPI master setup directly Stefan Wahren
@ 2015-08-25 21:04 ` Stefan Wahren
2015-08-25 22:07 ` Noralf Trønnes
2015-08-25 21:04 ` [PATCH 2/2] staging: fbtft: replace master->setup() with spi_setup() Stefan Wahren
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Wahren @ 2015-08-25 21:04 UTC (permalink / raw)
To: Noralf Trønnes, Thomas Petazzoni
Cc: Greg Kroah-Hartman, Henri Chain, linux-kernel, devel,
Stefan Wahren
Since the result of the setup function isn't adequate to check
9-bit SPI support, we better check bits_per_word_mask. Btw this
change avoids a NULL pointer dereference with master drivers
without a separate setup function.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/staging/fbtft/fbtft-core.c | 10 +++-------
drivers/staging/fbtft/flexfb.c | 11 ++++-------
2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 23392eb..7f5fa3d 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -1436,15 +1436,11 @@ int fbtft_probe_common(struct fbtft_display *display,
/* 9-bit SPI setup */
if (par->spi && display->buswidth == 9) {
- par->spi->bits_per_word = 9;
- ret = par->spi->master->setup(par->spi);
- if (ret) {
+ if (par->spi->master->bits_per_word_mask & SPI_BPW_MASK(9)) {
+ par->spi->bits_per_word = 9;
+ } else {
dev_warn(&par->spi->dev,
"9-bit SPI not available, emulating using 8-bit.\n");
- par->spi->bits_per_word = 8;
- ret = par->spi->master->setup(par->spi);
- if (ret)
- goto out_release;
/* allocate buffer with room for dc bits */
par->extra = devm_kzalloc(par->info->device,
par->txbuf.len + (par->txbuf.len / 8) + 8,
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
index c763efc..3f380a0 100644
--- a/drivers/staging/fbtft/flexfb.c
+++ b/drivers/staging/fbtft/flexfb.c
@@ -463,15 +463,12 @@ static int flexfb_probe_common(struct spi_device *sdev,
}
par->fbtftops.write_register = fbtft_write_reg8_bus9;
par->fbtftops.write_vmem = fbtft_write_vmem16_bus9;
- sdev->bits_per_word = 9;
- ret = sdev->master->setup(sdev);
- if (ret) {
+ if (par->spi->master->bits_per_word_mask
+ & SPI_BPW_MASK(9)) {
+ par->spi->bits_per_word = 9;
+ } else {
dev_warn(dev,
"9-bit SPI not available, emulating using 8-bit.\n");
- sdev->bits_per_word = 8;
- ret = sdev->master->setup(sdev);
- if (ret)
- goto out_release;
/* allocate buffer with room for dc bits */
par->extra = devm_kzalloc(par->info->device,
par->txbuf.len + (par->txbuf.len / 8) + 8,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] staging: fbtft: replace master->setup() with spi_setup()
2015-08-25 21:04 [PATCH 0/2] staging: fbtft: Avoid calling SPI master setup directly Stefan Wahren
2015-08-25 21:04 ` [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection Stefan Wahren
@ 2015-08-25 21:04 ` Stefan Wahren
1 sibling, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2015-08-25 21:04 UTC (permalink / raw)
To: Noralf Trønnes, Thomas Petazzoni
Cc: Greg Kroah-Hartman, Henri Chain, linux-kernel, devel,
Stefan Wahren
Calling the setup of the SPI master directly causes a NULL pointer
dereference with master drivers without a separate setup function.
This problem is reproduceable on ARM MXS platform.
So fix this issue by using spi_setup() instead.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/staging/fbtft/fb_uc1611.c | 2 +-
drivers/staging/fbtft/fb_watterott.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/fbtft/fb_uc1611.c b/drivers/staging/fbtft/fb_uc1611.c
index 32f3a9d..5cafa50 100644
--- a/drivers/staging/fbtft/fb_uc1611.c
+++ b/drivers/staging/fbtft/fb_uc1611.c
@@ -76,7 +76,7 @@ static int init_display(struct fbtft_par *par)
/* Set CS active high */
par->spi->mode |= SPI_CS_HIGH;
- ret = par->spi->master->setup(par->spi);
+ ret = spi_setup(par->spi);
if (ret) {
dev_err(par->info->device, "Could not set SPI_CS_HIGH\n");
return ret;
diff --git a/drivers/staging/fbtft/fb_watterott.c b/drivers/staging/fbtft/fb_watterott.c
index 88fb2c0..8eae6ef 100644
--- a/drivers/staging/fbtft/fb_watterott.c
+++ b/drivers/staging/fbtft/fb_watterott.c
@@ -169,7 +169,7 @@ static int init_display(struct fbtft_par *par)
/* enable SPI interface by having CS and MOSI low during reset */
save_mode = par->spi->mode;
par->spi->mode |= SPI_CS_HIGH;
- ret = par->spi->master->setup(par->spi); /* set CS inactive low */
+ ret = spi_setup(par->spi); /* set CS inactive low */
if (ret) {
dev_err(par->info->device, "Could not set SPI_CS_HIGH\n");
return ret;
@@ -180,7 +180,7 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
mdelay(1000);
par->spi->mode = save_mode;
- ret = par->spi->master->setup(par->spi);
+ ret = spi_setup(par->spi);
if (ret) {
dev_err(par->info->device, "Could not restore SPI mode\n");
return ret;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection
2015-08-25 21:04 ` [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection Stefan Wahren
@ 2015-08-25 22:07 ` Noralf Trønnes
0 siblings, 0 replies; 4+ messages in thread
From: Noralf Trønnes @ 2015-08-25 22:07 UTC (permalink / raw)
To: Stefan Wahren, Thomas Petazzoni
Cc: Greg Kroah-Hartman, Henri Chain, linux-kernel, devel
Den 25.08.2015 23:04, skrev Stefan Wahren:
> Since the result of the setup function isn't adequate to check
> 9-bit SPI support, we better check bits_per_word_mask. Btw this
> change avoids a NULL pointer dereference with master drivers
> without a separate setup function.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> drivers/staging/fbtft/fbtft-core.c | 10 +++-------
> drivers/staging/fbtft/flexfb.c | 11 ++++-------
> 2 files changed, 7 insertions(+), 14 deletions(-)
Thanks Stefan.
Both patches:
Acked-by: Noralf Trønnes <noralf@tronnes.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-25 22:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-25 21:04 [PATCH 0/2] staging: fbtft: Avoid calling SPI master setup directly Stefan Wahren
2015-08-25 21:04 ` [PATCH 1/2] staging: fbtft: fix 9-bit SPI support detection Stefan Wahren
2015-08-25 22:07 ` Noralf Trønnes
2015-08-25 21:04 ` [PATCH 2/2] staging: fbtft: replace master->setup() with spi_setup() Stefan Wahren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox