diff mbox

tcmu:add reference count of dev in tcmu_open function

Message ID 1498112466-8900-1-git-send-email-tang.wenji@zte.com.cn (mailing list archive)
State New, archived
Headers show

Commit Message

tang.wenji@zte.com.cn June 22, 2017, 6:21 a.m. UTC
From: Wenji Tang <tang.wenji@zte.com.cn>

In the tcmu_open function does not increase the reference count of dev, but in the tcmu_release function to decrease its reference count. When the user oepn/close device many times, the corresponding dev device is illegally released

Signed-off-by: Wenji Tang <tang.wenji@zte.com.cn>
---
 drivers/target/target_core_user.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Mike Christie June 22, 2017, 5:39 p.m. UTC | #1
On 06/22/2017 01:21 AM, tang.wenji@zte.com.cn wrote:
> From: Wenji Tang <tang.wenji@zte.com.cn>
> 
> In the tcmu_open function does not increase the reference count of dev, but in the tcmu_release function to decrease its reference count. When the user oepn/close device many times, the corresponding dev device is illegally released
> 
> Signed-off-by: Wenji Tang <tang.wenji@zte.com.cn>
> ---
>  drivers/target/target_core_user.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index beb5f09..376a290 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -1142,6 +1142,8 @@ static int tcmu_open(struct uio_info *info, struct inode *inode)
>  	udev->inode = inode;
>  
>  	pr_debug("open\n");
> +	
> +	kref_get(&udev->kref);
>  

Patch looks correct. I am removing the tcmu based refcounting in these
patches though:

https://www.spinics.net/lists/target-devel/msg15657.html

For refcounting on the uio side and to fix a leak in the uio code, I am
working on doing uio refcounting similar to these patches began to do:

https://marc.info/?t=142686341100003&r=1&w=2
--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Christie June 22, 2017, 5:51 p.m. UTC | #2
On 06/22/2017 12:39 PM, Mike Christie wrote:
> On 06/22/2017 01:21 AM, tang.wenji@zte.com.cn wrote:
>> From: Wenji Tang <tang.wenji@zte.com.cn>
>>
>> In the tcmu_open function does not increase the reference count of dev, but in the tcmu_release function to decrease its reference count. When the user oepn/close device many times, the corresponding dev device is illegally released
>>
>> Signed-off-by: Wenji Tang <tang.wenji@zte.com.cn>
>> ---
>>  drivers/target/target_core_user.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
>> index beb5f09..376a290 100644
>> --- a/drivers/target/target_core_user.c
>> +++ b/drivers/target/target_core_user.c
>> @@ -1142,6 +1142,8 @@ static int tcmu_open(struct uio_info *info, struct inode *inode)
>>  	udev->inode = inode;
>>  
>>  	pr_debug("open\n");
>> +	
>> +	kref_get(&udev->kref);
>>  
> 
> Patch looks correct. I am removing the tcmu based refcounting in these

I take that back.

We would need to implement a uio close function and do a matching
kref_put in there right?

> patches though:
> 

My patchset removed the refcounting because it assumed userspace used it
like how tcmu-runner did.

Are you using a different app that will open the uio device multiple
times? Will it have multiple users opening it at the same time?

> https://www.spinics.net/lists/target-devel/msg15657.html
> 
> For refcounting on the uio side and to fix a leak in the uio code, I am
> working on doing uio refcounting similar to these patches began to do:
> 
> https://marc.info/?t=142686341100003&r=1&w=2
> --
> To unsubscribe from this list: send the line "unsubscribe target-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index beb5f09..376a290 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1142,6 +1142,8 @@  static int tcmu_open(struct uio_info *info, struct inode *inode)
 	udev->inode = inode;
 
 	pr_debug("open\n");
+	
+	kref_get(&udev->kref);
 
 	return 0;
 }