diff options
author | Axel Lin <axel.lin@ingics.com> | 2013-09-10 15:43:41 +0800 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-09-17 12:56:14 +0100 |
commit | 94c69f765f1b4a658d96905ec59928e3e3e07e6a (patch) | |
tree | cfa1fffd3906bff17eed2e9771f2c33fd55877af /drivers/spi/spi-butterfly.c | |
parent | 272b98c6455f00884f0350f775c5342358ebb73f (diff) | |
download | lwn-94c69f765f1b4a658d96905ec59928e3e3e07e6a.tar.gz lwn-94c69f765f1b4a658d96905ec59928e3e3e07e6a.zip |
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-butterfly.c')
-rw-r--r-- | drivers/spi/spi-butterfly.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/spi/spi-butterfly.c b/drivers/spi/spi-butterfly.c index 5ed08e537433..b1ecea2d76b3 100644 --- a/drivers/spi/spi-butterfly.c +++ b/drivers/spi/spi-butterfly.c @@ -225,7 +225,7 @@ static void butterfly_attach(struct parport *p) master->bus_num = 42; master->num_chipselect = 2; - pp->bitbang.master = spi_master_get(master); + pp->bitbang.master = master; pp->bitbang.chipselect = butterfly_chipselect; pp->bitbang.txrx_word[SPI_MODE_0] = butterfly_txrx_word_mode0; |