Add devm* variant for automagic resource release. --- drivers/media/dvb-core/dvbdev.c | 21 +++++++++++++++++++++ include/media/dvbdev.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c index a3393cd4e584..c7a5302e8840 100644 --- a/drivers/media/dvb-core/dvbdev.c +++ b/drivers/media/dvb-core/dvbdev.c @@ -885,6 +885,27 @@ int dvb_register_adapter(struct dvb_adapter *adap, const char *name, } EXPORT_SYMBOL(dvb_register_adapter); +static void unregister_adapter(void *adap) +{ + dvb_unregister_adapter(adap); +} + +int devm_dvb_register_adapter(struct device *dev, struct dvb_adapter *adap, + const char *name, struct module *module, short *adapter_nums) +{ + int v1, v2; + + v1 = dvb_register_adapter(adap, name, module, dev, adapter_nums); + if (v1 < 0) + return v1; + + v2 = devm_add_action_or_reset(dev, unregister_adapter, adap); + if (v2 < 0) + return v2; + + return v1; +} +EXPORT_SYMBOL(devm_dvb_register_adapter); int dvb_unregister_adapter(struct dvb_adapter *adap) { diff --git a/include/media/dvbdev.h b/include/media/dvbdev.h index 551325858de3..32f8d1626319 100644 --- a/include/media/dvbdev.h +++ b/include/media/dvbdev.h @@ -202,6 +202,9 @@ int dvb_register_adapter(struct dvb_adapter *adap, const char *name, struct module *module, struct device *device, short *adapter_nums); +int devm_dvb_register_adapter(struct device *dev, struct dvb_adapter *adap, + const char *name, struct module *module, short *adapter_nums); + /** * dvb_unregister_adapter - Unregisters a DVB adapter * -- 2.17.1