The struct device of the media device driver (i.e. not that of the media
devnode) is pointed to by the media device. The struct device pointer is
mostly used for debug prints.

Ensure it will stay around as long as the media device does.

Signed-off-by: Sakari Ailus <sakari.ai...@linux.intel.com>
---
 drivers/media/media-device.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index d534011..8c08839 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -726,6 +726,7 @@ static void media_device_release(struct media_devnode 
*devnode)
        mdev->entity_internal_idx_max = 0;
        media_entity_graph_walk_cleanup(&mdev->pm_count_walk);
        mutex_destroy(&mdev->graph_mutex);
+       put_device(mdev->dev);
 
        kfree(mdev);
 }
@@ -734,9 +735,15 @@ struct media_device *media_device_alloc(struct device *dev)
 {
        struct media_device *mdev;
 
+       dev = get_device(dev);
+       if (!dev)
+               return NULL;
+
        mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
-       if (!mdev)
+       if (!mdev) {
+               put_device(dev);
                return NULL;
+       }
 
        mdev->dev = dev;
        media_device_init(mdev);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to