aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-gpio.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2013-09-10 03:43:41 -0400
committerMark Brown <broonie@linaro.org>2013-09-17 07:56:14 -0400
commit94c69f765f1b4a658d96905ec59928e3e3e07e6a (patch)
treecfa1fffd3906bff17eed2e9771f2c33fd55877af /drivers/spi/spi-gpio.c
parent272b98c6455f00884f0350f775c5342358ebb73f (diff)
spi: bitbang: Let spi_bitbang_start() take a reference to master
Many drivers that use bitbang library have a leak on probe error paths. This is because once a spi_master_get() call succeeds, we need an additional spi_master_put() call to free the memory. Fix this issue by moving the code taking a reference to master to spi_bitbang_start(), so spi_bitbang_start() will take a reference to master on success. With this change, the caller is responsible for calling spi_bitbang_stop() to decrement the reference and spi_master_put() as counterpart of spi_alloc_master() to prevent a memory leak. So now we have below patten for drivers using bitbang library: probe: spi_alloc_master -> Init reference count to 1 spi_bitbang_start -> Increment reference count remove: spi_bitbang_stop -> Decrement reference count spi_master_put -> Decrement reference count (reference count reaches 0) Fixup all users accordingly. Signed-off-by: Axel Lin <axel.lin@ingics.com> Suggested-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> Acked-by: Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/spi/spi-gpio.c')
-rw-r--r--drivers/spi/spi-gpio.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 68b69fec13a9..14c01b44ca7a 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -467,7 +467,7 @@ static int spi_gpio_probe(struct platform_device *pdev)
467 } 467 }
468#endif 468#endif
469 469
470 spi_gpio->bitbang.master = spi_master_get(master); 470 spi_gpio->bitbang.master = master;
471 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 471 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
472 472
473 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { 473 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) {
@@ -486,7 +486,6 @@ static int spi_gpio_probe(struct platform_device *pdev)
486 486
487 status = spi_bitbang_start(&spi_gpio->bitbang); 487 status = spi_bitbang_start(&spi_gpio->bitbang);
488 if (status < 0) { 488 if (status < 0) {
489 spi_master_put(spi_gpio->bitbang.master);
490gpio_free: 489gpio_free:
491 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) 490 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
492 gpio_free(SPI_MISO_GPIO); 491 gpio_free(SPI_MISO_GPIO);
@@ -510,13 +509,13 @@ static int spi_gpio_remove(struct platform_device *pdev)
510 509
511 /* stop() unregisters child devices too */ 510 /* stop() unregisters child devices too */
512 status = spi_bitbang_stop(&spi_gpio->bitbang); 511 status = spi_bitbang_stop(&spi_gpio->bitbang);
513 spi_master_put(spi_gpio->bitbang.master);
514 512
515 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) 513 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
516 gpio_free(SPI_MISO_GPIO); 514 gpio_free(SPI_MISO_GPIO);
517 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) 515 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
518 gpio_free(SPI_MOSI_GPIO); 516 gpio_free(SPI_MOSI_GPIO);
519 gpio_free(SPI_SCK_GPIO); 517 gpio_free(SPI_SCK_GPIO);
518 spi_master_put(spi_gpio->bitbang.master);
520 519
521 return status; 520 return status;
522} 521}