diff options
Diffstat (limited to 'drivers/crypto/ixp4xx_crypto.c')
| -rw-r--r-- | drivers/crypto/ixp4xx_crypto.c | 72 | 
1 files changed, 31 insertions, 41 deletions
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c index 21180d6cad6..f757a0f428b 100644 --- a/drivers/crypto/ixp4xx_crypto.c +++ b/drivers/crypto/ixp4xx_crypto.c @@ -218,23 +218,9 @@ static dma_addr_t crypt_phys;  static int support_aes = 1; -static void dev_release(struct device *dev) -{ -	return; -} -  #define DRIVER_NAME "ixp4xx_crypto" -static struct platform_device pseudo_dev = { -	.name = DRIVER_NAME, -	.id   = 0, -	.num_resources = 0, -	.dev  = { -		.coherent_dma_mask = DMA_BIT_MASK(32), -		.release = dev_release, -	} -}; -static struct device *dev = &pseudo_dev.dev; +static struct platform_device *pdev;  static inline dma_addr_t crypt_virt2phys(struct crypt_ctl *virt)  { @@ -263,6 +249,7 @@ static inline const struct ix_hash_algo *ix_hash(struct crypto_tfm *tfm)  static int setup_crypt_desc(void)  { +	struct device *dev = &pdev->dev;  	BUILD_BUG_ON(sizeof(struct crypt_ctl) != 64);  	crypt_virt = dma_alloc_coherent(dev,  			NPE_QLEN * sizeof(struct crypt_ctl), @@ -363,6 +350,7 @@ static void finish_scattered_hmac(struct crypt_ctl *crypt)  static void one_packet(dma_addr_t phys)  { +	struct device *dev = &pdev->dev;  	struct crypt_ctl *crypt;  	struct ixp_ctx *ctx;  	int failed; @@ -432,7 +420,7 @@ static void crypto_done_action(unsigned long arg)  	tasklet_schedule(&crypto_done_tasklet);  } -static int init_ixp_crypto(void) +static int init_ixp_crypto(struct device *dev)  {  	int ret = -ENODEV;  	u32 msg[2] = { 0, 0 }; @@ -519,7 +507,7 @@ err:  	return ret;  } -static void release_ixp_crypto(void) +static void release_ixp_crypto(struct device *dev)  {  	qmgr_disable_irq(RECV_QID);  	tasklet_kill(&crypto_done_tasklet); @@ -886,6 +874,7 @@ static int ablk_perform(struct ablkcipher_request *req, int encrypt)  	enum dma_data_direction src_direction = DMA_BIDIRECTIONAL;  	struct ablk_ctx *req_ctx = ablkcipher_request_ctx(req);  	struct buffer_desc src_hook; +	struct device *dev = &pdev->dev;  	gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?  				GFP_KERNEL : GFP_ATOMIC; @@ -1010,6 +999,7 @@ static int aead_perform(struct aead_request *req, int encrypt,  	unsigned int cryptlen;  	struct buffer_desc *buf, src_hook;  	struct aead_ctx *req_ctx = aead_request_ctx(req); +	struct device *dev = &pdev->dev;  	gfp_t flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?  				GFP_KERNEL : GFP_ATOMIC; @@ -1159,32 +1149,24 @@ static int aead_setkey(struct crypto_aead *tfm, const u8 *key,  			unsigned int keylen)  {  	struct ixp_ctx *ctx = crypto_aead_ctx(tfm); -	struct rtattr *rta = (struct rtattr *)key; -	struct crypto_authenc_key_param *param; +	struct crypto_authenc_keys keys; -	if (!RTA_OK(rta, keylen)) -		goto badkey; -	if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM) +	if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)  		goto badkey; -	if (RTA_PAYLOAD(rta) < sizeof(*param)) -		goto badkey; - -	param = RTA_DATA(rta); -	ctx->enckey_len = be32_to_cpu(param->enckeylen); -	key += RTA_ALIGN(rta->rta_len); -	keylen -= RTA_ALIGN(rta->rta_len); +	if (keys.authkeylen > sizeof(ctx->authkey)) +		goto badkey; -	if (keylen < ctx->enckey_len) +	if (keys.enckeylen > sizeof(ctx->enckey))  		goto badkey; -	ctx->authkey_len = keylen - ctx->enckey_len; -	memcpy(ctx->enckey, key + ctx->authkey_len, ctx->enckey_len); -	memcpy(ctx->authkey, key, ctx->authkey_len); +	memcpy(ctx->authkey, keys.authkey, keys.authkeylen); +	memcpy(ctx->enckey, keys.enckey, keys.enckeylen); +	ctx->authkey_len = keys.authkeylen; +	ctx->enckey_len = keys.enckeylen;  	return aead_setup(tfm, crypto_aead_authsize(tfm));  badkey: -	ctx->enckey_len = 0;  	crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);  	return -EINVAL;  } @@ -1418,20 +1400,28 @@ static struct ixp_alg ixp4xx_algos[] = {  } };  #define IXP_POSTFIX "-ixp4xx" + +static const struct platform_device_info ixp_dev_info __initdata = { +	.name		= DRIVER_NAME, +	.id		= 0, +	.dma_mask	= DMA_BIT_MASK(32), +}; +  static int __init ixp_module_init(void)  {  	int num = ARRAY_SIZE(ixp4xx_algos); -	int i,err ; +	int i, err; -	if (platform_device_register(&pseudo_dev)) -		return -ENODEV; +	pdev = platform_device_register_full(&ixp_dev_info); +	if (IS_ERR(pdev)) +		return PTR_ERR(pdev);  	spin_lock_init(&desc_lock);  	spin_lock_init(&emerg_lock); -	err = init_ixp_crypto(); +	err = init_ixp_crypto(&pdev->dev);  	if (err) { -		platform_device_unregister(&pseudo_dev); +		platform_device_unregister(pdev);  		return err;  	}  	for (i=0; i< num; i++) { @@ -1495,8 +1485,8 @@ static void __exit ixp_module_exit(void)  		if (ixp4xx_algos[i].registered)  			crypto_unregister_alg(&ixp4xx_algos[i].crypto);  	} -	release_ixp_crypto(); -	platform_device_unregister(&pseudo_dev); +	release_ixp_crypto(&pdev->dev); +	platform_device_unregister(pdev);  }  module_init(ixp_module_init);  | 
