diff options
author | weiping zhang <zhangweiping@didichuxing.com> | 2017-12-21 07:39:50 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2018-02-01 09:26:45 -0500 |
commit | f2b44cde7e1687ef7886831a3a30df653bda2481 (patch) | |
tree | e09f617e1bcc15cf3bc5a14ce1d692af83d28471 | |
parent | f6f93f75afb65997f4a84aaaab59dd06a4a06c80 (diff) |
virtio: split device_register into device_initialize and device_add
In order to make caller do a simple cleanup, we split device_register
into device_initialize and device_add. device_initialize always succeeds,
so the caller can always use put_device when register_virtio_device faild.
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
Suggested-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
-rw-r--r-- | drivers/virtio/virtio.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index bf7ff3934d7f..59e36ef4920f 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c | |||
@@ -303,11 +303,21 @@ void unregister_virtio_driver(struct virtio_driver *driver) | |||
303 | } | 303 | } |
304 | EXPORT_SYMBOL_GPL(unregister_virtio_driver); | 304 | EXPORT_SYMBOL_GPL(unregister_virtio_driver); |
305 | 305 | ||
306 | /** | ||
307 | * register_virtio_device - register virtio device | ||
308 | * @dev : virtio device to be registered | ||
309 | * | ||
310 | * On error, the caller must call put_device on &@dev->dev (and not kfree), | ||
311 | * as another code path may have obtained a reference to @dev. | ||
312 | * | ||
313 | * Returns: 0 on suceess, -error on failure | ||
314 | */ | ||
306 | int register_virtio_device(struct virtio_device *dev) | 315 | int register_virtio_device(struct virtio_device *dev) |
307 | { | 316 | { |
308 | int err; | 317 | int err; |
309 | 318 | ||
310 | dev->dev.bus = &virtio_bus; | 319 | dev->dev.bus = &virtio_bus; |
320 | device_initialize(&dev->dev); | ||
311 | 321 | ||
312 | /* Assign a unique device index and hence name. */ | 322 | /* Assign a unique device index and hence name. */ |
313 | err = ida_simple_get(&virtio_index_ida, 0, 0, GFP_KERNEL); | 323 | err = ida_simple_get(&virtio_index_ida, 0, 0, GFP_KERNEL); |
@@ -330,9 +340,11 @@ int register_virtio_device(struct virtio_device *dev) | |||
330 | 340 | ||
331 | INIT_LIST_HEAD(&dev->vqs); | 341 | INIT_LIST_HEAD(&dev->vqs); |
332 | 342 | ||
333 | /* device_register() causes the bus infrastructure to look for a | 343 | /* |
334 | * matching driver. */ | 344 | * device_add() causes the bus infrastructure to look for a matching |
335 | err = device_register(&dev->dev); | 345 | * driver. |
346 | */ | ||
347 | err = device_add(&dev->dev); | ||
336 | if (err) | 348 | if (err) |
337 | ida_simple_remove(&virtio_index_ida, dev->index); | 349 | ida_simple_remove(&virtio_index_ida, dev->index); |
338 | out: | 350 | out: |