media: mc: Add num_links flag to media_pad
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Sun, 14 Jan 2024 22:30:02 +0000 (00:30 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 5 Feb 2024 13:29:34 +0000 (14:29 +0100)
Maintain a counter of the links connected to a pad in the media_pad
structure. This helps checking if a pad is connected to anything, which
will be used in the pipeline building code.

Cc: stable@vger.kernel.org # 6.1
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/mc/mc-entity.c
include/media/media-entity.h

index 7839e3f68efa46deb563692303a0a4cd032429c1..c2d8f59b62c12597b7b83cf9cb3669a4493b33e6 100644 (file)
@@ -1038,6 +1038,9 @@ static void __media_entity_remove_link(struct media_entity *entity,
 
        /* Remove the reverse links for a data link. */
        if ((link->flags & MEDIA_LNK_FL_LINK_TYPE) == MEDIA_LNK_FL_DATA_LINK) {
+               link->source->num_links--;
+               link->sink->num_links--;
+
                if (link->source->entity == entity)
                        remote = link->sink->entity;
                else
@@ -1143,6 +1146,9 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
        sink->num_links++;
        source->num_links++;
 
+       link->source->num_links++;
+       link->sink->num_links++;
+
        return 0;
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
index c79176ed62999f7eb5d6107faf6077512c83101b..0393b23129eb9f2bc9415f29fc5d75030fc8f2b0 100644 (file)
@@ -225,6 +225,7 @@ enum media_pad_signal_type {
  * @graph_obj: Embedded structure containing the media object common data
  * @entity:    Entity this pad belongs to
  * @index:     Pad index in the entity pads array, numbered from 0 to n
+ * @num_links: Number of links connected to this pad
  * @sig_type:  Type of the signal inside a media pad
  * @flags:     Pad flags, as defined in
  *             :ref:`include/uapi/linux/media.h <media_header>`
@@ -236,6 +237,7 @@ struct media_pad {
        struct media_gobj graph_obj;    /* must be first field in struct */
        struct media_entity *entity;
        u16 index;
+       u16 num_links;
        enum media_pad_signal_type sig_type;
        unsigned long flags;