Skip to content

Commit

Permalink
crypto: ccp - Check for CCP before registering crypto algs
Browse files Browse the repository at this point in the history
If the ccp is built as a built-in module, then ccp-crypto (whether
built as a module or a built-in module) will be able to load and
it will register its crypto algorithms.  If the system does not have
a CCP this will result in -ENODEV being returned whenever a command
is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP
on the system.  The ccp-crypto module can use this to determine if it
should register it's crypto alogorithms.

Cc: [email protected]
Reported-by: Scot Doyle <[email protected]>
Signed-off-by: Tom Lendacky <[email protected]>
Tested-by: Scot Doyle <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
tlendacky authored and herbertx committed Sep 24, 2014
1 parent 413e557 commit c9f21cb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/crypto/ccp/ccp-crypto-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ static int ccp_crypto_init(void)
{
int ret;

ret = ccp_present();
if (ret)
return ret;

spin_lock_init(&req_queue_lock);
INIT_LIST_HEAD(&req_queue.cmds);
req_queue.backlog = &req_queue.cmds;
Expand Down
14 changes: 14 additions & 0 deletions drivers/crypto/ccp/ccp-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ static inline void ccp_del_device(struct ccp_device *ccp)
ccp_dev = NULL;
}

/**
* ccp_present - check if a CCP device is present
*
* Returns zero if a CCP device is present, -ENODEV otherwise.
*/
int ccp_present(void)
{
if (ccp_get_device())
return 0;

return -ENODEV;
}
EXPORT_SYMBOL_GPL(ccp_present);

/**
* ccp_enqueue_cmd - queue an operation for processing by the CCP
*
Expand Down
12 changes: 12 additions & 0 deletions include/linux/ccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ struct ccp_cmd;
#if defined(CONFIG_CRYPTO_DEV_CCP_DD) || \
defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE)

/**
* ccp_present - check if a CCP device is present
*
* Returns zero if a CCP device is present, -ENODEV otherwise.
*/
int ccp_present(void);

/**
* ccp_enqueue_cmd - queue an operation for processing by the CCP
*
Expand Down Expand Up @@ -53,6 +60,11 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd);

#else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */

static inline int ccp_present(void)
{
return -ENODEV;
}

static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
{
return -ENODEV;
Expand Down

0 comments on commit c9f21cb

Please sign in to comment.