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: cmac - use crypto_grab_cipher() and simplify error paths

Make the cmac 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 cmac_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
1d0459cd 16672970

+15 -18
+15 -18
crypto/cmac.c
··· 222 222 static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb) 223 223 { 224 224 struct shash_instance *inst; 225 + struct crypto_cipher_spawn *spawn; 225 226 struct crypto_alg *alg; 226 227 unsigned long alignmask; 227 228 int err; ··· 231 230 if (err) 232 231 return err; 233 232 234 - alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_CIPHER, 235 - CRYPTO_ALG_TYPE_MASK); 236 - if (IS_ERR(alg)) 237 - return PTR_ERR(alg); 233 + inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); 234 + if (!inst) 235 + return -ENOMEM; 236 + spawn = shash_instance_ctx(inst); 237 + 238 + err = crypto_grab_cipher(spawn, shash_crypto_instance(inst), 239 + crypto_attr_alg_name(tb[1]), 0, 0); 240 + if (err) 241 + goto err_free_inst; 242 + alg = crypto_spawn_cipher_alg(spawn); 238 243 239 244 switch (alg->cra_blocksize) { 240 245 case 16: ··· 248 241 break; 249 242 default: 250 243 err = -EINVAL; 251 - goto out_put_alg; 244 + goto err_free_inst; 252 245 } 253 246 254 - inst = shash_alloc_instance("cmac", alg); 255 - err = PTR_ERR(inst); 256 - if (IS_ERR(inst)) 257 - goto out_put_alg; 258 - 259 - err = crypto_init_spawn(shash_instance_ctx(inst), alg, 260 - shash_crypto_instance(inst), 261 - CRYPTO_ALG_TYPE_MASK); 247 + err = crypto_inst_setname(shash_crypto_instance(inst), tmpl->name, alg); 262 248 if (err) 263 - goto out_free_inst; 249 + goto err_free_inst; 264 250 265 251 alignmask = alg->cra_alignmask; 266 252 inst->alg.base.cra_alignmask = alignmask; ··· 282 282 283 283 err = shash_register_instance(tmpl, inst); 284 284 if (err) { 285 - out_free_inst: 285 + err_free_inst: 286 286 shash_free_instance(shash_crypto_instance(inst)); 287 287 } 288 - 289 - out_put_alg: 290 - crypto_mod_put(alg); 291 288 return err; 292 289 } 293 290