diff options
author | Ohad Ben-Cohen <ohad@wizery.com> | 2012-07-02 04:41:16 -0400 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2012-07-05 17:53:25 -0400 |
commit | c6b5a27628faf6657b741d828a1462d832d0dbc5 (patch) | |
tree | 3f5bcb10c6d2b1e395330536476d471415632832 | |
parent | 7183a2a799b81490354973117ecd810c23cdc668 (diff) |
remoteproc: simplify unregister/free interfaces
Simplify the unregister/free interfaces, and make them easier
to understand and use, by moving to a symmetric and consistent
alloc() -> register() -> unregister() -> free() flow.
To create and register an rproc instance, one needed to invoke
rproc_alloc() followed by rproc_register().
To unregister and free an rproc instance, one now needs to invoke
rproc_unregister() followed by rproc_free().
Cc: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
-rw-r--r-- | Documentation/remoteproc.txt | 21 | ||||
-rw-r--r-- | drivers/remoteproc/omap_remoteproc.c | 5 | ||||
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 25 |
3 files changed, 20 insertions, 31 deletions
diff --git a/Documentation/remoteproc.txt b/Documentation/remoteproc.txt index 70a048cd3fa3..ad6ded4bca5c 100644 --- a/Documentation/remoteproc.txt +++ b/Documentation/remoteproc.txt | |||
@@ -120,14 +120,14 @@ int dummy_rproc_example(struct rproc *my_rproc) | |||
120 | On success, the new rproc is returned, and on failure, NULL. | 120 | On success, the new rproc is returned, and on failure, NULL. |
121 | 121 | ||
122 | Note: _never_ directly deallocate @rproc, even if it was not registered | 122 | Note: _never_ directly deallocate @rproc, even if it was not registered |
123 | yet. Instead, if you just need to unroll rproc_alloc(), use rproc_free(). | 123 | yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). |
124 | 124 | ||
125 | void rproc_free(struct rproc *rproc) | 125 | void rproc_free(struct rproc *rproc) |
126 | - Free an rproc handle that was allocated by rproc_alloc. | 126 | - Free an rproc handle that was allocated by rproc_alloc. |
127 | This function should _only_ be used if @rproc was only allocated, | 127 | This function essentially unrolls rproc_alloc(), by decrementing the |
128 | but not registered yet. | 128 | rproc's refcount. It doesn't directly free rproc; that would happen |
129 | If @rproc was already successfully registered (by calling | 129 | only if there are no other references to rproc and its refcount now |
130 | rproc_register()), then use rproc_unregister() instead. | 130 | dropped to zero. |
131 | 131 | ||
132 | int rproc_register(struct rproc *rproc) | 132 | int rproc_register(struct rproc *rproc) |
133 | - Register @rproc with the remoteproc framework, after it has been | 133 | - Register @rproc with the remoteproc framework, after it has been |
@@ -143,19 +143,14 @@ int dummy_rproc_example(struct rproc *my_rproc) | |||
143 | probed. | 143 | probed. |
144 | 144 | ||
145 | int rproc_unregister(struct rproc *rproc) | 145 | int rproc_unregister(struct rproc *rproc) |
146 | - Unregister a remote processor, and decrement its refcount. | 146 | - Unroll rproc_register(). |
147 | If its refcount drops to zero, then @rproc will be freed. If not, | ||
148 | it will be freed later once the last reference is dropped. | ||
149 | |||
150 | This function should be called when the platform specific rproc | 147 | This function should be called when the platform specific rproc |
151 | implementation decides to remove the rproc device. it should | 148 | implementation decides to remove the rproc device. it should |
152 | _only_ be called if a previous invocation of rproc_register() | 149 | _only_ be called if a previous invocation of rproc_register() |
153 | has completed successfully. | 150 | has completed successfully. |
154 | 151 | ||
155 | After rproc_unregister() returns, @rproc is _not_ valid anymore and | 152 | After rproc_unregister() returns, @rproc is still valid, and its |
156 | it shouldn't be used. More specifically, don't call rproc_free() | 153 | last refcount should be decremented by calling rproc_free(). |
157 | or try to directly free @rproc after rproc_unregister() returns; | ||
158 | none of these are needed, and calling them is a bug. | ||
159 | 154 | ||
160 | Returns 0 on success and -EINVAL if @rproc isn't valid. | 155 | Returns 0 on success and -EINVAL if @rproc isn't valid. |
161 | 156 | ||
diff --git a/drivers/remoteproc/omap_remoteproc.c b/drivers/remoteproc/omap_remoteproc.c index b5e6d2981741..4f2fe8fd7fe6 100644 --- a/drivers/remoteproc/omap_remoteproc.c +++ b/drivers/remoteproc/omap_remoteproc.c | |||
@@ -214,7 +214,10 @@ static int __devexit omap_rproc_remove(struct platform_device *pdev) | |||
214 | { | 214 | { |
215 | struct rproc *rproc = platform_get_drvdata(pdev); | 215 | struct rproc *rproc = platform_get_drvdata(pdev); |
216 | 216 | ||
217 | return rproc_unregister(rproc); | 217 | rproc_unregister(rproc); |
218 | rproc_free(rproc); | ||
219 | |||
220 | return 0; | ||
218 | } | 221 | } |
219 | 222 | ||
220 | static struct platform_driver omap_rproc_driver = { | 223 | static struct platform_driver omap_rproc_driver = { |
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index aa713aade30e..4a77dc1df3d8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
@@ -1472,7 +1472,7 @@ static struct device_type rproc_type = { | |||
1472 | * On success the new rproc is returned, and on failure, NULL. | 1472 | * On success the new rproc is returned, and on failure, NULL. |
1473 | * | 1473 | * |
1474 | * Note: _never_ directly deallocate @rproc, even if it was not registered | 1474 | * Note: _never_ directly deallocate @rproc, even if it was not registered |
1475 | * yet. Instead, if you just need to unroll rproc_alloc(), use rproc_free(). | 1475 | * yet. Instead, when you need to unroll rproc_alloc(), use rproc_free(). |
1476 | */ | 1476 | */ |
1477 | struct rproc *rproc_alloc(struct device *dev, const char *name, | 1477 | struct rproc *rproc_alloc(struct device *dev, const char *name, |
1478 | const struct rproc_ops *ops, | 1478 | const struct rproc_ops *ops, |
@@ -1526,14 +1526,13 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, | |||
1526 | EXPORT_SYMBOL(rproc_alloc); | 1526 | EXPORT_SYMBOL(rproc_alloc); |
1527 | 1527 | ||
1528 | /** | 1528 | /** |
1529 | * rproc_free() - free an rproc handle that was allocated by rproc_alloc | 1529 | * rproc_free() - unroll rproc_alloc() |
1530 | * @rproc: the remote processor handle | 1530 | * @rproc: the remote processor handle |
1531 | * | 1531 | * |
1532 | * This function should _only_ be used if @rproc was only allocated, | 1532 | * This function decrements the rproc dev refcount. |
1533 | * but not registered yet. | ||
1534 | * | 1533 | * |
1535 | * If @rproc was already successfully registered (by calling rproc_register()), | 1534 | * If no one holds any reference to rproc anymore, then its refcount would |
1536 | * then use rproc_unregister() instead. | 1535 | * now drop to zero, and it would be freed. |
1537 | */ | 1536 | */ |
1538 | void rproc_free(struct rproc *rproc) | 1537 | void rproc_free(struct rproc *rproc) |
1539 | { | 1538 | { |
@@ -1545,19 +1544,14 @@ EXPORT_SYMBOL(rproc_free); | |||
1545 | * rproc_unregister() - unregister a remote processor | 1544 | * rproc_unregister() - unregister a remote processor |
1546 | * @rproc: rproc handle to unregister | 1545 | * @rproc: rproc handle to unregister |
1547 | * | 1546 | * |
1548 | * Unregisters a remote processor, and decrements its refcount. | ||
1549 | * If its refcount drops to zero, then @rproc will be freed. If not, | ||
1550 | * it will be freed later once the last reference is dropped. | ||
1551 | * | ||
1552 | * This function should be called when the platform specific rproc | 1547 | * This function should be called when the platform specific rproc |
1553 | * implementation decides to remove the rproc device. it should | 1548 | * implementation decides to remove the rproc device. it should |
1554 | * _only_ be called if a previous invocation of rproc_register() | 1549 | * _only_ be called if a previous invocation of rproc_register() |
1555 | * has completed successfully. | 1550 | * has completed successfully. |
1556 | * | 1551 | * |
1557 | * After rproc_unregister() returns, @rproc is _not_ valid anymore and | 1552 | * After rproc_unregister() returns, @rproc isn't freed yet, because |
1558 | * it shouldn't be used. More specifically, don't call rproc_free() | 1553 | * of the outstanding reference created by rproc_alloc. To decrement that |
1559 | * or try to directly free @rproc after rproc_unregister() returns; | 1554 | * one last refcount, one still needs to call rproc_free(). |
1560 | * none of these are needed, and calling them is a bug. | ||
1561 | * | 1555 | * |
1562 | * Returns 0 on success and -EINVAL if @rproc isn't valid. | 1556 | * Returns 0 on success and -EINVAL if @rproc isn't valid. |
1563 | */ | 1557 | */ |
@@ -1580,9 +1574,6 @@ int rproc_unregister(struct rproc *rproc) | |||
1580 | 1574 | ||
1581 | device_del(&rproc->dev); | 1575 | device_del(&rproc->dev); |
1582 | 1576 | ||
1583 | /* unroll rproc_alloc. TODO: we may want to let the users do that */ | ||
1584 | put_device(&rproc->dev); | ||
1585 | |||
1586 | return 0; | 1577 | return 0; |
1587 | } | 1578 | } |
1588 | EXPORT_SYMBOL(rproc_unregister); | 1579 | EXPORT_SYMBOL(rproc_unregister); |