summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorStefan Agner <stefan.agner@toradex.com>2016-09-30 11:04:56 -0700
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>2016-10-01 17:35:51 +0200
commita5a7e6d1698f75cf3bac5075e9ddd61acdf07dbe (patch)
tree72fea3f35b6763afb0496659d66fe3d75178094e /drivers/char
parentfa359d75f35900293ca8ee3189d9f0f867f4f8c0 (diff)
char: vf610_sema4: improve error handling
Add proper error handling in case the device does not exist. Use ERR_PTR for all error cases. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Acked-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/vf610_sema4.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/char/vf610_sema4.c b/drivers/char/vf610_sema4.c
index 352676a307ca..7560c057ff9e 100644
--- a/drivers/char/vf610_sema4.c
+++ b/drivers/char/vf610_sema4.c
@@ -30,17 +30,22 @@ vf610_sema4_mutex_create(u32 dev_num, u32 mutex_num)
{
struct vf610_sema4_mutex *mutex_ptr = NULL;
+ if (!vf610_sema4)
+ return ERR_PTR(-ENODEV);
+
if (mutex_num >= SEMA4_NUM_GATES || dev_num >= SEMA4_NUM_DEVICES)
- goto out;
+ return ERR_PTR(-EINVAL);
if (vf610_sema4->cpine_val & (1 < mutex_num)) {
pr_err("Error: requiring a allocated sema4.\n");
pr_err("mutex_num %d cpine_val 0x%08x.\n",
mutex_num, vf610_sema4->cpine_val);
}
+
mutex_ptr = kzalloc(sizeof(*mutex_ptr), GFP_KERNEL);
if (!mutex_ptr)
- goto out;
+ return ERR_PTR(-ENOMEM);
+
vf610_sema4->mutex_ptr[mutex_num] = mutex_ptr;
vf610_sema4->alloced |= 1 < mutex_num;
vf610_sema4->cpine_val |= idx_sema4[mutex_num];
@@ -50,7 +55,6 @@ vf610_sema4_mutex_create(u32 dev_num, u32 mutex_num)
mutex_ptr->gate_num = mutex_num;
init_waitqueue_head(&mutex_ptr->wait_q);
-out:
return mutex_ptr;
}
EXPORT_SYMBOL(vf610_sema4_mutex_create);