Commit 4c879170296174bde05cd1c643dac16594edee77

Authored by Steffen Klassert
Committed by Herbert Xu
1 parent 7e3de7b1be

padata: Check for valid padata instance on start

This patch introduces the PADATA_INVALID flag which is
checked on padata start. This will be used to mark a padata
instance as invalid, if the padata cpumask does not intersect
with the active cpumask. we change padata_start to return an
error if the PADATA_INVALID is set. Also we adapt the only
padata user, pcrypt to this change.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Showing 3 changed files with 32 additions and 8 deletions Side-by-side Diff

... ... @@ -385,6 +385,7 @@
385 385  
386 386 static int __init pcrypt_init(void)
387 387 {
  388 + int err = -ENOMEM;
388 389 encwq = create_workqueue("pencrypt");
389 390 if (!encwq)
390 391 goto err;
391 392  
392 393  
393 394  
... ... @@ -400,14 +401,22 @@
400 401  
401 402 pcrypt_dec_padata = padata_alloc(cpu_possible_mask, decwq);
402 403 if (!pcrypt_dec_padata)
403   - goto err_free_padata;
  404 + goto err_free_enc_padata;
404 405  
405   - padata_start(pcrypt_enc_padata);
406   - padata_start(pcrypt_dec_padata);
  406 + err = padata_start(pcrypt_enc_padata);
  407 + if (err)
  408 + goto err_free_dec_padata;
407 409  
  410 + err = padata_start(pcrypt_dec_padata);
  411 + if (err)
  412 + goto err_free_dec_padata;
  413 +
408 414 return crypto_register_template(&pcrypt_tmpl);
409 415  
410   -err_free_padata:
  416 +err_free_dec_padata:
  417 + padata_free(pcrypt_dec_padata);
  418 +
  419 +err_free_enc_padata:
411 420 padata_free(pcrypt_enc_padata);
412 421  
413 422 err_destroy_decwq:
... ... @@ -417,7 +426,7 @@
417 426 destroy_workqueue(encwq);
418 427  
419 428 err:
420   - return -ENOMEM;
  429 + return err;
421 430 }
422 431  
423 432 static void __exit pcrypt_exit(void)
include/linux/padata.h
... ... @@ -126,6 +126,7 @@
126 126 u8 flags;
127 127 #define PADATA_INIT 1
128 128 #define PADATA_RESET 2
  129 +#define PADATA_INVALID 4
129 130 };
130 131  
131 132 extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
... ... @@ -138,7 +139,7 @@
138 139 cpumask_var_t cpumask);
139 140 extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
140 141 extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
141   -extern void padata_start(struct padata_instance *pinst);
  142 +extern int padata_start(struct padata_instance *pinst);
142 143 extern void padata_stop(struct padata_instance *pinst);
143 144 #endif
... ... @@ -485,6 +485,11 @@
485 485 BUG_ON(atomic_read(&pd->refcnt) != 0);
486 486 }
487 487  
  488 +static void __padata_start(struct padata_instance *pinst)
  489 +{
  490 + pinst->flags |= PADATA_INIT;
  491 +}
  492 +
488 493 /* Replace the internal control stucture with a new one. */
489 494 static void padata_replace(struct padata_instance *pinst,
490 495 struct parallel_data *pd_new)
491 496  
492 497  
493 498  
... ... @@ -619,11 +624,20 @@
619 624 *
620 625 * @pinst: padata instance to start
621 626 */
622   -void padata_start(struct padata_instance *pinst)
  627 +int padata_start(struct padata_instance *pinst)
623 628 {
  629 + int err = 0;
  630 +
624 631 mutex_lock(&pinst->lock);
625   - pinst->flags |= PADATA_INIT;
  632 +
  633 + if (pinst->flags & PADATA_INVALID)
  634 + err =-EINVAL;
  635 +
  636 + __padata_start(pinst);
  637 +
626 638 mutex_unlock(&pinst->lock);
  639 +
  640 + return err;
627 641 }
628 642 EXPORT_SYMBOL(padata_start);
629 643