Merged
drivers/ub/sentry: some bugfix #20901
drivers/ub/sentry: some bugfix #20901
Merged
tong_1001Add on Mar 2
Total: 6 files changed+19-21
@@ -32,7 +32,7 @@
32#define PANIC_TIMEOUT_MS_MAX 360000032#define PANIC_TIMEOUT_MS_MAX 3600000
33#define KERNEL_REBOOT_TIMEOUT_MS_MIN 033#define KERNEL_REBOOT_TIMEOUT_MS_MIN 0
34#define KERNEL_REBOOT_TIMEOUT_MS_MAX 360000034#define KERNEL_REBOOT_TIMEOUT_MS_MAX 3600000
35-#define LOCAL_EID_MAX_LEN (EID_MAX_LEN * 2 + 1 + 1)35+#define LOCAL_EID_MAX_LEN (EID_MAX_LEN * MAX_DIE_NUM + 1 + 1)
36 36 
37#undef pr_fmt37#undef pr_fmt
38#define pr_fmt(fmt) "[sentry][remote client]: " fmt38#define pr_fmt(fmt) "[sentry][remote client]: " fmt
@@ -1035,14 +1035,15 @@ static int __init sentry_remote_reporter_init(void)
1035 if (ret)1035 if (ret)
1036 return ret;1036 return ret;
1037 1037 
1038- sentry_client_ctx.msg_str = kzalloc(MAX_NODE_NUM * 2 * sizeof(char *), GFP_KERNEL);1038+ sentry_client_ctx.msg_str = kzalloc(MAX_NODE_NUM * MAX_DIE_NUM * sizeof(char *),
1039+ GFP_KERNEL);
1039 if (!sentry_client_ctx.msg_str) {1040 if (!sentry_client_ctx.msg_str) {
1040 pr_err("Failed to allocate memory for msg_str\n");1041 pr_err("Failed to allocate memory for msg_str\n");
1041 ret = -ENOMEM;1042 ret = -ENOMEM;
1042 goto stop_kthread;1043 goto stop_kthread;
1043 }1044 }
1044 1045 
1045- for (i = 0; i < MAX_NODE_NUM * 2; i++) {1046+ for (i = 0; i < MAX_NODE_NUM * MAX_DIE_NUM; i++) {
1046 sentry_client_ctx.msg_str[i] = kzalloc(URMA_SEND_DATA_MAX_LEN, GFP_KERNEL);1047 sentry_client_ctx.msg_str[i] = kzalloc(URMA_SEND_DATA_MAX_LEN, GFP_KERNEL);
1047 if (!sentry_client_ctx.msg_str[i]) {1048 if (!sentry_client_ctx.msg_str[i]) {
1048 pr_err("Failed to allocate memory for msg_str[%d]\n", i);1049 pr_err("Failed to allocate memory for msg_str[%d]\n", i);
@@ -1079,7 +1080,7 @@ static int __init sentry_remote_reporter_init(void)
1079unregister_kernel_reboot:1080unregister_kernel_reboot:
1080 unregister_reboot_notifier(&kernel_reboot_notifier);1081 unregister_reboot_notifier(&kernel_reboot_notifier);
1081free_msg_str:1082free_msg_str:
1082- free_char_array(sentry_client_ctx.msg_str, MAX_NODE_NUM * 2);1083+ free_char_array(sentry_client_ctx.msg_str, MAX_NODE_NUM * MAX_DIE_NUM);
1083stop_kthread:1084stop_kthread:
1084 sentry_panic_reporter_exit();1085 sentry_panic_reporter_exit();
1085 return ret;1086 return ret;
@@ -1099,7 +1100,7 @@ static void __exit sentry_remote_reporter_exit(void)
1099 unregister_reboot_notifier(&kernel_reboot_notifier);1100 unregister_reboot_notifier(&kernel_reboot_notifier);
1100 pr_info("Kernel reboot handler unregistered\n");1101 pr_info("Kernel reboot handler unregistered\n");
1101 1102 
1102- free_char_array(sentry_client_ctx.msg_str, MAX_NODE_NUM * 2);1103+ free_char_array(sentry_client_ctx.msg_str, MAX_NODE_NUM * MAX_DIE_NUM);
1103 1104 
1104 if (sentry_client_ctx.panic_proc_dir)1105 if (sentry_client_ctx.panic_proc_dir)
1105 proc_remove(sentry_client_ctx.panic_proc_dir);1106 proc_remove(sentry_client_ctx.panic_proc_dir);
@@ -135,7 +135,7 @@ int send_msg_to_userspace_and_ack(struct sentry_msg_helper_msg *msg,
135 }135 }
136 136 
137 /* Get acknowledgment success, send acknowledgment message */137 /* Get acknowledgment success, send acknowledgment message */
138- char send_ack[URMA_SEND_DATA_MAX_LEN];138+ char send_ack[URMA_SEND_DATA_MAX_LEN] = {0};
139 139 
140 ret = snprintf(send_ack, URMA_SEND_DATA_MAX_LEN, "%d_%u_%s_%lu",140 ret = snprintf(send_ack, URMA_SEND_DATA_MAX_LEN, "%d_%u_%s_%lu",
141 ack_type,141 ack_type,
@@ -274,7 +274,7 @@ int create_kthread_to_process_msg(const char *event_msg,
274 enum SENTRY_REMOTE_COMM_TYPE comm_type)274 enum SENTRY_REMOTE_COMM_TYPE comm_type)
275{275{
276 int ret;276 int ret;
277- struct sentry_msg_helper_msg msg;277+ struct sentry_msg_helper_msg msg = {0};
278 uint32_t random_id;278 uint32_t random_id;
279 struct child_thread_process_data *child_data;279 struct child_thread_process_data *child_data;
280 struct task_struct *child_thread;280 struct task_struct *child_thread;
@@ -388,7 +388,7 @@ static int process_urma_data(void *data)
388 }388 }
389 389 
390free_msg:390free_msg:
391- free_char_array(msg_str, MAX_NODE_NUM);391+ free_char_array(msg_str, MAX_NODE_NUM * MAX_DIE_NUM);
392 392 
393 pr_info("Urma receiver thread stopped!\n");393 pr_info("Urma receiver thread stopped!\n");
394 return ret;394 return ret;
@@ -114,7 +114,7 @@ static int acpi_power_notifier_callback(struct notifier_block *nb,
114 unsigned long action, void *data)114 unsigned long action, void *data)
115{115{
116 int ret;116 int ret;
117- struct sentry_msg_helper_msg msg;117+ struct sentry_msg_helper_msg msg = {0};
118 118 
119 if (!g_power_off_enable)119 if (!g_power_off_enable)
120 return NOTIFY_OK;120 return NOTIFY_OK;
@@ -147,7 +147,7 @@ static int lowmem_notifier_callback(struct notifier_block *nb,
147 unsigned long action, void *parm)147 unsigned long action, void *parm)
148{148{
149 struct reclaim_notify_data *data = parm;149 struct reclaim_notify_data *data = parm;
150- struct sentry_msg_helper_msg msg;150+ struct sentry_msg_helper_msg msg = {0};
151 int ret;151 int ret;
152 int i;152 int i;
153 153 
@@ -463,7 +463,7 @@ static const struct proc_ops proc_ub_mem_fault_with_kill_file_operations = {
463 */463 */
464static int ub_mem_ras_handler(uint64_t phys_addr, enum ras_err_type err_type)464static int ub_mem_ras_handler(uint64_t phys_addr, enum ras_err_type err_type)
465{465{
466- struct sentry_msg_helper_msg msg;466+ struct sentry_msg_helper_msg msg = {0};
467 struct page *page;467 struct page *page;
468 int ret;468 int ret;
469 469 
@@ -1130,11 +1130,6 @@ int sentry_create_urma_resource(union ubcore_eid eid[], int eid_num)
1130{1130{
1131 int ret, i;1131 int ret, i;
1132 1132 
1133- if (eid_num > MAX_DIE_NUM) {
1134- pr_err("Invalid eid num, failed to create urma resource\n");
1135- return -EINVAL;
1136- }
1137- 
1138 /* Prepare for new device matching by cleaning up old resources */1133 /* Prepare for new device matching by cleaning up old resources */
1139 release_all_resource();1134 release_all_resource();
1140 1135 
@@ -1236,7 +1231,7 @@ int process_multi_eid_string(char *eid_buf, char eid_array[][EID_MAX_LEN],
1236 int eid_num = 0;1231 int eid_num = 0;
1237 char *eid_part;1232 char *eid_part;
1238 1233 
1239- if (!eid_buf || !sepstr || eid_max_num > MAX_DIE_NUM) {1234+ if (!eid_buf || !sepstr) {
1240 pr_err("Invalid param, failed to process multi eid string\n");1235 pr_err("Invalid param, failed to process multi eid string\n");
1241 return -EINVAL;1236 return -EINVAL;
1242 }1237 }
@@ -2085,7 +2080,8 @@ int urma_send(const char *buf, size_t len, const char *dst_eid, int die_index)
2085 if (!g_is_created_ubcore_resource)2080 if (!g_is_created_ubcore_resource)
2086 return -ENODEV;2081 return -ENODEV;
2087 2082 
2088- if (!buf || !dst_eid || len > URMA_SEND_DATA_MAX_LEN || strlen(buf) > len) {2083+ /* at broadcast mode, dst_eid is NULL */
2084+ if (!buf || len > URMA_SEND_DATA_MAX_LEN || strlen(buf) > len) {
2089 pr_err("%s: Invalid param, failed to send data\n", __func__);2085 pr_err("%s: Invalid param, failed to send data\n", __func__);
2090 return -EINVAL;2086 return -EINVAL;
2091 }2087 }
@@ -2269,7 +2265,7 @@ static int __init sentry_urma_comm_init(void)
2269{2265{
2270 int ret = 0;2266 int ret = 0;
2271 2267 
2272- sentry_urma_ctx.proc_dir = proc_mkdir_mode(PROC_DEVICE_PATH, 0550, NULL);2268+ sentry_urma_ctx.proc_dir = proc_mkdir_mode(PROC_DEVICE_PATH, PROC_DIR_PERMISSION, NULL);
2273 if (!sentry_urma_ctx.proc_dir) {2269 if (!sentry_urma_ctx.proc_dir) {
2274 pr_err("create /proc/%s dir failed\n", PROC_DEVICE_PATH);2270 pr_err("create /proc/%s dir failed\n", PROC_DEVICE_PATH);
2275 return -ENOMEM;2271 return -ENOMEM;
@@ -50,7 +50,8 @@ int uvb_send(const char *str, uint32_t dst_cna, bool is_sync)
50 return -EINVAL;50 return -EINVAL;
51 }51 }
52 52 
53- struct cis_message msg;53+ struct cis_message msg = {0};
54+ 
54 msg.input = (char *)str;55 msg.input = (char *)str;
55 msg.input_size = strlen(str) + 1;56 msg.input_size = strlen(str) + 1;
56 msg.output = NULL;57 msg.output = NULL;
@@ -34,7 +34,7 @@ static long smh_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg
34 34 
35 switch (cmd) {35 switch (cmd) {
36 case SMH_MSG_ACK: {36 case SMH_MSG_ACK: {
37- struct sentry_msg_helper_msg cmd_msg;37+ struct sentry_msg_helper_msg cmd_msg = {0};
38 38 
39 if (copy_from_user(&cmd_msg, (void __user *)arg, sizeof(cmd_msg)))39 if (copy_from_user(&cmd_msg, (void __user *)arg, sizeof(cmd_msg)))
40 return -EFAULT;40 return -EFAULT;