@@ -265,6 +265,12 @@ DMA
DRM
devm_drm_dev_init()
+DVB
+ devm_dvb_register_adapter()
+ devm_dvb_register_frontend()
+ devm_dvb_dmx_init()
+ devm_dvb_dmxdev_init()
+
GPIO
devm_gpiod_get()
devm_gpiod_get_index()
@@ -1444,6 +1444,19 @@ int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *dvb_adapter)
EXPORT_SYMBOL(dvb_dmxdev_init);
+static void dmxdev_release(void *dmxdev)
+{
+ dvb_dmxdev_release(dmxdev);
+}
+
+int devm_dvb_dmxdev_init(struct device *dev, struct dmxdev *dmxdev,
+ struct dvb_adapter *dvb_adapter)
+{
+ int rc = dvb_dmxdev_init(dmxdev, dvb_adapter);
+ return rc ? : devm_add_action_or_reset(dev, dmxdev_release, dmxdev);
+}
+EXPORT_SYMBOL(devm_dvb_dmxdev_init);
+
void dvb_dmxdev_release(struct dmxdev *dmxdev)
{
dmxdev->exit = 1;
@@ -28,6 +28,7 @@
#include <linux/string.h>
#include <linux/crc32.h>
#include <linux/uaccess.h>
+#include <linux/device.h>
#include <asm/div64.h>
#include <media/dvb_demux.h>
@@ -1317,6 +1318,18 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
EXPORT_SYMBOL(dvb_dmx_init);
+static void dmx_release(void *dvbdemux)
+{
+ dvb_dmx_release(dvbdemux);
+}
+
+int devm_dvb_dmx_init(struct device *dev, struct dvb_demux *dvbdemux)
+{
+ int rc = dvb_dmx_init(dvbdemux);
+ return rc ? : devm_add_action_or_reset(dev, dmx_release, dvbdemux);
+}
+EXPORT_SYMBOL(devm_dvb_dmx_init);
+
void dvb_dmx_release(struct dvb_demux *dvbdemux)
{
vfree(dvbdemux->cnt_storage);
@@ -3007,6 +3007,19 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
}
EXPORT_SYMBOL(dvb_register_frontend);
+static void unregister_frontend(void *fe)
+{
+ dvb_unregister_frontend(fe);
+}
+
+int devm_dvb_register_frontend(struct device *dev,
+ struct dvb_adapter *dvb, struct dvb_frontend *fe)
+{
+ int rc = dvb_register_frontend(dvb, fe);
+ return rc ? : devm_add_action_or_reset(dev, unregister_frontend, fe);
+}
+EXPORT_SYMBOL(devm_dvb_register_frontend);
+
int dvb_unregister_frontend(struct dvb_frontend *fe)
{
struct dvb_frontend_private *fepriv = fe->frontend_priv;
@@ -885,6 +885,18 @@ 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 rc = dvb_register_adapter(adap, name, module, dev, adapter_nums);
+ return rc ? : devm_add_action_or_reset(dev, unregister_adapter, adap);
+}
+EXPORT_SYMBOL(devm_dvb_register_adapter);
int dvb_unregister_adapter(struct dvb_adapter *adap)
{
@@ -204,6 +204,9 @@ struct dmxdev {
*/
int dvb_dmxdev_init(struct dmxdev *dmxdev, struct dvb_adapter *adap);
+int devm_dvb_dmxdev_init(struct device *dev, struct dmxdev *dmxdev,
+ struct dvb_adapter *dvb_adapter);
+
/**
* dvb_dmxdev_release - releases a digital TV demux and unregisters it.
*
@@ -266,6 +266,8 @@ struct dvb_demux {
*/
int dvb_dmx_init(struct dvb_demux *demux);
+int devm_dvb_dmx_init(struct device *dev, struct dvb_demux *demux);
+
/**
* dvb_dmx_release - releases a digital TV demux internal buffers.
*
@@ -713,6 +713,9 @@ struct dvb_frontend {
int dvb_register_frontend(struct dvb_adapter *dvb,
struct dvb_frontend *fe);
+int devm_dvb_register_frontend(struct device *dev,
+ struct dvb_adapter *dvb, struct dvb_frontend *fe);
+
/**
* dvb_unregister_frontend() - Unregisters a DVB frontend
*
@@ -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
*
Provide devm variants for automatic resource release on device removal. Makes error-handling in probe() much simpler, thus less error-prone. And once all resources are devmanaged, remove() is no longer needed. Signed-off-by: Marc Gonzalez <marc.w.gonzalez@free.fr> --- Changes from v1: x Simplify devm_dvb_register_adapter() implementation x Add 3 more devm APIs x Document them in devres.rst --- Documentation/driver-model/devres.rst | 6 ++++++ drivers/media/dvb-core/dmxdev.c | 13 +++++++++++++ drivers/media/dvb-core/dvb_demux.c | 13 +++++++++++++ drivers/media/dvb-core/dvb_frontend.c | 13 +++++++++++++ drivers/media/dvb-core/dvbdev.c | 12 ++++++++++++ include/media/dmxdev.h | 3 +++ include/media/dvb_demux.h | 2 ++ include/media/dvb_frontend.h | 3 +++ include/media/dvbdev.h | 3 +++ 9 files changed, 68 insertions(+)