1 From 5ad0d8d1172ffdbf289022ac3b8e4dc893531290 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 15 Jan 2024 00:30:02 +0200
4 Subject: media: mc: Add num_links flag to media_pad
6 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 [ Upstream commit baeddf94aa61879b118f2faa37ed126d772670cc ]
10 Maintain a counter of the links connected to a pad in the media_pad
11 structure. This helps checking if a pad is connected to anything, which
12 will be used in the pipeline building code.
14 Cc: stable@vger.kernel.org # 6.1
15 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
16 Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
17 Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
18 Signed-off-by: Sasha Levin <sashal@kernel.org>
20 drivers/media/mc/mc-entity.c | 6 ++++++
21 include/media/media-entity.h | 2 ++
22 2 files changed, 8 insertions(+)
24 diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
25 index 7839e3f68efa4..c2d8f59b62c12 100644
26 --- a/drivers/media/mc/mc-entity.c
27 +++ b/drivers/media/mc/mc-entity.c
28 @@ -1038,6 +1038,9 @@ static void __media_entity_remove_link(struct media_entity *entity,
30 /* Remove the reverse links for a data link. */
31 if ((link->flags & MEDIA_LNK_FL_LINK_TYPE) == MEDIA_LNK_FL_DATA_LINK) {
32 + link->source->num_links--;
33 + link->sink->num_links--;
35 if (link->source->entity == entity)
36 remote = link->sink->entity;
38 @@ -1143,6 +1146,9 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
42 + link->source->num_links++;
43 + link->sink->num_links++;
47 EXPORT_SYMBOL_GPL(media_create_pad_link);
48 diff --git a/include/media/media-entity.h b/include/media/media-entity.h
49 index 2b6cd343ee9e0..4d95893c89846 100644
50 --- a/include/media/media-entity.h
51 +++ b/include/media/media-entity.h
52 @@ -225,6 +225,7 @@ enum media_pad_signal_type {
53 * @graph_obj: Embedded structure containing the media object common data
54 * @entity: Entity this pad belongs to
55 * @index: Pad index in the entity pads array, numbered from 0 to n
56 + * @num_links: Number of links connected to this pad
57 * @sig_type: Type of the signal inside a media pad
58 * @flags: Pad flags, as defined in
59 * :ref:`include/uapi/linux/media.h <media_header>`
60 @@ -236,6 +237,7 @@ struct media_pad {
61 struct media_gobj graph_obj; /* must be first field in struct */
62 struct media_entity *entity;
65 enum media_pad_signal_type sig_type;