Skip to content

Commit

Permalink
staging: tidspbridge: Clean up error-handling code
Browse files Browse the repository at this point in the history
In the first hunk, 0 is returned on memory allocation failure, even though
other failures return -ENOMEM or other similar values.

In the second hunk, there was error handling code that returned without
freeing psz_path_name.

A simplified version of the semantic match that finds the first problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Julia Lawall authored and Greg Kroah-Hartman committed Oct 15, 2010
1 parent aaf0885 commit cc58cbb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/staging/tidspbridge/pmgr/dspapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ u32 mgrwrap_register_object(union trapped_args *args, void *pr_ctxt)
args->args_mgr_registerobject.psz_path_name) +
1;
psz_path_name = kmalloc(path_size, GFP_KERNEL);
if (!psz_path_name)
if (!psz_path_name) {
status = -ENOMEM;
goto func_end;
}
ret = strncpy_from_user(psz_path_name,
(char *)args->args_mgr_registerobject.
psz_path_name, path_size);
Expand All @@ -503,8 +505,10 @@ u32 mgrwrap_register_object(union trapped_args *args, void *pr_ctxt)
goto func_end;
}

if (args->args_mgr_registerobject.obj_type >= DSP_DCDMAXOBJTYPE)
return -EINVAL;
if (args->args_mgr_registerobject.obj_type >= DSP_DCDMAXOBJTYPE) {
status = -EINVAL;
goto func_end;
}

status = dcd_register_object(&uuid_obj,
args->args_mgr_registerobject.obj_type,
Expand Down

0 comments on commit cc58cbb

Please sign in to comment.