diff options
author | Ohad Ben-Cohen <ohad@wizery.com> | 2012-05-30 15:02:24 -0400 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2012-07-05 17:53:25 -0400 |
commit | 7183a2a799b81490354973117ecd810c23cdc668 (patch) | |
tree | cfd720d9a745f8d010120ca434246336423aea32 /drivers/remoteproc | |
parent | b5ab5e24e960b9f780a4cc96815cfd4b0d412720 (diff) |
remoteproc: remove the now-redundant kref
Now that every rproc instance contains a device, we don't need a
kref anymore to maintain the refcount of the rproc instances:
that's what device are good with!
This patch removes the now-redundant kref, and switches to
{get, put}_device instead of kref_{get, put}.
We also don't need the kref's release function anymore, and instead,
we just utilize the class's release handler (which is now responsible
for all memory de-allocations).
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Fernando Guzman Lugo <fernando.lugo@ti.com>
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Diffstat (limited to 'drivers/remoteproc')
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 50 | ||||
-rw-r--r-- | drivers/remoteproc/remoteproc_virtio.c | 8 |
2 files changed, 15 insertions, 43 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 25f937843836..aa713aade30e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
@@ -1257,42 +1257,12 @@ out: | |||
1257 | } | 1257 | } |
1258 | EXPORT_SYMBOL(rproc_shutdown); | 1258 | EXPORT_SYMBOL(rproc_shutdown); |
1259 | 1259 | ||
1260 | /** | ||
1261 | * rproc_release() - completely deletes the existence of a remote processor | ||
1262 | * @kref: the rproc's kref | ||
1263 | * | ||
1264 | * This function should _never_ be called directly. | ||
1265 | * | ||
1266 | * The only reasonable location to use it is as an argument when kref_put'ing | ||
1267 | * @rproc's refcount. | ||
1268 | * | ||
1269 | * This way it will be called when no one holds a valid pointer to this @rproc | ||
1270 | * anymore (and obviously after it is removed from the rprocs klist). | ||
1271 | * | ||
1272 | * Note: this function is not static because rproc_vdev_release() needs it when | ||
1273 | * it decrements @rproc's refcount. | ||
1274 | */ | ||
1275 | void rproc_release(struct kref *kref) | ||
1276 | { | ||
1277 | struct rproc *rproc = container_of(kref, struct rproc, refcount); | ||
1278 | |||
1279 | dev_info(&rproc->dev, "removing %s\n", rproc->name); | ||
1280 | |||
1281 | rproc_delete_debug_dir(rproc); | ||
1282 | |||
1283 | /* | ||
1284 | * At this point no one holds a reference to rproc anymore, | ||
1285 | * so we can directly unroll rproc_alloc() | ||
1286 | */ | ||
1287 | rproc_free(rproc); | ||
1288 | } | ||
1289 | |||
1290 | /* will be called when an rproc is added to the rprocs klist */ | 1260 | /* will be called when an rproc is added to the rprocs klist */ |
1291 | static void klist_rproc_get(struct klist_node *n) | 1261 | static void klist_rproc_get(struct klist_node *n) |
1292 | { | 1262 | { |
1293 | struct rproc *rproc = container_of(n, struct rproc, node); | 1263 | struct rproc *rproc = container_of(n, struct rproc, node); |
1294 | 1264 | ||
1295 | kref_get(&rproc->refcount); | 1265 | get_device(&rproc->dev); |
1296 | } | 1266 | } |
1297 | 1267 | ||
1298 | /* will be called when an rproc is removed from the rprocs klist */ | 1268 | /* will be called when an rproc is removed from the rprocs klist */ |
@@ -1300,7 +1270,7 @@ static void klist_rproc_put(struct klist_node *n) | |||
1300 | { | 1270 | { |
1301 | struct rproc *rproc = container_of(n, struct rproc, node); | 1271 | struct rproc *rproc = container_of(n, struct rproc, node); |
1302 | 1272 | ||
1303 | kref_put(&rproc->refcount, rproc_release); | 1273 | put_device(&rproc->dev); |
1304 | } | 1274 | } |
1305 | 1275 | ||
1306 | static struct rproc *next_rproc(struct klist_iter *i) | 1276 | static struct rproc *next_rproc(struct klist_iter *i) |
@@ -1342,7 +1312,7 @@ struct rproc *rproc_get_by_name(const char *name) | |||
1342 | klist_iter_init(&rprocs, &i); | 1312 | klist_iter_init(&rprocs, &i); |
1343 | while ((rproc = next_rproc(&i)) != NULL) | 1313 | while ((rproc = next_rproc(&i)) != NULL) |
1344 | if (!strcmp(rproc->name, name)) { | 1314 | if (!strcmp(rproc->name, name)) { |
1345 | kref_get(&rproc->refcount); | 1315 | get_device(&rproc->dev); |
1346 | break; | 1316 | break; |
1347 | } | 1317 | } |
1348 | klist_iter_exit(&i); | 1318 | klist_iter_exit(&i); |
@@ -1355,7 +1325,7 @@ struct rproc *rproc_get_by_name(const char *name) | |||
1355 | 1325 | ||
1356 | ret = rproc_boot(rproc); | 1326 | ret = rproc_boot(rproc); |
1357 | if (ret < 0) { | 1327 | if (ret < 0) { |
1358 | kref_put(&rproc->refcount, rproc_release); | 1328 | put_device(&rproc->dev); |
1359 | return NULL; | 1329 | return NULL; |
1360 | } | 1330 | } |
1361 | 1331 | ||
@@ -1382,7 +1352,7 @@ void rproc_put(struct rproc *rproc) | |||
1382 | rproc_shutdown(rproc); | 1352 | rproc_shutdown(rproc); |
1383 | 1353 | ||
1384 | /* downref rproc's refcount */ | 1354 | /* downref rproc's refcount */ |
1385 | kref_put(&rproc->refcount, rproc_release); | 1355 | put_device(&rproc->dev); |
1386 | } | 1356 | } |
1387 | EXPORT_SYMBOL(rproc_put); | 1357 | EXPORT_SYMBOL(rproc_put); |
1388 | 1358 | ||
@@ -1463,6 +1433,10 @@ static void rproc_type_release(struct device *dev) | |||
1463 | { | 1433 | { |
1464 | struct rproc *rproc = container_of(dev, struct rproc, dev); | 1434 | struct rproc *rproc = container_of(dev, struct rproc, dev); |
1465 | 1435 | ||
1436 | dev_info(&rproc->dev, "releasing %s\n", rproc->name); | ||
1437 | |||
1438 | rproc_delete_debug_dir(rproc); | ||
1439 | |||
1466 | idr_remove_all(&rproc->notifyids); | 1440 | idr_remove_all(&rproc->notifyids); |
1467 | idr_destroy(&rproc->notifyids); | 1441 | idr_destroy(&rproc->notifyids); |
1468 | 1442 | ||
@@ -1536,8 +1510,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, | |||
1536 | 1510 | ||
1537 | atomic_set(&rproc->power, 0); | 1511 | atomic_set(&rproc->power, 0); |
1538 | 1512 | ||
1539 | kref_init(&rproc->refcount); | ||
1540 | |||
1541 | mutex_init(&rproc->lock); | 1513 | mutex_init(&rproc->lock); |
1542 | 1514 | ||
1543 | idr_init(&rproc->notifyids); | 1515 | idr_init(&rproc->notifyids); |
@@ -1608,8 +1580,8 @@ int rproc_unregister(struct rproc *rproc) | |||
1608 | 1580 | ||
1609 | device_del(&rproc->dev); | 1581 | device_del(&rproc->dev); |
1610 | 1582 | ||
1611 | /* the rproc will only be released after its refcount drops to zero */ | 1583 | /* unroll rproc_alloc. TODO: we may want to let the users do that */ |
1612 | kref_put(&rproc->refcount, rproc_release); | 1584 | put_device(&rproc->dev); |
1613 | 1585 | ||
1614 | return 0; | 1586 | return 0; |
1615 | } | 1587 | } |
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index b6621831a58a..3541b4492f64 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c | |||
@@ -225,7 +225,7 @@ static struct virtio_config_ops rproc_virtio_config_ops = { | |||
225 | 225 | ||
226 | /* | 226 | /* |
227 | * This function is called whenever vdev is released, and is responsible | 227 | * This function is called whenever vdev is released, and is responsible |
228 | * to decrement the remote processor's refcount taken when vdev was | 228 | * to decrement the remote processor's refcount which was taken when vdev was |
229 | * added. | 229 | * added. |
230 | * | 230 | * |
231 | * Never call this function directly; it will be called by the driver | 231 | * Never call this function directly; it will be called by the driver |
@@ -240,7 +240,7 @@ static void rproc_vdev_release(struct device *dev) | |||
240 | list_del(&rvdev->node); | 240 | list_del(&rvdev->node); |
241 | kfree(rvdev); | 241 | kfree(rvdev); |
242 | 242 | ||
243 | kref_put(&rproc->refcount, rproc_release); | 243 | put_device(&rproc->dev); |
244 | } | 244 | } |
245 | 245 | ||
246 | /** | 246 | /** |
@@ -272,11 +272,11 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) | |||
272 | * Therefore we must increment the rproc refcount here, and decrement | 272 | * Therefore we must increment the rproc refcount here, and decrement |
273 | * it _only_ when the vdev is released. | 273 | * it _only_ when the vdev is released. |
274 | */ | 274 | */ |
275 | kref_get(&rproc->refcount); | 275 | get_device(&rproc->dev); |
276 | 276 | ||
277 | ret = register_virtio_device(vdev); | 277 | ret = register_virtio_device(vdev); |
278 | if (ret) { | 278 | if (ret) { |
279 | kref_put(&rproc->refcount, rproc_release); | 279 | put_device(&rproc->dev); |
280 | dev_err(dev, "failed to register vdev: %d\n", ret); | 280 | dev_err(dev, "failed to register vdev: %d\n", ret); |
281 | goto out; | 281 | goto out; |
282 | } | 282 | } |