Skip to content

Commit cc0c868

Browse files
Rahi374pelwell
authored andcommitted
media: platform: video-mux: Fix mutex locking
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]>
1 parent e03a63b commit cc0c868

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/media/platform/video-mux.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static int video_mux_link_setup(struct media_entity *entity,
7070
{
7171
struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
7272
struct v4l2_subdev *source_sd;
73+
struct v4l2_subdev_state *sd_state;
7374
struct video_mux *vmux = v4l2_subdev_to_video_mux(sd);
7475
u16 source_pad = entity->num_pads - 1;
7576
int ret = 0;
@@ -85,10 +86,10 @@ static int video_mux_link_setup(struct media_entity *entity,
8586
remote->entity->name, remote->index, local->entity->name,
8687
local->index, flags & MEDIA_LNK_FL_ENABLED);
8788

89+
sd_state = v4l2_subdev_lock_and_get_active_state(sd);
8890
mutex_lock(&vmux->lock);
8991

9092
if (flags & MEDIA_LNK_FL_ENABLED) {
91-
struct v4l2_subdev_state *sd_state;
9293
struct v4l2_mbus_framefmt *source_mbusformat;
9394

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

108109
/* Propagate the active format to the source */
109-
sd_state = v4l2_subdev_lock_and_get_active_state(sd);
110110
source_mbusformat = v4l2_subdev_get_pad_format(sd, sd_state,
111111
source_pad);
112112
*source_mbusformat = *v4l2_subdev_get_pad_format(sd, sd_state,
113113
vmux->active);
114-
v4l2_subdev_unlock_state(sd_state);
115114

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

130129
out:
131130
mutex_unlock(&vmux->lock);
131+
v4l2_subdev_unlock_state(sd_state);
132132
return ret;
133133
}
134134

0 commit comments

Comments
 (0)