diff options
author | Bjorn Andersson <bjorn.andersson@linaro.org> | 2016-10-19 22:40:06 -0400 |
---|---|---|
committer | Bjorn Andersson <bjorn.andersson@linaro.org> | 2016-11-15 00:52:15 -0500 |
commit | aab8d8022304b646fbf6eed5f6ac9bc21d54d2fd (patch) | |
tree | d93bd609e457d4280e16ba1f9125465a2345d1f8 | |
parent | be33c28fadc5442d30f0f9dc08f6b4e3664b12f7 (diff) |
remoteproc: Assign kref to rproc_vdev
No functional change
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 10 | ||||
-rw-r--r-- | drivers/remoteproc/remoteproc_internal.h | 1 | ||||
-rw-r--r-- | drivers/remoteproc/remoteproc_virtio.c | 10 | ||||
-rw-r--r-- | include/linux/remoteproc.h | 3 |
4 files changed, 20 insertions, 4 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index b5e314fe1f4c..67f581d0c488 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
@@ -356,6 +356,8 @@ static int rproc_handle_vdev(struct rproc *rproc, struct fw_rsc_vdev *rsc, | |||
356 | if (!rvdev) | 356 | if (!rvdev) |
357 | return -ENOMEM; | 357 | return -ENOMEM; |
358 | 358 | ||
359 | kref_init(&rvdev->refcount); | ||
360 | |||
359 | rvdev->rproc = rproc; | 361 | rvdev->rproc = rproc; |
360 | 362 | ||
361 | /* parse the vrings */ | 363 | /* parse the vrings */ |
@@ -384,6 +386,14 @@ free_rvdev: | |||
384 | return ret; | 386 | return ret; |
385 | } | 387 | } |
386 | 388 | ||
389 | void rproc_vdev_release(struct kref *ref) | ||
390 | { | ||
391 | struct rproc_vdev *rvdev = container_of(ref, struct rproc_vdev, refcount); | ||
392 | |||
393 | list_del(&rvdev->node); | ||
394 | kfree(rvdev); | ||
395 | } | ||
396 | |||
387 | /** | 397 | /** |
388 | * rproc_handle_trace() - handle a shared trace buffer resource | 398 | * rproc_handle_trace() - handle a shared trace buffer resource |
389 | * @rproc: the remote processor | 399 | * @rproc: the remote processor |
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index c2c3e4762b90..1e9e5b3f021c 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h | |||
@@ -49,6 +49,7 @@ struct rproc_fw_ops { | |||
49 | void rproc_release(struct kref *kref); | 49 | void rproc_release(struct kref *kref); |
50 | irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); | 50 | irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); |
51 | int rproc_boot_nowait(struct rproc *rproc); | 51 | int rproc_boot_nowait(struct rproc *rproc); |
52 | void rproc_vdev_release(struct kref *ref); | ||
52 | 53 | ||
53 | /* from remoteproc_virtio.c */ | 54 | /* from remoteproc_virtio.c */ |
54 | int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id); | 55 | int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id); |
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 01870a16d6d2..0d1ad3ed149d 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c | |||
@@ -282,14 +282,13 @@ static const struct virtio_config_ops rproc_virtio_config_ops = { | |||
282 | * Never call this function directly; it will be called by the driver | 282 | * Never call this function directly; it will be called by the driver |
283 | * core when needed. | 283 | * core when needed. |
284 | */ | 284 | */ |
285 | static void rproc_vdev_release(struct device *dev) | 285 | static void rproc_virtio_dev_release(struct device *dev) |
286 | { | 286 | { |
287 | struct virtio_device *vdev = dev_to_virtio(dev); | 287 | struct virtio_device *vdev = dev_to_virtio(dev); |
288 | struct rproc_vdev *rvdev = vdev_to_rvdev(vdev); | 288 | struct rproc_vdev *rvdev = vdev_to_rvdev(vdev); |
289 | struct rproc *rproc = vdev_to_rproc(vdev); | 289 | struct rproc *rproc = vdev_to_rproc(vdev); |
290 | 290 | ||
291 | list_del(&rvdev->node); | 291 | kref_put(&rvdev->refcount, rproc_vdev_release); |
292 | kfree(rvdev); | ||
293 | 292 | ||
294 | put_device(&rproc->dev); | 293 | put_device(&rproc->dev); |
295 | } | 294 | } |
@@ -313,7 +312,7 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) | |||
313 | vdev->id.device = id, | 312 | vdev->id.device = id, |
314 | vdev->config = &rproc_virtio_config_ops, | 313 | vdev->config = &rproc_virtio_config_ops, |
315 | vdev->dev.parent = dev; | 314 | vdev->dev.parent = dev; |
316 | vdev->dev.release = rproc_vdev_release; | 315 | vdev->dev.release = rproc_virtio_dev_release; |
317 | 316 | ||
318 | /* | 317 | /* |
319 | * We're indirectly making a non-temporary copy of the rproc pointer | 318 | * We're indirectly making a non-temporary copy of the rproc pointer |
@@ -325,6 +324,9 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) | |||
325 | */ | 324 | */ |
326 | get_device(&rproc->dev); | 325 | get_device(&rproc->dev); |
327 | 326 | ||
327 | /* Reference the vdev and vring allocations */ | ||
328 | kref_get(&rvdev->refcount); | ||
329 | |||
328 | ret = register_virtio_device(vdev); | 330 | ret = register_virtio_device(vdev); |
329 | if (ret) { | 331 | if (ret) { |
330 | put_device(&rproc->dev); | 332 | put_device(&rproc->dev); |
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index f6d5e66854e4..5def5c84b9c0 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h | |||
@@ -487,6 +487,7 @@ struct rproc_vring { | |||
487 | 487 | ||
488 | /** | 488 | /** |
489 | * struct rproc_vdev - remoteproc state for a supported virtio device | 489 | * struct rproc_vdev - remoteproc state for a supported virtio device |
490 | * @refcount: reference counter for the vdev and vring allocations | ||
490 | * @node: list node | 491 | * @node: list node |
491 | * @rproc: the rproc handle | 492 | * @rproc: the rproc handle |
492 | * @vdev: the virio device | 493 | * @vdev: the virio device |
@@ -494,6 +495,8 @@ struct rproc_vring { | |||
494 | * @rsc_offset: offset of the vdev's resource entry | 495 | * @rsc_offset: offset of the vdev's resource entry |
495 | */ | 496 | */ |
496 | struct rproc_vdev { | 497 | struct rproc_vdev { |
498 | struct kref refcount; | ||
499 | |||
497 | struct list_head node; | 500 | struct list_head node; |
498 | struct rproc *rproc; | 501 | struct rproc *rproc; |
499 | struct virtio_device vdev; | 502 | struct virtio_device vdev; |