diff mbox series

[05/14] firmware: scmi: factorize scmi transport look up

Message ID 20220513062622.155433-6-etienne.carriere@linaro.org
State Superseded
Headers show
Series SCMI multi-channel and optee shm | expand

Commit Message

Etienne Carriere May 13, 2022, 6:26 a.m. UTC
Defines local helper function find_scmi_transport_device() with the
instructions to find the SCMI transport device from a SCMI protocol
device.

Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
---
 drivers/firmware/scmi/scmi_agent-uclass.c | 26 +++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c
index c9c9c00384a..f7fa5df214c 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -109,6 +109,20 @@  static int scmi_bind_protocols(struct udevice *dev)
 	return ret;
 }
 
+static struct udevice *find_scmi_transport_device(struct udevice *dev)
+{
+	struct udevice *parent = dev;
+
+	do {
+		parent = dev_get_parent(parent);
+	} while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT);
+
+	if (!parent)
+		dev_err(dev, "Invalid SCMI device, agent not found\n");
+
+	return parent;
+}
+
 static const struct scmi_agent_ops *transport_dev_ops(struct udevice *dev)
 {
 	return (const struct scmi_agent_ops *)dev->driver->ops;
@@ -118,17 +132,11 @@  int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel,
 			  struct scmi_msg *msg)
 {
 	const struct scmi_agent_ops *ops;
-	struct udevice *parent = dev;
+	struct udevice *parent;
 
-	/* Find related SCMI agent device */
-	do {
-		parent = dev_get_parent(parent);
-	} while (parent && device_get_uclass_id(parent) != UCLASS_SCMI_AGENT);
-
-	if (!parent) {
-		dev_err(dev, "Invalid SCMI device, agent not found\n");
+	parent = find_scmi_transport_device(dev);
+	if (!parent)
 		return -ENODEV;
-	}
 
 	ops = transport_dev_ops(parent);