Skip to content

Commit

Permalink
virtio: Don't access index after unregister.
Browse files Browse the repository at this point in the history
Virtio wants to release used indices after the corresponding
virtio device has been unregistered. However, virtio does not
hold an extra reference, giving up its last reference with
device_unregister(), making accessing dev->index afterwards
invalid.

I actually saw problems when testing my (not-yet-merged)
virtio-ccw code:

- device_add virtio-net,id=xxx
-> creates device virtio<n> with n>0

- device_del xxx
-> deletes virtio<n>, but calls ida_simple_remove with an
   index of 0

- device_add virtio-net,id=xxx
-> tries to add virtio0, which is still in use...

So let's save the index we want to release before calling
device_unregister().

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Acked-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
Cc: stable@kernel.org
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Cornelia Huck authored and Rusty Russell committed Nov 9, 2012
1 parent f6a79af commit 237242b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ EXPORT_SYMBOL_GPL(register_virtio_device);

void unregister_virtio_device(struct virtio_device *dev)
{
int index = dev->index; /* save for after device release */

device_unregister(&dev->dev);
ida_simple_remove(&virtio_index_ida, dev->index);
ida_simple_remove(&virtio_index_ida, index);
}
EXPORT_SYMBOL_GPL(unregister_virtio_device);

Expand Down

0 comments on commit 237242b

Please sign in to comment.