diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-09-02 08:50:58 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-10-21 03:14:03 -0400 |
commit | 04950cdf071b6e5aa4794c93ad3e3ce8a1c4aa8c (patch) | |
tree | 24a8d32ee63ef7c0a634e67dc67fdef0f84a14a6 | |
parent | 6bdf2afd02ae12bf8ac93e6d14c4b4dfef7c4c59 (diff) |
virtio: console: Add a find_port_by_devt() function
To convert to using cdev as a pointer to avoid kref troubles, we have to
use a different method to get to a port from an inode than the current
container_of method.
Add find_port_by_devt() that looks up all portdevs and ports with those
portdevs to find the right port.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | drivers/char/virtio_console.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index b70fe96c1ccd..0c8f2aa3074a 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -227,6 +227,41 @@ out: | |||
227 | return port; | 227 | return port; |
228 | } | 228 | } |
229 | 229 | ||
230 | static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev, | ||
231 | dev_t dev) | ||
232 | { | ||
233 | struct port *port; | ||
234 | unsigned long flags; | ||
235 | |||
236 | spin_lock_irqsave(&portdev->ports_lock, flags); | ||
237 | list_for_each_entry(port, &portdev->ports, list) | ||
238 | if (port->cdev.dev == dev) | ||
239 | goto out; | ||
240 | port = NULL; | ||
241 | out: | ||
242 | spin_unlock_irqrestore(&portdev->ports_lock, flags); | ||
243 | |||
244 | return port; | ||
245 | } | ||
246 | |||
247 | static struct port *find_port_by_devt(dev_t dev) | ||
248 | { | ||
249 | struct ports_device *portdev; | ||
250 | struct port *port; | ||
251 | unsigned long flags; | ||
252 | |||
253 | spin_lock_irqsave(&pdrvdata_lock, flags); | ||
254 | list_for_each_entry(portdev, &pdrvdata.portdevs, list) { | ||
255 | port = find_port_by_devt_in_portdev(portdev, dev); | ||
256 | if (port) | ||
257 | goto out; | ||
258 | } | ||
259 | port = NULL; | ||
260 | out: | ||
261 | spin_unlock_irqrestore(&pdrvdata_lock, flags); | ||
262 | return port; | ||
263 | } | ||
264 | |||
230 | static struct port *find_port_by_id(struct ports_device *portdev, u32 id) | 265 | static struct port *find_port_by_id(struct ports_device *portdev, u32 id) |
231 | { | 266 | { |
232 | struct port *port; | 267 | struct port *port; |
@@ -719,7 +754,7 @@ static int port_fops_open(struct inode *inode, struct file *filp) | |||
719 | struct port *port; | 754 | struct port *port; |
720 | int ret; | 755 | int ret; |
721 | 756 | ||
722 | port = container_of(cdev, struct port, cdev); | 757 | port = find_port_by_devt(cdev->dev); |
723 | filp->private_data = port; | 758 | filp->private_data = port; |
724 | 759 | ||
725 | /* | 760 | /* |