Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: xcbc - use crypto_grab_cipher() and simplify error paths

Make the xcbc template use the new function crypto_grab_cipher() to
initialize its cipher spawn.

This is needed to make all spawns be initialized in a consistent way.

This required making xcbc_create() allocate the instance directly rather
than use shash_alloc_instance().

Also simplify the error handling by taking advantage of crypto_drop_*()
now accepting (as a no-op) spawns that haven't been initialized yet, and
by taking advantage of crypto_grab_*() now handling ERR_PTR() names.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
1e212a6a 3b4e73d8

+18 -24
+18 -24
crypto/xcbc.c
··· 188 188 static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb) 189 189 { 190 190 struct shash_instance *inst; 191 + struct crypto_cipher_spawn *spawn; 191 192 struct crypto_alg *alg; 192 193 unsigned long alignmask; 193 194 int err; ··· 197 196 if (err) 198 197 return err; 199 198 200 - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, 201 - CRYPTO_ALG_TYPE_MASK); 202 - if (IS_ERR(alg)) 203 - return PTR_ERR(alg); 199 + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); 200 + if (!inst) 201 + return -ENOMEM; 202 + spawn = shash_instance_ctx(inst); 204 203 205 - switch(alg->cra_blocksize) { 206 - case XCBC_BLOCKSIZE: 207 - break; 208 - default: 209 - goto out_put_alg; 210 - } 211 - 212 - inst = shash_alloc_instance("xcbc", alg); 213 - err = PTR_ERR(inst); 214 - if (IS_ERR(inst)) 215 - goto out_put_alg; 216 - 217 - err = crypto_init_spawn(shash_instance_ctx(inst), alg, 218 - shash_crypto_instance(inst), 219 - CRYPTO_ALG_TYPE_MASK); 204 + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), 205 + crypto_attr_alg_name(tb[1]), 0, 0); 220 206 if (err) 221 - goto out_free_inst; 207 + goto err_free_inst; 208 + alg = crypto_spawn_cipher_alg(spawn); 209 + 210 + err = -EINVAL; 211 + if (alg->cra_blocksize != XCBC_BLOCKSIZE) 212 + goto err_free_inst; 213 + 214 + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); 215 + if (err) 216 + goto err_free_inst; 222 217 223 218 alignmask = alg->cra_alignmask | 3; 224 219 inst->alg.base.cra_alignmask = alignmask; ··· 241 244 242 245 err = shash_register_instance(tmpl, inst); 243 246 if (err) { 244 - out_free_inst: 247 + err_free_inst: 245 248 shash_free_instance(shash_crypto_instance(inst)); 246 249 } 247 - 248 - out_put_alg: 249 - crypto_mod_put(alg); 250 250 return err; 251 251 } 252 252