diff options
author | Mark Brown <broonie@linaro.org> | 2013-09-17 00:59:54 +0100 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-09-17 00:59:54 +0100 |
commit | fbce71cae72f9f8fd1f2d00e0d47d6cc5f74e2e1 (patch) | |
tree | a883297030b85f1fca55bd6b3c787d9f0753c999 /drivers/spi | |
parent | 50c959fc3366693174cdf3f1c82d0c01bbee926f (diff) | |
parent | 666d5b4c742ba666eb68b467d777b7862f362ae5 (diff) | |
download | blackbird-op-linux-fbce71cae72f9f8fd1f2d00e0d47d6cc5f74e2e1.tar.gz blackbird-op-linux-fbce71cae72f9f8fd1f2d00e0d47d6cc5f74e2e1.zip |
Merge remote-tracking branch 'spi/topic/devm' into spi-s3c64xx
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9e039c60c068..a586ceb111fc 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1245,6 +1245,41 @@ done: } EXPORT_SYMBOL_GPL(spi_register_master); +static void devm_spi_unregister(struct device *dev, void *res) +{ + spi_unregister_master(*(struct spi_master **)res); +} + +/** + * dev_spi_register_master - register managed SPI master controller + * @dev: device managing SPI master + * @master: initialized master, originally from spi_alloc_master() + * Context: can sleep + * + * Register a SPI device as with spi_register_master() which will + * automatically be unregister + */ +int devm_spi_register_master(struct device *dev, struct spi_master *master) +{ + struct spi_master **ptr; + int ret; + + ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = spi_register_master(master); + if (ret != 0) { + *ptr = master; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_spi_register_master); + static int __unregister(struct device *dev, void *null) { spi_unregister_device(to_spi_device(dev)); |