lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220525190617.696344-17-paul.kocialkowski@bootlin.com>
Date:   Wed, 25 May 2022 21:05:49 +0200
From:   Paul Kocialkowski <paul.kocialkowski@...tlin.com>
To:     linux-kernel@...r.kernel.org, linux-media@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-sunxi@...ts.linux.dev
Cc:     Yong Deng <yong.deng@...ewell.com>,
        Paul Kocialkowski <paul.kocialkowski@...tlin.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Chen-Yu Tsai <wens@...e.org>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        Samuel Holland <samuel@...lland.org>,
        Laurent Pinchart <laurent.pinchart@...asonboard.com>,
        Maxime Ripard <mripard@...nel.org>,
        Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: [PATCH v5 16/44] media: media-entity: Add helper to get a single enabled link

In a situation where multiple links can be connected to the same
pad of an entity, drivers might need to ensure that only a single
link is enabled to apply appropriate routing (when the hardware can
only use one at a time).

Add a helper to return the single enabled link of an entity given
a specific pad index, which errors out when zero or more than one
link candidates are found.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@...tlin.com>
---
 drivers/media/mc/mc-entity.c | 26 ++++++++++++++++++++++++++
 include/media/media-entity.h | 13 +++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index 11f5207f73aa..5387bd5f4cd7 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -900,6 +900,32 @@ media_entity_find_link(struct media_pad *source, struct media_pad *sink)
 }
 EXPORT_SYMBOL_GPL(media_entity_find_link);
 
+struct media_link *
+media_entity_get_single_enabled_link(struct media_entity *entity,
+				     u16 pad_index)
+{
+	struct media_link *candidate = ERR_PTR(-ENODEV);
+	struct media_link *link;
+
+	list_for_each_entry(link, &entity->links, list) {
+		struct media_pad *pad = link->sink->entity == entity ?
+					link->sink : link->source;
+
+		if (pad->index != pad_index ||
+		    !(link->flags & MEDIA_LNK_FL_ENABLED))
+			continue;
+
+		/* Error out with more than a single candidate. */
+		if (candidate != ERR_PTR(-ENODEV))
+			return ERR_PTR(-ENXIO);
+
+		candidate = link;
+	}
+
+	return candidate;
+}
+EXPORT_SYMBOL_GPL(media_entity_get_single_enabled_link);
+
 struct media_pad *media_entity_remote_pad(const struct media_pad *pad)
 {
 	struct media_link *link;
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index a9a1c0ec5d1c..63c1436ffacf 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -847,6 +847,19 @@ int media_entity_setup_link(struct media_link *link, u32 flags);
 struct media_link *media_entity_find_link(struct media_pad *source,
 		struct media_pad *sink);
 
+/**
+ * media_entity_get_single_enabled_link - Get a single link for an entity pad
+ * @entity: The entity
+ * @pad_index: The index of the entity's pad expected to take part in link
+ *
+ * Return: returns a pointer to the single enabled link with the entity's pad.
+ * If no such link exists, returns a pointer error with %-ENODEV.
+ * If more than a single link exist, returns a pointer error with %-ENXIO.
+ */
+struct media_link *
+media_entity_get_single_enabled_link(struct media_entity *entity,
+				     u16 pad_index);
+
 /**
  * media_entity_remote_pad - Find the pad at the remote end of a link
  * @pad: Pad at the local end of the link
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ