Add media_device_unregister_put() interface to release reference to a media device allocated using the Media Device Allocator API. The media device is unregistered and freed when the last driver that holds the reference to the media device releases the reference. The media device is unregistered and freed in the kref put handler. Signed-off-by: Shuah Khan <shuahkh@xxxxxxxxxxxxxxx> --- drivers/media/media-device.c | 11 +++++++++++ include/media/media-device.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 33a9952..b5c279a 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -36,6 +36,7 @@ #include <media/media-device.h> #include <media/media-devnode.h> #include <media/media-entity.h> +#include <media/media-dev-allocator.h> #ifdef CONFIG_MEDIA_CONTROLLER @@ -818,6 +819,16 @@ void media_device_unregister(struct media_device *mdev) } EXPORT_SYMBOL_GPL(media_device_unregister); +void media_device_unregister_put(struct media_device *mdev) +{ + if (mdev == NULL) + return; + + dev_dbg(mdev->dev, "%s: mdev %p\n", __func__, mdev); + media_device_put(mdev); +} +EXPORT_SYMBOL_GPL(media_device_unregister_put); + static void media_device_release_devres(struct device *dev, void *res) { } diff --git a/include/media/media-device.h b/include/media/media-device.h index f743ae2..8bd836e 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -499,6 +499,18 @@ int __must_check __media_device_register(struct media_device *mdev, void media_device_unregister(struct media_device *mdev); /** + * media_device_unregister_put() - Unregisters a media device element + * + * @mdev: pointer to struct &media_device + * + * Should be called to unregister media device allocated with Media Device + * Allocator API media_device_get() interface. + * It is safe to call this function on an unregistered (but initialised) + * media device. + */ +void media_device_unregister_put(struct media_device *mdev); + +/** * media_device_register_entity() - registers a media entity inside a * previously registered media device. * @@ -658,6 +670,9 @@ static inline int media_device_register(struct media_device *mdev) static inline void media_device_unregister(struct media_device *mdev) { } +static inline void media_device_unregister_put(struct media_device *mdev) +{ +} static inline int media_device_register_entity(struct media_device *mdev, struct media_entity *entity) { -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html