diff options
author | Mark Brown <broonie@linaro.org> | 2013-10-11 20:10:13 +0100 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-10-11 20:10:13 +0100 |
commit | 2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46 (patch) | |
tree | f50c505d9811d6fa2d9c042f2fdfa7ebcf79e158 /drivers/spi/spi.c | |
parent | b158935f70b9c156903338053216dd0adf7ce31c (diff) | |
parent | ebd805cc14bec607e74795b7933570f240508cb4 (diff) | |
download | linux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.tar.gz linux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.tar.bz2 linux-2cc6e2e0c8157b9e6ed8dbe5c7284865f6afbd46.zip |
Merge remote-tracking branch 'spi/topic/s3c64xx' into spi-loop
Diffstat (limited to 'drivers/spi/spi.c')
-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 85c18d8a86b3..f37356c26b7d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1370,6 +1370,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)); |