Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: Check for active links on pads with MEDIA_PAD_FL_MUST_CONNECT flag

Do not allow streaming if a pad with MEDIA_PAD_FL_MUST_CONNECT flag is not
connected by an active link.
This patch makes it possible to avoid drivers having to check for the most
common case of link state validation: a sink pad that must be connected.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Sakari Ailus and committed by
Mauro Carvalho Chehab
de49c285 d0700c51

+32 -5
+32 -5
drivers/media/media-entity.c
··· 235 235 media_entity_graph_walk_start(&graph, entity); 236 236 237 237 while ((entity = media_entity_graph_walk_next(&graph))) { 238 + DECLARE_BITMAP(active, entity->num_pads); 239 + DECLARE_BITMAP(has_no_links, entity->num_pads); 238 240 unsigned int i; 239 241 240 242 entity->stream_count++; ··· 250 248 if (!entity->ops || !entity->ops->link_validate) 251 249 continue; 252 250 251 + bitmap_zero(active, entity->num_pads); 252 + bitmap_fill(has_no_links, entity->num_pads); 253 + 253 254 for (i = 0; i < entity->num_links; i++) { 254 255 struct media_link *link = &entity->links[i]; 256 + struct media_pad *pad = link->sink->entity == entity 257 + ? link->sink : link->source; 255 258 256 - /* Is this pad part of an enabled link? */ 257 - if (!(link->flags & MEDIA_LNK_FL_ENABLED)) 258 - continue; 259 + /* Mark that a pad is connected by a link. */ 260 + bitmap_clear(has_no_links, pad->index, 1); 259 261 260 - /* Are we the sink or not? */ 261 - if (link->sink->entity != entity) 262 + /* 263 + * Pads that either do not need to connect or 264 + * are connected through an enabled link are 265 + * fine. 266 + */ 267 + if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) || 268 + link->flags & MEDIA_LNK_FL_ENABLED) 269 + bitmap_set(active, pad->index, 1); 270 + 271 + /* 272 + * Link validation will only take place for 273 + * sink ends of the link that are enabled. 274 + */ 275 + if (link->sink != pad || 276 + !(link->flags & MEDIA_LNK_FL_ENABLED)) 262 277 continue; 263 278 264 279 ret = entity->ops->link_validate(link); 265 280 if (ret < 0 && ret != -ENOIOCTLCMD) 266 281 goto error; 282 + } 283 + 284 + /* Either no links or validated links are fine. */ 285 + bitmap_or(active, active, has_no_links, entity->num_pads); 286 + 287 + if (!bitmap_full(active, entity->num_pads)) { 288 + ret = -EPIPE; 289 + goto error; 267 290 } 268 291 } 269 292