From 85736acbdf5acd07a4d82dca76c33075fd0fca29 Mon Sep 17 00:00:00 2001 From: shenchenkai Date: Thu, 6 Jan 2022 20:32:03 +0800 Subject: [PATCH] hilog: fix some hilog problem ohos inclusion category: bugfix issue: #I4PH4E CVE: NA -------------------------------- 1. hilog use pid to print tgid, it is wrong, fix it. 2. fix hilog compile warning. 3. reduce print log if hilog ringbuffer is full. Signed-off-by: shenchenkai --- drivers/staging/hilog/hilog.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/staging/hilog/hilog.c b/drivers/staging/hilog/hilog.c index 167d4e3f359f..2c0f843a1867 100644 --- a/drivers/staging/hilog/hilog.c +++ b/drivers/staging/hilog/hilog.c @@ -44,7 +44,7 @@ module_param(hilog_major, int, 0444); struct cdev g_hilog_cdev; -#define HILOG_BUFFER CONFIG_HILOG_BUFFER_SIZE +#define HILOG_BUFFER ((size_t)CONFIG_HILOG_BUFFER_SIZE) #define HILOG_DRIVER "/dev/hilog" struct hilog_entry { @@ -161,7 +161,7 @@ static ssize_t hilog_read(struct file *file, if (count < header.len + sizeof(header)) { pr_err("buffer too small,buf_len=%d, header.len=%d,%d\n", - count, header.len, header.header_size); + (int)count, header.len, header.header_size); retval = -ENOMEM; goto out; } @@ -260,7 +260,7 @@ static void hilog_head_init(struct hilog_entry *header, size_t len) header->len = len; header->pid = current->pid; - header->task_id = current->pid; + header->task_id = current->tgid; header->header_size = sizeof(struct hilog_entry); } @@ -269,7 +269,9 @@ static void hilog_cover_old_log(size_t buf_len) int retval; struct hilog_entry header; size_t total_size = buf_len + sizeof(struct hilog_entry); - int drop_log_lines = 0; + static int drop_log_lines; + static int is_last_time_full; + int is_this_time_full = 0; while (total_size + hilog_dev.size >= HILOG_BUFFER) { retval = hilog_read_ring_head_buffer((unsigned char *)&header, @@ -278,11 +280,18 @@ static void hilog_cover_old_log(size_t buf_len) break; drop_log_lines++; + is_this_time_full = 1; + is_last_time_full = 1; hilog_buffer_dec(sizeof(header) + header.len); } - if (drop_log_lines > 0) - pr_info("hilog ringbuffer full, drop %d line(s) log", - drop_log_lines); + if (is_last_time_full == 1 && is_this_time_full == 0) { + /* so we can only print one log if hilog ring buffer is full in a short time */ + if (drop_log_lines > 0) + pr_info("hilog ringbuffer full, drop %d line(s) log\n", + drop_log_lines); + is_last_time_full = 0; + drop_log_lines = 0; + } } int hilog_write_internal(const char __user *buffer, size_t buf_len) -- Gitee