]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
virtio: Don't access index after unregister.
authorCornelia Huck <cornelia.huck@de.ibm.com>
Fri, 9 Nov 2012 04:24:12 +0000 (14:54 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 9 Nov 2012 04:24:24 +0000 (14:54 +1030)
commit237242bddc99041e15a4ca51b8439657cadaff17
treea506fe81ea564d15ed2544d5bb477bc58405603f
parentf6a79af8f3701b5a0df431a76adee212616154dc
virtio: Don't access index after unregister.

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>
drivers/virtio/virtio.c