Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: fbtft: fix 9-bit SPI support detection

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>
Acked-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Stefan Wahren and committed by
Greg Kroah-Hartman
cabb5b2a d98229f0

+7 -14
+3 -7
drivers/staging/fbtft/fbtft-core.c
··· 1436 1436 1437 1437 /* 9-bit SPI setup */ 1438 1438 if (par->spi && display->buswidth == 9) { 1439 - par->spi->bits_per_word = 9; 1440 - ret = par->spi->master->setup(par->spi); 1441 - if (ret) { 1439 + if (par->spi->master->bits_per_word_mask & SPI_BPW_MASK(9)) { 1440 + par->spi->bits_per_word = 9; 1441 + } else { 1442 1442 dev_warn(&par->spi->dev, 1443 1443 "9-bit SPI not available, emulating using 8-bit.\n"); 1444 - par->spi->bits_per_word = 8; 1445 - ret = par->spi->master->setup(par->spi); 1446 - if (ret) 1447 - goto out_release; 1448 1444 /* allocate buffer with room for dc bits */ 1449 1445 par->extra = devm_kzalloc(par->info->device, 1450 1446 par->txbuf.len + (par->txbuf.len / 8) + 8,
+4 -7
drivers/staging/fbtft/flexfb.c
··· 463 463 } 464 464 par->fbtftops.write_register = fbtft_write_reg8_bus9; 465 465 par->fbtftops.write_vmem = fbtft_write_vmem16_bus9; 466 - sdev->bits_per_word = 9; 467 - ret = sdev->master->setup(sdev); 468 - if (ret) { 466 + if (par->spi->master->bits_per_word_mask 467 + & SPI_BPW_MASK(9)) { 468 + par->spi->bits_per_word = 9; 469 + } else { 469 470 dev_warn(dev, 470 471 "9-bit SPI not available, emulating using 8-bit.\n"); 471 - sdev->bits_per_word = 8; 472 - ret = sdev->master->setup(sdev); 473 - if (ret) 474 - goto out_release; 475 472 /* allocate buffer with room for dc bits */ 476 473 par->extra = devm_kzalloc(par->info->device, 477 474 par->txbuf.len + (par->txbuf.len / 8) + 8,