chub: ipc: fix kernel panic by runtime error
authorWen Xie <xiewen3@motorola.com>
Tue, 19 Feb 2019 07:45:20 +0000 (15:45 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Mon, 10 Jun 2019 03:21:07 +0000 (11:21 +0800)
Samsung patch:
fix kernel panic by runtime error.

Change-Id: I4f93bb680c570042e6c3a49b88e549b357edd063
Signed-off-by: Wen Xie <xiewen3@motorola.com>
Reviewed-on: https://gerrit.mot.com/1310433
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Yuchang Guo <guoyc1@mt.com>
Reviewed-by: Hua Tan <tanhua1@motorola.com>
Submit-Approved: Jira Key

drivers/staging/nanohub/chub_ipc.c

index 5e687c1cc69a1106232143204cbf9c481a6f76ae..d0129e992c13d7fd4a827d334bcdcb0f154756dd 100644 (file)
@@ -958,6 +958,7 @@ void ipc_logbuf_outprint(struct runtimelog_buf *rt_buf, u32 loop)
                struct ipc_logbuf *logbuf = &ipc_map->logbuf;
                u32 eq;
                u32 len;
+               u32 lenout;
 
 retry:
                eq = logbuf->eq;
@@ -982,13 +983,15 @@ retry:
                                        CSP_PRINTF_INFO("%s: FW-ERR: %s", NAME_PREFIX, (char *)log);
 
                                if (rt_buf) {
-                                       if (rt_buf->write_index + len + LOGFILE_NUM_SIZE > rt_buf->buffer_size)
+                                       if (rt_buf->write_index + len + LOGFILE_NUM_SIZE >= rt_buf->buffer_size)
                                                rt_buf->write_index = 0;
-                                       len = sprintf(rt_buf->buffer + rt_buf->write_index, "%10d:%s", log->size, log);
-                                       rt_buf->write_index += len;
+                                       lenout = snprintf(rt_buf->buffer + rt_buf->write_index, LOGFILE_NUM_SIZE + len, "%10d:%s\n", log->size, log);
+                                       rt_buf->write_index += lenout;
+                                       if (lenout != (LOGFILE_NUM_SIZE + len))
+                                               pr_info("%s: %s: size-n missmatch: %d -> %d\n", NAME_PREFIX, __func__, LOGFILE_NUM_SIZE + len, lenout);
                                }
                        } else {
-                               pr_err("%s: size err:%d, eq:%d, dq:%d\n", __func__, len, eq, logbuf->dq);
+                               pr_err("%s: %s: size err:%d, eq:%d, dq:%d\n", NAME_PREFIX, __func__, len, eq, logbuf->dq);
                        }
                        logbuf->dq = (logbuf->dq + 1) % LOGBUF_NUM;
                }