Skip to content

Commit

Permalink
virtio_console: Use virtio device index to generate port name
Browse files Browse the repository at this point in the history
Use virtio device index for creating unique device port names.
Current index allocation in virtio is based on a monotonically
increasing variable "index". A better handling of this is to
use device index which is allocated by ida.

Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Sjur Brændeland authored and Rusty Russell committed Feb 12, 2013
1 parent 35cdc9e commit dc18f08
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ struct ports_driver_data {
/* List of all the devices we're handling */
struct list_head portdevs;

/* Number of devices this driver is handling */
unsigned int index;

/*
* This is used to keep track of the number of hvc consoles
* spawned by this driver. This number is given as the first
Expand Down Expand Up @@ -169,9 +166,6 @@ struct ports_device {
/* Array of per-port IO virtqueues */
struct virtqueue **in_vqs, **out_vqs;

/* Used for numbering devices for sysfs and debugfs */
unsigned int drv_index;

/* Major number for this device. Ports will be created as minors. */
int chr_major;
};
Expand Down Expand Up @@ -1415,7 +1409,7 @@ static int add_port(struct ports_device *portdev, u32 id)
}
port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
devt, port, "vport%up%u",
port->portdev->drv_index, id);
port->portdev->vdev->index, id);
if (IS_ERR(port->dev)) {
err = PTR_ERR(port->dev);
dev_err(&port->portdev->vdev->dev,
Expand Down Expand Up @@ -1470,7 +1464,7 @@ static int add_port(struct ports_device *portdev, u32 id)
* inspect a port's state at any time
*/
sprintf(debugfs_name, "vport%up%u",
port->portdev->drv_index, id);
port->portdev->vdev->index, id);
port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
pdrvdata.debugfs_dir,
port,
Expand Down Expand Up @@ -1961,16 +1955,12 @@ static int virtcons_probe(struct virtio_device *vdev)
portdev->vdev = vdev;
vdev->priv = portdev;

spin_lock_irq(&pdrvdata_lock);
portdev->drv_index = pdrvdata.index++;
spin_unlock_irq(&pdrvdata_lock);

portdev->chr_major = register_chrdev(0, "virtio-portsdev",
&portdev_fops);
if (portdev->chr_major < 0) {
dev_err(&vdev->dev,
"Error %d registering chrdev for device %u\n",
portdev->chr_major, portdev->drv_index);
portdev->chr_major, vdev->index);
err = portdev->chr_major;
goto free;
}
Expand Down

0 comments on commit dc18f08

Please sign in to comment.