spi: bitbang: Let spi_bitbang_start() take a reference to master
authorAxel Lin <axel.lin@ingics.com>
Tue, 10 Sep 2013 07:43:41 +0000 (15:43 +0800)
committerMark Brown <broonie@linaro.org>
Mon, 7 Oct 2013 13:50:43 +0000 (14:50 +0100)
commit702a4879ec337463f858c8ab467482cce260bf18
treee726356d57e6be815e201d12694a82c461a636e3
parentd0e639c9e06d44e713170031fe05fb60ebe680af
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>
18 files changed:
drivers/spi/spi-altera.c
drivers/spi/spi-ath79.c
drivers/spi/spi-au1550.c
drivers/spi/spi-bitbang.c
drivers/spi/spi-butterfly.c
drivers/spi/spi-davinci.c
drivers/spi/spi-efm32.c
drivers/spi/spi-fsl-dspi.c
drivers/spi/spi-gpio.c
drivers/spi/spi-imx.c
drivers/spi/spi-lm70llp.c
drivers/spi/spi-nuc900.c
drivers/spi/spi-oc-tiny.c
drivers/spi/spi-ppc4xx.c
drivers/spi/spi-s3c24xx.c
drivers/spi/spi-sh-sci.c
drivers/spi/spi-sirf.c
drivers/spi/spi-xilinx.c