Skip to content

Commit 02244ba

Browse files
committed
crypto: api - Add more comments to crypto_remove_spawns
This patch explains the logic behind crypto_remove_spawns and its underling crypto_more_spawns. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 4f87ee1 commit 02244ba

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎crypto/algapi.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ static void crypto_destroy_instance(struct crypto_alg *alg)
8282
crypto_tmpl_put(tmpl);
8383
}
8484

85+
/*
86+
* This function adds a spawn to the list secondary_spawns which
87+
* will be used at the end of crypto_remove_spawns to unregister
88+
* instances, unless the spawn happens to be one that is depended
89+
* on by the new algorithm (nalg in crypto_remove_spawns).
90+
*
91+
* This function is also responsible for resurrecting any algorithms
92+
* in the dependency chain of nalg by unsetting n->dead.
93+
*/
8594
static struct list_head *crypto_more_spawns(struct crypto_alg *alg,
8695
struct list_head *stack,
8796
struct list_head *top,
@@ -128,6 +137,12 @@ static void crypto_remove_instance(struct crypto_instance *inst,
128137
BUG_ON(!list_empty(&inst->alg.cra_users));
129138
}
130139

140+
/*
141+
* Given an algorithm alg, remove all algorithms that depend on it
142+
* through spawns. If nalg is not null, then exempt any algorithms
143+
* that is depended on by nalg. This is useful when nalg itself
144+
* depends on alg.
145+
*/
131146
void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
132147
struct crypto_alg *nalg)
133148
{
@@ -146,6 +161,11 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
146161
list_move(&spawn->list, &top);
147162
}
148163

164+
/*
165+
* Perform a depth-first walk starting from alg through
166+
* the cra_users tree. The list stack records the path
167+
* from alg to the current spawn.
168+
*/
149169
spawns = &top;
150170
do {
151171
while (!list_empty(spawns)) {
@@ -180,6 +200,11 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
180200
} while ((spawns = crypto_more_spawns(alg, &stack, &top,
181201
&secondary_spawns)));
182202

203+
/*
204+
* Remove all instances that are marked as dead. Also
205+
* complete the resurrection of the others by moving them
206+
* back to the cra_users list.
207+
*/
183208
list_for_each_entry_safe(spawn, n, &secondary_spawns, list) {
184209
if (!spawn->dead)
185210
list_move(&spawn->list, &spawn->alg->cra_users);

0 commit comments

Comments
 (0)