msm: adsprpc: Fix NULL pointer error when DEBUG_FS is disabled

Add extra checks to avoid NULL pointer derefernce when DEBUG_FS
is disabled.

Change-Id: I46ff3b8b27b53ff5bb5dead78ccdefc410435dda
Acked-by: Tadakamalla Krishnaiah <ktadakam@qti.qualcomm.com>
Signed-off-by: Mohammed Nayeem Ur Rahman <mohara@codeaurora.org>
This commit is contained in:
Mohammed Nayeem Ur Rahman 2020-05-11 20:54:52 +05:30 • committed by Gerrit - the friendly Code Review server
commit 9fb522a577

View file

@ -4898,19 +4898,26 @@ static int fastrpc_set_process_info(struct fastrpc_file *fl)
fl->tgid = current->tgid;
snprintf(strpid, PID_SIZE, "%d", current->pid);
buf_size = strlen(current->comm) + strlen("_") + strlen(strpid) + 1;
fl->debug_buf = kzalloc(buf_size, GFP_KERNEL);
if (!fl->debug_buf) {
err = -ENOMEM;
return err;
}
snprintf(fl->debug_buf, UL_SIZE, "%.10s%s%d",
if (debugfs_root) {
buf_size = strlen(current->comm) + strlen("_")
+ strlen(strpid) + 1;
fl->debug_buf = kzalloc(buf_size, GFP_KERNEL);
if (!fl->debug_buf) {
err = -ENOMEM;
return err;
}
snprintf(fl->debug_buf, UL_SIZE, "%.10s%s%d",
current->comm, "_", current->pid);
fl->debugfs_file = debugfs_create_file(fl->debug_buf, 0644,
debugfs_root, fl, &debugfs_fops);
if (!fl->debugfs_file)
ADSPRPC_WARN("failed to create debugfs file %s\n",
fl->debug_buf);
fl->debugfs_file = debugfs_create_file(fl->debug_buf, 0644,
debugfs_root, fl, &debugfs_fops);
if (IS_ERR_OR_NULL(fl->debugfs_file)) {
pr_warn("Error: %s: %s: failed to create debugfs file %s\n",
current->comm, __func__, fl->debug_buf);
fl->debugfs_file = NULL;
kfree(fl->debug_buf);
fl->debug_buf = NULL;
}
}
return err;
}
@ -5700,6 +5707,15 @@ static int fastrpc_cb_probe(struct device *dev)
}
chan->sesscount++;
if (debugfs_root) {
debugfs_global_file = debugfs_create_file("global", 0644,
debugfs_root, NULL, &debugfs_fops);
if (IS_ERR_OR_NULL(debugfs_global_file)) {
pr_warn("Error: %s: %s: failed to create debugfs global file\n",
current->comm, __func__);
debugfs_global_file = NULL;
}
}
bail:
return err;
}
@ -5948,8 +5964,12 @@ static int __init fastrpc_device_init(void)
int err = 0, i;
debugfs_root = debugfs_create_dir("adsprpc", NULL);
debugfs_global_file = debugfs_create_file("global", 0644, debugfs_root,
NULL, &debugfs_fops);
if (IS_ERR_OR_NULL(debugfs_root)) {
pr_warn("Error: %s: %s: failed to create debugfs root dir\n",
current->comm, __func__);
debugfs_remove_recursive(debugfs_root);
debugfs_root = NULL;
}
memset(me, 0, sizeof(*me));
fastrpc_init(me);
me->dev = NULL;
@ -5958,7 +5978,7 @@ static int __init fastrpc_device_init(void)
if (err)
goto register_bail;
VERIFY(err, 0 == alloc_chrdev_region(&me->dev_no, 0, NUM_CHANNELS,
DEVICE_NAME));
DEVICE_NAME));
if (err)
goto alloc_chrdev_bail;
cdev_init(&me->cdev, &fops);