public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] uio: Fix uio driver to refcount device
@ 2015-03-13 10:17 Brian Russell
  2015-03-18 17:07 ` Brian Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Russell @ 2015-03-13 10:17 UTC (permalink / raw)
  To: Hans J. Koch, Greg Kroah-Hartman; +Cc: linux-kernel

Protect uio driver from crashing if its owner is hot unplugged while there
are open fds.

Signed-off-by: Brian Russell <brussell@brocade.com>
---
 drivers/uio/uio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 6276f13..70ce015 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -434,9 +434,11 @@ static int uio_open(struct inode *inode, struct file *filep)
 		goto out;
 	}
 
+	get_device(idev);
+
 	if (!try_module_get(idev->owner)) {
 		ret = -ENODEV;
-		goto out;
+		goto err_module_get;
 	}
 
 	listener = kmalloc(sizeof(*listener), GFP_KERNEL);
@@ -462,6 +464,9 @@ err_infoopen:
 err_alloc_listener:
 	module_put(idev->owner);
 
+err_module_get:
+	put_device(idev);
+
 out:
 	return ret;
 }
@@ -485,6 +490,7 @@ static int uio_release(struct inode *inode, struct file *filep)
 
 	module_put(idev->owner);
 	kfree(listener);
+	put_device(idev);
 	return ret;
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] uio: Fix uio driver to refcount device
  2015-03-13 10:17 [PATCH v2] uio: Fix uio driver to refcount device Brian Russell
@ 2015-03-18 17:07 ` Brian Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Russell @ 2015-03-18 17:07 UTC (permalink / raw)
  To: Hans J. Koch, Greg Kroah-Hartman; +Cc: linux-kernel

Responding to myself ...

On 13/03/15 10:17, Brian Russell wrote:
> Protect uio driver from crashing if its owner is hot unplugged while there
> are open fds.
> 
> Signed-off-by: Brian Russell <brussell@brocade.com>
> ---
>  drivers/uio/uio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> index 6276f13..70ce015 100644
> --- a/drivers/uio/uio.c
> +++ b/drivers/uio/uio.c
> @@ -434,9 +434,11 @@ static int uio_open(struct inode *inode, struct file *filep)
>  		goto out;
>  	}
>  
> +	get_device(idev);
> +

This is bogus, idev is uio_device *, not device *. Turns out this patch only masked the crash I was seeing, so please ignore. Updated version to follow ...

Thanks,

Brian

>  	if (!try_module_get(idev->owner)) {
>  		ret = -ENODEV;
> -		goto out;
> +		goto err_module_get;
>  	}
>  
>  	listener = kmalloc(sizeof(*listener), GFP_KERNEL);
> @@ -462,6 +464,9 @@ err_infoopen:
>  err_alloc_listener:
>  	module_put(idev->owner);
>  
> +err_module_get:
> +	put_device(idev);
> +
>  out:
>  	return ret;
>  }
> @@ -485,6 +490,7 @@ static int uio_release(struct inode *inode, struct file *filep)
>  
>  	module_put(idev->owner);
>  	kfree(listener);
> +	put_device(idev);
>  	return ret;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-18 17:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-13 10:17 [PATCH v2] uio: Fix uio driver to refcount device Brian Russell
2015-03-18 17:07 ` Brian Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox