Skip to content

Commit

Permalink
msm: vidc: Fix broken debugfs creation error checks and error paths
Browse files Browse the repository at this point in the history
The debugfs helper functions do not always return NULL when they fail;
instead, they can return an error number casted as a pointer, so that their
users have the option to determine the exact cause of failure.

Use the IS_ERR_OR_NULL() helper when checking for debugfs errors to fix the
error checks.

Change-Id: I937e294036482c13e1f40e5ea68db1673dcb6154
Signed-off-by: Sultan Alsawaf <sultanxda@gmail.com>
Signed-off-by: Albert I <krascgq@outlook.co.id>
Signed-off-by: khusika <khusikadhamar@gmail.com>
  • Loading branch information
kerneltoast authored and khusika committed Aug 9, 2018
1 parent fce83f3 commit bc1aa0e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions drivers/media/platform/msm/vidc/msm_vidc_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ struct dentry *msm_vidc_debugfs_init_drv(void)
struct dentry *msm_vidc_debugfs_init_core(struct msm_vidc_core *core,
struct dentry *parent)
{
struct dentry *dir = NULL;
struct dentry *dir;
char debugfs_name[MAX_DEBUGFS_NAME];
if (!core) {
dprintk(VIDC_ERR, "Invalid params, core: %pK\n", core);
Expand All @@ -236,22 +236,24 @@ struct dentry *msm_vidc_debugfs_init_core(struct msm_vidc_core *core,

snprintf(debugfs_name, MAX_DEBUGFS_NAME, "core%d", core->id);
dir = debugfs_create_dir(debugfs_name, parent);
if (!dir) {
if (IS_ERR_OR_NULL(dir)) {
dprintk(VIDC_ERR, "Failed to create debugfs for msm_vidc\n");
goto failed_create_dir;
}

if (!debugfs_create_file("info", S_IRUGO, dir, core, &core_info_fops)) {
if (IS_ERR_OR_NULL(debugfs_create_file("info", S_IRUGO, dir, core, &core_info_fops))) {
dprintk(VIDC_ERR, "debugfs_create_file: fail\n");
goto failed_create_dir;
goto failed_create_file;
}
if (!debugfs_create_file("trigger_ssr", S_IWUSR,
dir, core, &ssr_fops)) {
if (IS_ERR_OR_NULL(debugfs_create_file("trigger_ssr", S_IWUSR,
dir, core, &ssr_fops))) {
dprintk(VIDC_ERR, "debugfs_create_file: fail\n");
goto failed_create_dir;
goto failed_create_file;
}
failed_create_file:
debugfs_remove_recursive(dir);
failed_create_dir:
return dir;
return NULL;
}

static int inst_info_open(struct inode *inode, struct file *file)
Expand Down Expand Up @@ -435,7 +437,7 @@ static const struct file_operations inst_info_fops = {
struct dentry *msm_vidc_debugfs_init_inst(struct msm_vidc_inst *inst,
struct dentry *parent)
{
struct dentry *dir = NULL, *info = NULL;
struct dentry *dir, *info;
char debugfs_name[MAX_DEBUGFS_NAME];
struct core_inst_pair *idata = NULL;

Expand All @@ -455,14 +457,14 @@ struct dentry *msm_vidc_debugfs_init_inst(struct msm_vidc_inst *inst,
idata->inst = inst;

dir = debugfs_create_dir(debugfs_name, parent);
if (!dir) {
if (IS_ERR_OR_NULL(dir)) {
dprintk(VIDC_ERR, "Failed to create debugfs for msm_vidc\n");
goto failed_create_dir;
}

info = debugfs_create_file("info", S_IRUGO, dir,
idata, &inst_info_fops);
if (!info) {
if (IS_ERR_OR_NULL(info)) {
dprintk(VIDC_ERR, "debugfs_create_file: fail\n");
goto failed_create_file;
}
Expand All @@ -473,11 +475,10 @@ struct dentry *msm_vidc_debugfs_init_inst(struct msm_vidc_inst *inst,

failed_create_file:
debugfs_remove_recursive(dir);
dir = NULL;
failed_create_dir:
kfree(idata);
exit:
return dir;
return NULL;
}

void msm_vidc_debugfs_deinit_inst(struct msm_vidc_inst *inst)
Expand Down

0 comments on commit bc1aa0e

Please sign in to comment.