diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index ca16bd3091bd..da4126863ecc 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -577,6 +577,8 @@ EXPORT_SYMBOL_GPL(__media_device_register); * media_device_unregister - unregister a media device * @mdev: The media device * + * It is safe to call this function on an unregistered + * (but initialised) media device. */ void media_device_unregister(struct media_device *mdev) { @@ -584,6 +586,10 @@ void media_device_unregister(struct media_device *mdev) struct media_entity *next; struct media_interface *intf, *tmp_intf; + /* Check if mdev was ever registered at all */ + if (!media_devnode_is_registered(&mdev->devnode)) + return; + /* Remove all entities from the media device */ list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list) media_device_unregister_entity(entity);