mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-17 22:41:25 +00:00
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>
This commit is contained in:
parent
6bdf2afd02
commit
04950cdf07
@ -227,6 +227,41 @@ out:
|
||||
return port;
|
||||
}
|
||||
|
||||
static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev,
|
||||
dev_t dev)
|
||||
{
|
||||
struct port *port;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&portdev->ports_lock, flags);
|
||||
list_for_each_entry(port, &portdev->ports, list)
|
||||
if (port->cdev.dev == dev)
|
||||
goto out;
|
||||
port = NULL;
|
||||
out:
|
||||
spin_unlock_irqrestore(&portdev->ports_lock, flags);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
static struct port *find_port_by_devt(dev_t dev)
|
||||
{
|
||||
struct ports_device *portdev;
|
||||
struct port *port;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&pdrvdata_lock, flags);
|
||||
list_for_each_entry(portdev, &pdrvdata.portdevs, list) {
|
||||
port = find_port_by_devt_in_portdev(portdev, dev);
|
||||
if (port)
|
||||
goto out;
|
||||
}
|
||||
port = NULL;
|
||||
out:
|
||||
spin_unlock_irqrestore(&pdrvdata_lock, flags);
|
||||
return port;
|
||||
}
|
||||
|
||||
static struct port *find_port_by_id(struct ports_device *portdev, u32 id)
|
||||
{
|
||||
struct port *port;
|
||||
@ -719,7 +754,7 @@ static int port_fops_open(struct inode *inode, struct file *filp)
|
||||
struct port *port;
|
||||
int ret;
|
||||
|
||||
port = container_of(cdev, struct port, cdev);
|
||||
port = find_port_by_devt(cdev->dev);
|
||||
filp->private_data = port;
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user