Skip to content

Commit

Permalink
media: platform: video-mux: Fix mutex locking
Browse files Browse the repository at this point in the history
The current order of locking between the driver mutex and the v4l2
subdev state lock causes a circuluar locking dependency when trying to
set up a link. Fix this.

Signed-off-by: Paul Elder <[email protected]>
Reviewed-by: Laurent Pinchart <[email protected]>
Signed-off-by: Kieran Bingham <[email protected]>
  • Loading branch information
Rahi374 authored and pelwell committed Oct 17, 2024
1 parent e03a63b commit cc0c868
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/media/platform/video-mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static int video_mux_link_setup(struct media_entity *entity,
{
struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
struct v4l2_subdev *source_sd;
struct v4l2_subdev_state *sd_state;
struct video_mux *vmux = v4l2_subdev_to_video_mux(sd);
u16 source_pad = entity->num_pads - 1;
int ret = 0;
Expand All @@ -85,10 +86,10 @@ static int video_mux_link_setup(struct media_entity *entity,
remote->entity->name, remote->index, local->entity->name,
local->index, flags & MEDIA_LNK_FL_ENABLED);

sd_state = v4l2_subdev_lock_and_get_active_state(sd);
mutex_lock(&vmux->lock);

if (flags & MEDIA_LNK_FL_ENABLED) {
struct v4l2_subdev_state *sd_state;
struct v4l2_mbus_framefmt *source_mbusformat;

if (vmux->active == local->index)
Expand All @@ -106,12 +107,10 @@ static int video_mux_link_setup(struct media_entity *entity,
vmux->active = local->index;

/* Propagate the active format to the source */
sd_state = v4l2_subdev_lock_and_get_active_state(sd);
source_mbusformat = v4l2_subdev_get_pad_format(sd, sd_state,
source_pad);
*source_mbusformat = *v4l2_subdev_get_pad_format(sd, sd_state,
vmux->active);
v4l2_subdev_unlock_state(sd_state);

source_sd = media_entity_to_v4l2_subdev(remote->entity);
vmux->subdev.ctrl_handler = source_sd->ctrl_handler;
Expand All @@ -129,6 +128,7 @@ static int video_mux_link_setup(struct media_entity *entity,

out:
mutex_unlock(&vmux->lock);
v4l2_subdev_unlock_state(sd_state);
return ret;
}

Expand Down

0 comments on commit cc0c868

Please sign in to comment.