The MPFS system controller run_service() helper only submits the mailbox
request but does not read back the response data. However, the caller
must explicitly receive the response.

Add a public system controller helper to receive mailbox service
responses to populate the response buffer after issuing a system
controller request.

Without this, the drivers copy uninitialised stack data instead of
mailbox response data, resulting in deterministic output.

Signed-off-by: Jamie Gibbons <[email protected]>
---
 drivers/misc/mpfs_syscontroller.c | 28 ++++++++++++++++++++++++----
 include/mpfs-mailbox.h            |  1 +
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/mpfs_syscontroller.c 
b/drivers/misc/mpfs_syscontroller.c
index f608d5518b0..61d6780f0b9 100644
--- a/drivers/misc/mpfs_syscontroller.c
+++ b/drivers/misc/mpfs_syscontroller.c
@@ -85,6 +85,28 @@ int mpfs_syscontroller_run_service(struct 
mpfs_syscontroller_priv *sys_controlle
 }
 EXPORT_SYMBOL_GPL(mpfs_syscontroller_run_service);
 
+/**
+ * mpfs_syscontroller_recv_response() - Receive the MPFS system service 
response
+ * @sys_controller:    MPFS system controller instance
+ * @msg:                       System service message
+ * @timeout_ms:                Timeout in milliseconds
+ * 
+ * Receive the mailbox response for a previously issued MPFS system
+ * controller service request and populate the response buffer.
+ * 
+ * Return: 0 if all goes good, else appropriate error message.
+ */
+int mpfs_syscontroller_recv_response(struct mpfs_syscontroller_priv 
*sys_controller, struct mpfs_mss_msg *msg, unsigned long timeout_ms)
+{
+       int ret;
+
+       ret = mbox_recv(&sys_controller->chan, msg, timeout_ms);
+       if (ret)
+               dev_err(sys_controller->chan.dev, "Service failed: %d, abort. 
Failure: %u\n", ret, msg->response->resp_status);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(mpfs_syscontroller_recv_response);
+
 /**
  * mpfs_syscontroller_read_sernum() - Use system service to read the device 
serial number
  * @sys_serv_priv:     system service private data
@@ -116,11 +138,9 @@ int mpfs_syscontroller_read_sernum(struct mpfs_sys_serv 
*sys_serv_priv, u8 *devi
        }
 
        /* Receive the response */
-       ret = mbox_recv(&sys_serv_priv->sys_controller->chan, &msg, 
timeoutsecs);
-       if (ret) {
-               dev_err(sys_serv_priv->sys_controller->chan.dev, "Service 
failed: %d, abort. Failure: %u\n", ret, msg.response->resp_status);
+       ret = mpfs_syscontroller_recv_response(sys_serv_priv->sys_controller, 
&msg, timeoutsecs);
+       if (ret)
                return ret;
-       }
 
        debug("%s: Read successful %s\n",
              __func__, sys_serv_priv->sys_controller->chan.dev->name);
diff --git a/include/mpfs-mailbox.h b/include/mpfs-mailbox.h
index c0ff327a4ce..3922e8d1019 100644
--- a/include/mpfs-mailbox.h
+++ b/include/mpfs-mailbox.h
@@ -58,6 +58,7 @@ struct mpfs_sys_serv {
 };
 
 int mpfs_syscontroller_run_service(struct mpfs_syscontroller_priv 
*sys_controller, struct mpfs_mss_msg *msg);
+int mpfs_syscontroller_recv_response(struct mpfs_syscontroller_priv* 
sys_controller, struct mpfs_mss_msg* msg, unsigned long timeout_ms);
 int mpfs_syscontroller_read_sernum(struct mpfs_sys_serv *sys_serv_priv, u8 
*device_serial_number);
 void mpfs_syscontroller_process_dtbo(struct mpfs_sys_serv *sys_serv_priv);
 struct mpfs_syscontroller_priv *mpfs_syscontroller_get(struct udevice *dev);
-- 
2.43.0

Reply via email to