[Manual Merge] Bulk merge missing merge commit shas into main

Bug: b/325548077
Change-Id: I17edaa5bb5398131c34e51684124564ca3f076eb
diff --git a/lib/memlog/memlog.c b/lib/memlog/memlog.c
index 92a0879..390a2ee 100644
--- a/lib/memlog/memlog.c
+++ b/lib/memlog/memlog.c
@@ -166,7 +166,7 @@
     status_t result;
     struct log_rb* rb;
 
-    if (!IS_PAGE_ALIGNED(sz)) {
+    if (!IS_PAGE_ALIGNED(sz) || sz == 0) {
         return SM_ERR_INVALID_PARAMETERS;
     }
 
diff --git a/services/smc/smc_service.c b/services/smc/smc_service.c
index 247fa3a..8f1a5b2 100644
--- a/services/smc/smc_service.c
+++ b/services/smc/smc_service.c
@@ -93,7 +93,7 @@
     struct smc_channel_ctx* channel_ctx = ctx;
     int rc;
     struct smc_msg request;
-    struct smc_msg response = {0};
+    struct smc_response response = {0};
     struct smc_regs ret;
     uint32_t smc_nr;
 
@@ -108,7 +108,13 @@
     if (rc != NO_ERROR) {
         TRACEF("%s: failed (%d) client not allowed to call SMC number %x\n",
                __func__, rc, smc_nr);
-        response.params[0] = (ulong)ERR_ACCESS_DENIED;
+        /*
+         * callers of smc_read_response should not consume the struct smc_msg
+         * out parameter if the status code is negative but we write the error
+         * code into the message anyway out of an over-abundance of caution.
+         */
+        response.msg.params[0] = (ulong)ERR_ACCESS_DENIED;
+        response.rc = ERR_ACCESS_DENIED;
         goto send_response;
     }
 
@@ -117,7 +123,9 @@
     if (rc != NO_ERROR) {
         TRACEF("%s: failed (%d) invalid request for SMC number %x\n", __func__,
                rc, smc_nr);
-        response.params[0] = (ulong)ERR_INVALID_ARGS;
+        /* same reasoning as the ERR_ACCESS_DENIED case above */
+        response.msg.params[0] = (ulong)ERR_INVALID_ARGS;
+        response.rc = ERR_INVALID_ARGS;
         goto send_response;
     }
 
@@ -129,10 +137,15 @@
     };
     ret = smc(&args);
 
-    response.params[0] = ret.r0;
-    response.params[1] = ret.r1;
-    response.params[2] = ret.r2;
-    response.params[3] = ret.r3;
+    response.msg.params[0] = ret.r0;
+    response.msg.params[1] = ret.r1;
+    response.msg.params[2] = ret.r2;
+    response.msg.params[3] = ret.r3;
+
+    if ((int32_t)ret.r0 == SM_ERR_UNDEFINED_SMC) {
+        TRACEF("%s: unknown or failed smcall: %x\n", __func__, smc_nr);
+        response.rc = ERR_GENERIC;
+    }
 
 send_response:
     rc = ktipc_send(channel, &response, sizeof(response));
@@ -183,7 +196,7 @@
 const static struct ktipc_port smc_service_port = {
         .name = SMC_SERVICE_PORT,
         .uuid = &kernel_uuid,
-        .msg_max_size = sizeof(struct smc_msg),
+        .msg_max_size = sizeof(struct smc_response),
         .msg_queue_len = 1,
         .acl = &smc_service_port_acl,
         .priv = NULL,