Skip to content

Commit

Permalink
padata: Check for valid padata instance on start
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
klassert authored and herbertx committed Jul 14, 2010
1 parent 7e3de7b commit 4c87917
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
19 changes: 14 additions & 5 deletions crypto/pcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ static struct crypto_template pcrypt_tmpl = {

static int __init pcrypt_init(void)
{
int err = -ENOMEM;
encwq = create_workqueue("pencrypt");
if (!encwq)
goto err;
Expand All @@ -400,14 +401,22 @@ static int __init pcrypt_init(void)

pcrypt_dec_padata = padata_alloc(cpu_possible_mask, decwq);
if (!pcrypt_dec_padata)
goto err_free_padata;
goto err_free_enc_padata;

padata_start(pcrypt_enc_padata);
padata_start(pcrypt_dec_padata);
err = padata_start(pcrypt_enc_padata);
if (err)
goto err_free_dec_padata;

err = padata_start(pcrypt_dec_padata);
if (err)
goto err_free_dec_padata;

return crypto_register_template(&pcrypt_tmpl);

err_free_padata:
err_free_dec_padata:
padata_free(pcrypt_dec_padata);

err_free_enc_padata:
padata_free(pcrypt_enc_padata);

err_destroy_decwq:
Expand All @@ -417,7 +426,7 @@ static int __init pcrypt_init(void)
destroy_workqueue(encwq);

err:
return -ENOMEM;
return err;
}

static void __exit pcrypt_exit(void)
Expand Down
3 changes: 2 additions & 1 deletion include/linux/padata.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct padata_instance {
u8 flags;
#define PADATA_INIT 1
#define PADATA_RESET 2
#define PADATA_INVALID 4
};

extern struct padata_instance *padata_alloc(const struct cpumask *cpumask,
Expand All @@ -138,6 +139,6 @@ extern int padata_set_cpumask(struct padata_instance *pinst,
cpumask_var_t cpumask);
extern int padata_add_cpu(struct padata_instance *pinst, int cpu);
extern int padata_remove_cpu(struct padata_instance *pinst, int cpu);
extern void padata_start(struct padata_instance *pinst);
extern int padata_start(struct padata_instance *pinst);
extern void padata_stop(struct padata_instance *pinst);
#endif
18 changes: 16 additions & 2 deletions kernel/padata.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ static void padata_flush_queues(struct parallel_data *pd)
BUG_ON(atomic_read(&pd->refcnt) != 0);
}

static void __padata_start(struct padata_instance *pinst)
{
pinst->flags |= PADATA_INIT;
}

/* Replace the internal control stucture with a new one. */
static void padata_replace(struct padata_instance *pinst,
struct parallel_data *pd_new)
Expand Down Expand Up @@ -619,11 +624,20 @@ EXPORT_SYMBOL(padata_remove_cpu);
*
* @pinst: padata instance to start
*/
void padata_start(struct padata_instance *pinst)
int padata_start(struct padata_instance *pinst)
{
int err = 0;

mutex_lock(&pinst->lock);
pinst->flags |= PADATA_INIT;

if (pinst->flags & PADATA_INVALID)
err =-EINVAL;

__padata_start(pinst);

mutex_unlock(&pinst->lock);

return err;
}
EXPORT_SYMBOL(padata_start);

Expand Down

0 comments on commit 4c87917

Please sign in to comment.