mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	crypto: api - Add cra_type->destroy hook
Add a cra_type->destroy hook so that resources can be freed after the last user of a registered algorithm is gone. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
		
							parent
							
								
									01894c8488
								
							
						
					
					
						commit
						3d6979bf3b
					
				
					 2 changed files with 14 additions and 2 deletions
				
			
		
							
								
								
									
										10
									
								
								crypto/api.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								crypto/api.c
									
									
									
									
									
								
							| 
						 | 
					@ -707,5 +707,15 @@ void crypto_req_done(void *data, int err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(crypto_req_done);
 | 
					EXPORT_SYMBOL_GPL(crypto_req_done);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void crypto_destroy_alg(struct crypto_alg *alg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (alg->cra_type && alg->cra_type->destroy)
 | 
				
			||||||
 | 
							alg->cra_type->destroy(alg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (alg->cra_destroy)
 | 
				
			||||||
 | 
							alg->cra_destroy(alg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(crypto_destroy_alg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MODULE_DESCRIPTION("Cryptographic core API");
 | 
					MODULE_DESCRIPTION("Cryptographic core API");
 | 
				
			||||||
MODULE_LICENSE("GPL");
 | 
					MODULE_LICENSE("GPL");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +40,7 @@ struct crypto_type {
 | 
				
			||||||
	void (*show)(struct seq_file *m, struct crypto_alg *alg);
 | 
						void (*show)(struct seq_file *m, struct crypto_alg *alg);
 | 
				
			||||||
	int (*report)(struct sk_buff *skb, struct crypto_alg *alg);
 | 
						int (*report)(struct sk_buff *skb, struct crypto_alg *alg);
 | 
				
			||||||
	void (*free)(struct crypto_instance *inst);
 | 
						void (*free)(struct crypto_instance *inst);
 | 
				
			||||||
 | 
						void (*destroy)(struct crypto_alg *alg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned int type;
 | 
						unsigned int type;
 | 
				
			||||||
	unsigned int maskclear;
 | 
						unsigned int maskclear;
 | 
				
			||||||
| 
						 | 
					@ -127,6 +128,7 @@ void *crypto_create_tfm_node(struct crypto_alg *alg,
 | 
				
			||||||
			const struct crypto_type *frontend, int node);
 | 
								const struct crypto_type *frontend, int node);
 | 
				
			||||||
void *crypto_clone_tfm(const struct crypto_type *frontend,
 | 
					void *crypto_clone_tfm(const struct crypto_type *frontend,
 | 
				
			||||||
		       struct crypto_tfm *otfm);
 | 
							       struct crypto_tfm *otfm);
 | 
				
			||||||
 | 
					void crypto_destroy_alg(struct crypto_alg *alg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void *crypto_create_tfm(struct crypto_alg *alg,
 | 
					static inline void *crypto_create_tfm(struct crypto_alg *alg,
 | 
				
			||||||
			const struct crypto_type *frontend)
 | 
								const struct crypto_type *frontend)
 | 
				
			||||||
| 
						 | 
					@ -163,8 +165,8 @@ static inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline void crypto_alg_put(struct crypto_alg *alg)
 | 
					static inline void crypto_alg_put(struct crypto_alg *alg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
 | 
						if (refcount_dec_and_test(&alg->cra_refcnt))
 | 
				
			||||||
		alg->cra_destroy(alg);
 | 
							crypto_destroy_alg(alg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int crypto_tmpl_get(struct crypto_template *tmpl)
 | 
					static inline int crypto_tmpl_get(struct crypto_template *tmpl)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue