]> git.karo-electronics.de Git - linux-beck.git/commit
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>
Tue, 17 Sep 2013 11:56:14 +0000 (12:56 +0100)
commit94c69f765f1b4a658d96905ec59928e3e3e07e6a
treecfa1fffd3906bff17eed2e9771f2c33fd55877af
parent272b98c6455f00884f0350f775c5342358ebb73f
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