Commit 0e43734d authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

media: v4l2-subdev: add release() internal op

If the subdevice created a device node, then the v4l2_subdev cannot
be freed until the last user of the device node closes it.

This means that we need a release() callback in v4l2_subdev_internal_ops
that is called from the video_device release function so the subdevice
driver can postpone freeing memory until the that callback is called.

If no video device node was created then the release callback can
be called immediately when the subdev is unregistered.
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent ea6c7e34
......@@ -216,10 +216,18 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
}
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
static void v4l2_subdev_release(struct v4l2_subdev *sd)
{
struct module *owner = !sd->owner_v4l2_dev ? sd->owner : NULL;
if (sd->internal_ops && sd->internal_ops->release)
sd->internal_ops->release(sd);
module_put(owner);
}
static void v4l2_device_release_subdev_node(struct video_device *vdev)
{
struct v4l2_subdev *sd = video_get_drvdata(vdev);
sd->devnode = NULL;
v4l2_subdev_release(video_get_drvdata(vdev));
kfree(vdev);
}
......@@ -318,8 +326,9 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
media_device_unregister_entity(&sd->entity);
}
#endif
video_unregister_device(sd->devnode);
if (!sd->owner_v4l2_dev)
module_put(sd->owner);
if (sd->devnode)
video_unregister_device(sd->devnode);
else
v4l2_subdev_release(sd);
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
......@@ -755,7 +755,17 @@ struct v4l2_subdev_ops {
*
* @open: called when the subdev device node is opened by an application.
*
* @close: called when the subdev device node is closed.
* @close: called when the subdev device node is closed. Please note that
* it is possible for @close to be called after @unregistered!
*
* @release: called when the last user of the subdev device is gone. This
* happens after the @unregistered callback and when the last open
* filehandle to the v4l-subdevX device node was closed. If no device
* node was created for this sub-device, then the @release callback
* is called right after the @unregistered callback.
* The @release callback is typically used to free the memory containing
* the v4l2_subdev structure. It is almost certainly required for any
* sub-device that sets the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
*
* .. note::
* Never call this from drivers, only the v4l2 framework can call
......@@ -766,6 +776,7 @@ struct v4l2_subdev_internal_ops {
void (*unregistered)(struct v4l2_subdev *sd);
int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
void (*release)(struct v4l2_subdev *sd);
};
#define V4L2_SUBDEV_NAME_SIZE 32
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment