Merge "drivers: soc: qcom: Added check to avoid opening multiple instance"
This commit is contained in:
commit
5d45bd7a1e
1 changed files with 18 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
|
/* Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 and
|
* it under the terms of the GNU General Public License version 2 and
|
||||||
|
@ -68,8 +68,9 @@ static void *dummy_q6_mvm;
|
||||||
static void *dummy_q6_cvs;
|
static void *dummy_q6_cvs;
|
||||||
dev_t device_num;
|
dev_t device_num;
|
||||||
|
|
||||||
|
static struct mutex session_lock;
|
||||||
static spinlock_t voicesvc_lock;
|
static spinlock_t voicesvc_lock;
|
||||||
static bool is_released;
|
static bool is_released = 1;
|
||||||
static int voice_svc_dummy_reg(void);
|
static int voice_svc_dummy_reg(void);
|
||||||
static int voice_svc_dummy_dereg(void);
|
static int voice_svc_dummy_dereg(void);
|
||||||
|
|
||||||
|
@ -645,14 +646,23 @@ static int voice_svc_dummy_dereg(void)
|
||||||
static int voice_svc_open(struct inode *inode, struct file *file)
|
static int voice_svc_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
struct voice_svc_prvt *prtd = NULL;
|
struct voice_svc_prvt *prtd = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
pr_debug("%s\n", __func__);
|
pr_debug("%s\n", __func__);
|
||||||
|
|
||||||
|
mutex_lock(&session_lock);
|
||||||
|
if (is_released == 0) {
|
||||||
|
pr_err("%s: Access denied to device\n", __func__);
|
||||||
|
ret = -EBUSY;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
prtd = kmalloc(sizeof(struct voice_svc_prvt), GFP_KERNEL);
|
prtd = kmalloc(sizeof(struct voice_svc_prvt), GFP_KERNEL);
|
||||||
|
|
||||||
if (prtd == NULL) {
|
if (prtd == NULL) {
|
||||||
pr_err("%s: kmalloc failed\n", __func__);
|
pr_err("%s: kmalloc failed\n", __func__);
|
||||||
return -ENOMEM;
|
ret = -ENOMEM;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(prtd, 0, sizeof(struct voice_svc_prvt));
|
memset(prtd, 0, sizeof(struct voice_svc_prvt));
|
||||||
|
@ -676,7 +686,9 @@ static int voice_svc_open(struct inode *inode, struct file *file)
|
||||||
voice_svc_dummy_reg();
|
voice_svc_dummy_reg();
|
||||||
reg_dummy_sess = 1;
|
reg_dummy_sess = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
done:
|
||||||
|
mutex_unlock(&session_lock);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int voice_svc_release(struct inode *inode, struct file *file)
|
static int voice_svc_release(struct inode *inode, struct file *file)
|
||||||
|
@ -810,6 +822,7 @@ static int voice_svc_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
pr_debug("%s: Device created\n", __func__);
|
pr_debug("%s: Device created\n", __func__);
|
||||||
spin_lock_init(&voicesvc_lock);
|
spin_lock_init(&voicesvc_lock);
|
||||||
|
mutex_init(&session_lock);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
add_err:
|
add_err:
|
||||||
|
@ -832,6 +845,7 @@ static int voice_svc_remove(struct platform_device *pdev)
|
||||||
kfree(voice_svc_dev->cdev);
|
kfree(voice_svc_dev->cdev);
|
||||||
device_destroy(voice_svc_class, device_num);
|
device_destroy(voice_svc_class, device_num);
|
||||||
class_destroy(voice_svc_class);
|
class_destroy(voice_svc_class);
|
||||||
|
mutex_destroy(&session_lock);
|
||||||
unregister_chrdev_region(0, MINOR_NUMBER);
|
unregister_chrdev_region(0, MINOR_NUMBER);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue