diff options
author | Mark Brown <broonie@linaro.org> | 2013-09-16 19:59:54 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-09-16 19:59:54 -0400 |
commit | fbce71cae72f9f8fd1f2d00e0d47d6cc5f74e2e1 (patch) | |
tree | a883297030b85f1fca55bd6b3c787d9f0753c999 /drivers | |
parent | 50c959fc3366693174cdf3f1c82d0c01bbee926f (diff) | |
parent | 666d5b4c742ba666eb68b467d777b7862f362ae5 (diff) |
Merge remote-tracking branch 'spi/topic/devm' into spi-s3c64xx
Diffstat (limited to 'drivers')
-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: | |||
1245 | } | 1245 | } |
1246 | EXPORT_SYMBOL_GPL(spi_register_master); | 1246 | EXPORT_SYMBOL_GPL(spi_register_master); |
1247 | 1247 | ||
1248 | static void devm_spi_unregister(struct device *dev, void *res) | ||
1249 | { | ||
1250 | spi_unregister_master(*(struct spi_master **)res); | ||
1251 | } | ||
1252 | |||
1253 | /** | ||
1254 | * dev_spi_register_master - register managed SPI master controller | ||
1255 | * @dev: device managing SPI master | ||
1256 | * @master: initialized master, originally from spi_alloc_master() | ||
1257 | * Context: can sleep | ||
1258 | * | ||
1259 | * Register a SPI device as with spi_register_master() which will | ||
1260 | * automatically be unregister | ||
1261 | */ | ||
1262 | int devm_spi_register_master(struct device *dev, struct spi_master *master) | ||
1263 | { | ||
1264 | struct spi_master **ptr; | ||
1265 | int ret; | ||
1266 | |||
1267 | ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); | ||
1268 | if (!ptr) | ||
1269 | return -ENOMEM; | ||
1270 | |||
1271 | ret = spi_register_master(master); | ||
1272 | if (ret != 0) { | ||
1273 | *ptr = master; | ||
1274 | devres_add(dev, ptr); | ||
1275 | } else { | ||
1276 | devres_free(ptr); | ||
1277 | } | ||
1278 | |||
1279 | return ret; | ||
1280 | } | ||
1281 | EXPORT_SYMBOL_GPL(devm_spi_register_master); | ||
1282 | |||
1248 | static int __unregister(struct device *dev, void *null) | 1283 | static int __unregister(struct device *dev, void *null) |
1249 | { | 1284 | { |
1250 | spi_unregister_device(to_spi_device(dev)); | 1285 | spi_unregister_device(to_spi_device(dev)); |