• Tomi Valkeinen's avatar
    media: subdev: add subdev state locking · ed647ea6
    Tomi Valkeinen authored
    The V4L2 subdevs have managed without centralized locking for the state
    (previously pad_config), as the try-state is supposedly safe (although I
    believe two TRY ioctls for the same fd would race), and the
    active-state, and its locking, is managed by the drivers internally.
    
    We now have active-state in a centralized position, and need locking.
    Strictly speaking the locking is only needed for new drivers that use
    the new state, as the current drivers continue behaving as they used to.
    
    However, active-state locking is complicated by the fact that currently
    the real active-state of a subdev is split into multiple parts: the new
    v4l2_subdev_state, subdev control state, and subdev's internal state.
    
    In the future all these three states should be combined into one state
    (the v4l2_subdev_state), and then a single lock for the state should be
    sufficient.
    
    But to solve the current split-state situation we need to share locks
    between the three states. This is accomplished by using the same lock
    management as the control handler does: we use a pointer to a mutex,
    allowing the driver to override the default mutex. Thus the driver can
    do e.g.:
    
    sd->state_lock = sd->ctrl_handler->lock;
    
    before calling v4l2_subdev_init_finalize(), resulting in sharing the
    same lock between the states and the controls.
    
    The locking model for active-state is such that any subdev op that gets
    the state as a parameter expects the state to be already locked by the
    caller, and expects the caller to release the lock.
    Signed-off-by: default avatarTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
    Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
    Reviewed-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
    ed647ea6
v4l2-subdev.c 25.2 KB