[PATCH 2/2] crypto: talitos: Delete an error message for a failed memory allocation in talitos_edesc_alloc()

2018-03-12 Thread SF Markus Elfring
From: Markus Elfring 
Date: Mon, 12 Mar 2018 14:18:23 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/talitos.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index a2271322db34..4c7318981d28 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1399,7 +1399,6 @@ static struct talitos_edesc *talitos_edesc_alloc(struct 
device *dev,
 
edesc = kmalloc(alloc_len, GFP_DMA | flags);
if (!edesc) {
-   dev_err(dev, "could not allocate edescriptor\n");
err = ERR_PTR(-ENOMEM);
goto error_sg;
}
-- 
2.16.2



[PATCH 1/2] crypto: talitos: Use common error handling code in talitos_edesc_alloc()

2018-03-12 Thread SF Markus Elfring
From: Markus Elfring 
Date: Mon, 12 Mar 2018 14:08:55 +0100

Add jump targets so that an error message and the setting of a specific
error code is stored only once at the end of this function.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/talitos.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 6882fa2f8bad..a2271322db34 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1352,29 +1352,24 @@ static struct talitos_edesc *talitos_edesc_alloc(struct 
device *dev,
if (!dst || dst == src) {
src_len = assoclen + cryptlen + authsize;
src_nents = sg_nents_for_len(src, src_len);
-   if (src_nents < 0) {
-   dev_err(dev, "Invalid number of src SG.\n");
-   err = ERR_PTR(-EINVAL);
-   goto error_sg;
-   }
+   if (src_nents < 0)
+   goto report_failure;
+
src_nents = (src_nents == 1) ? 0 : src_nents;
dst_nents = dst ? src_nents : 0;
dst_len = 0;
} else { /* dst && dst != src*/
src_len = assoclen + cryptlen + (encrypt ? 0 : authsize);
src_nents = sg_nents_for_len(src, src_len);
-   if (src_nents < 0) {
-   dev_err(dev, "Invalid number of src SG.\n");
-   err = ERR_PTR(-EINVAL);
-   goto error_sg;
-   }
+   if (src_nents < 0)
+   goto report_failure;
+
src_nents = (src_nents == 1) ? 0 : src_nents;
dst_len = assoclen + cryptlen + (encrypt ? authsize : 0);
dst_nents = sg_nents_for_len(dst, dst_len);
if (dst_nents < 0) {
dev_err(dev, "Invalid number of dst SG.\n");
-   err = ERR_PTR(-EINVAL);
-   goto error_sg;
+   goto set_error_code;
}
dst_nents = (dst_nents == 1) ? 0 : dst_nents;
}
@@ -1424,6 +1419,11 @@ static struct talitos_edesc *talitos_edesc_alloc(struct 
device *dev,
 DMA_BIDIRECTIONAL);
}
return edesc;
+
+report_failure:
+   dev_err(dev, "Invalid number of src SG.\n");
+set_error_code:
+   err = ERR_PTR(-EINVAL);
 error_sg:
if (iv_dma)
dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
-- 
2.16.2



[PATCH] crypto: ccp: Use memdup_user() rather than duplicating its implementation

2018-03-05 Thread SF Markus Elfring
From: Markus Elfring 
Date: Mon, 5 Mar 2018 13:50:13 +0100

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ccp/psp-dev.c | 15 +--
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index fcfa5b1eae61..8255258cd040 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -367,8 +367,6 @@ static int sev_ioctl_do_pek_csr(struct sev_issue_cmd *argp)
 
 void *psp_copy_user_blob(u64 __user uaddr, u32 len)
 {
-   void *data;
-
if (!uaddr || !len)
return ERR_PTR(-EINVAL);
 
@@ -376,18 +374,7 @@ void *psp_copy_user_blob(u64 __user uaddr, u32 len)
if (len > SEV_FW_BLOB_MAX_SIZE)
return ERR_PTR(-EINVAL);
 
-   data = kmalloc(len, GFP_KERNEL);
-   if (!data)
-   return ERR_PTR(-ENOMEM);
-
-   if (copy_from_user(data, (void __user *)(uintptr_t)uaddr, len))
-   goto e_free;
-
-   return data;
-
-e_free:
-   kfree(data);
-   return ERR_PTR(-EFAULT);
+   return memdup_user((void __user *)(uintptr_t)uaddr, len);
 }
 EXPORT_SYMBOL_GPL(psp_copy_user_blob);
 
-- 
2.16.2



Re: [2/2] crypto: bcm: One function call less in do_shash() after error detection

2018-02-23 Thread SF Markus Elfring
> This patch is pointless as kfree on NULL is a no-op.

I prefer to avoid unnecessary function calls generally.

Regards,
Markus


Re: [PATCH 2/2] crypto: omap: Improve a size determination in three functions

2018-02-22 Thread SF Markus Elfring
>> @@ -1032,14 +1032,13 @@ static int omap_aes_get_res_pdev(struct omap_aes_dev 
>> *dd,
>>  static int omap_aes_probe(struct platform_device *pdev)
>>  {
>>  struct device *dev = >dev;
>> -struct omap_aes_dev *dd;
>>  struct crypto_alg *algp;
>>  struct aead_alg *aalg;
>>  struct resource res;
>>  int err = -ENOMEM, i, j, irq = -1;
>>  u32 reg;
>> +struct omap_aes_dev *dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL);
>>  
>> -dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL);
> 
> I'm fine with sizeof(*dd)

Thanks for your feedback.


> but please don't combine the allocation with the declaration.

Why do you not like such an implementation detail?

Regards,
Markus


[PATCH] crypto: atmel: Delete error messages for a failed memory allocation in six functions

2018-02-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 15 Feb 2018 11:38:30 +0100

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/atmel-aes.c  | 6 +-
 drivers/crypto/atmel-sha.c  | 9 ++---
 drivers/crypto/atmel-tdes.c | 9 ++---
 3 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 691c6465b71e..6fb24fc94b1f 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -2602,16 +2602,13 @@ static struct crypto_platform_data 
*atmel_aes_of_init(struct platform_device *pd
}
 
pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
-   if (!pdata) {
-   dev_err(>dev, "could not allocate memory for pdata\n");
+   if (!pdata)
return ERR_PTR(-ENOMEM);
-   }
 
pdata->dma_slave = devm_kzalloc(>dev,
sizeof(*(pdata->dma_slave)),
GFP_KERNEL);
if (!pdata->dma_slave) {
-   dev_err(>dev, "could not allocate memory for 
dma_slave\n");
devm_kfree(>dev, pdata);
return ERR_PTR(-ENOMEM);
}
@@ -2649,7 +2646,6 @@ static int atmel_aes_probe(struct platform_device *pdev)
 
aes_dd = devm_kzalloc(>dev, sizeof(*aes_dd), GFP_KERNEL);
if (aes_dd == NULL) {
-   dev_err(dev, "unable to alloc data struct.\n");
err = -ENOMEM;
goto aes_dd_err;
}
diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 8874aa5ca0f7..4d43081120db 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -2726,18 +2726,14 @@ static struct crypto_platform_data 
*atmel_sha_of_init(struct platform_device *pd
}
 
pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
-   if (!pdata) {
-   dev_err(>dev, "could not allocate memory for pdata\n");
+   if (!pdata)
return ERR_PTR(-ENOMEM);
-   }
 
pdata->dma_slave = devm_kzalloc(>dev,
sizeof(*(pdata->dma_slave)),
GFP_KERNEL);
-   if (!pdata->dma_slave) {
-   dev_err(>dev, "could not allocate memory for 
dma_slave\n");
+   if (!pdata->dma_slave)
return ERR_PTR(-ENOMEM);
-   }
 
return pdata;
 }
@@ -2758,7 +2754,6 @@ static int atmel_sha_probe(struct platform_device *pdev)
 
sha_dd = devm_kzalloc(>dev, sizeof(*sha_dd), GFP_KERNEL);
if (sha_dd == NULL) {
-   dev_err(dev, "unable to alloc data struct.\n");
err = -ENOMEM;
goto sha_dd_err;
}
diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index 592124f8382b..97b0423efa7f 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -1312,18 +1312,14 @@ static struct crypto_platform_data 
*atmel_tdes_of_init(struct platform_device *p
}
 
pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
-   if (!pdata) {
-   dev_err(>dev, "could not allocate memory for pdata\n");
+   if (!pdata)
return ERR_PTR(-ENOMEM);
-   }
 
pdata->dma_slave = devm_kzalloc(>dev,
sizeof(*(pdata->dma_slave)),
GFP_KERNEL);
-   if (!pdata->dma_slave) {
-   dev_err(>dev, "could not allocate memory for 
dma_slave\n");
+   if (!pdata->dma_slave)
return ERR_PTR(-ENOMEM);
-   }
 
return pdata;
 }
@@ -1344,7 +1340,6 @@ static int atmel_tdes_probe(struct platform_device *pdev)
 
tdes_dd = devm_kmalloc(>dev, sizeof(*tdes_dd), GFP_KERNEL);
if (tdes_dd == NULL) {
-   dev_err(dev, "unable to alloc data struct.\n");
err = -ENOMEM;
goto tdes_dd_err;
}
-- 
2.16.1



[PATCH 2/2] crypto: bcm: One function call less in do_shash() after error detection

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 22:22:20 +0100

The kfree() function was called in one case by the do_shash() function
during error handling even if the passed variable contained a null pointer.

* Reorder two function calls at the end.

* Add a jump target.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/bcm/util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/bcm/util.c b/drivers/crypto/bcm/util.c
index a912c6ad3e85..c141a0242223 100644
--- a/drivers/crypto/bcm/util.c
+++ b/drivers/crypto/bcm/util.c
@@ -279,7 +279,7 @@ int do_shash(unsigned char *name, unsigned char *result,
sdesc = kmalloc(size, GFP_KERNEL);
if (!sdesc) {
rc = -ENOMEM;
-   goto do_shash_err;
+   goto free_shash;
}
sdesc->shash.tfm = hash;
sdesc->shash.flags = 0x0;
@@ -314,9 +314,9 @@ int do_shash(unsigned char *name, unsigned char *result,
pr_err("%s: Could not generate %s hash\n", __func__, name);
 
 do_shash_err:
-   crypto_free_shash(hash);
kfree(sdesc);
-
+free_shash:
+   crypto_free_shash(hash);
return rc;
 }
 
-- 
2.16.1



[PATCH 1/2] crypto: bcm: Delete an error message for a failed memory allocation in do_shash()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 22:05:11 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/bcm/util.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/bcm/util.c b/drivers/crypto/bcm/util.c
index d543c010ccd9..a912c6ad3e85 100644
--- a/drivers/crypto/bcm/util.c
+++ b/drivers/crypto/bcm/util.c
@@ -279,7 +279,6 @@ int do_shash(unsigned char *name, unsigned char *result,
sdesc = kmalloc(size, GFP_KERNEL);
if (!sdesc) {
rc = -ENOMEM;
-   pr_err("%s: Memory allocation failure\n", __func__);
goto do_shash_err;
}
sdesc->shash.tfm = hash;
-- 
2.16.1



[PATCH 0/2] crypto/bcm: Adjustments for do_shash()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 22:30:07 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation
  One function call less after error detection

 drivers/crypto/bcm/util.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

-- 
2.16.1



[PATCH] crypto: bfin_crc: Delete an error message for a failed memory allocation in bfin_crypto_crc_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 21:34:54 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/bfin_crc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/crypto/bfin_crc.c b/drivers/crypto/bfin_crc.c
index a118b9bed669..7a1d6ed6d0b7 100644
--- a/drivers/crypto/bfin_crc.c
+++ b/drivers/crypto/bfin_crc.c
@@ -575,10 +575,8 @@ static int bfin_crypto_crc_probe(struct platform_device 
*pdev)
int ret;
 
crc = devm_kzalloc(dev, sizeof(*crc), GFP_KERNEL);
-   if (!crc) {
-   dev_err(>dev, "fail to malloc bfin_crypto_crc\n");
+   if (!crc)
return -ENOMEM;
-   }
 
crc->dev = dev;
 
-- 
2.16.1



[PATCH 2/2] crypto: caam: Use common error handling code in four functions

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 19:14:49 +0100

Add jump targets so that a bit of exception handling can be better reused
at the end of these functions.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamalg.c  | 32 
 drivers/crypto/caam/caamhash.c | 23 ++-
 2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index d1f25a90552a..3d26c44040c7 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1560,11 +1560,8 @@ static struct ablkcipher_edesc 
*ablkcipher_edesc_alloc(struct ablkcipher_request
/* allocate space for base edesc and hw desc commands, link tables */
edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
GFP_DMA | flags);
-   if (!edesc) {
-   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
-  iv_dma, ivsize, 0, 0);
-   return ERR_PTR(-ENOMEM);
-   }
+   if (!edesc)
+   goto unmap_caam;
 
edesc->src_nents = src_nents;
edesc->dst_nents = dst_nents;
@@ -1587,10 +1584,8 @@ static struct ablkcipher_edesc 
*ablkcipher_edesc_alloc(struct ablkcipher_request
sec4_sg_bytes, DMA_TO_DEVICE);
if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
dev_err(jrdev, "unable to map S/G table\n");
-   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
-  iv_dma, ivsize, 0, 0);
kfree(edesc);
-   return ERR_PTR(-ENOMEM);
+   goto unmap_caam;
}
 
edesc->iv_dma = iv_dma;
@@ -1603,6 +1598,11 @@ static struct ablkcipher_edesc 
*ablkcipher_edesc_alloc(struct ablkcipher_request
 
*iv_contig_out = in_contig;
return edesc;
+
+unmap_caam:
+   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
+  iv_dma, ivsize, 0, 0);
+   return ERR_PTR(-ENOMEM);
 }
 
 static int ablkcipher_encrypt(struct ablkcipher_request *req)
@@ -1768,11 +1768,8 @@ static struct ablkcipher_edesc 
*ablkcipher_giv_edesc_alloc(
sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
GFP_DMA | flags);
-   if (!edesc) {
-   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
-  iv_dma, ivsize, 0, 0);
-   return ERR_PTR(-ENOMEM);
-   }
+   if (!edesc)
+   goto unmap_caam;
 
edesc->src_nents = src_nents;
edesc->dst_nents = dst_nents;
@@ -1795,10 +1792,8 @@ static struct ablkcipher_edesc 
*ablkcipher_giv_edesc_alloc(
sec4_sg_bytes, DMA_TO_DEVICE);
if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
dev_err(jrdev, "unable to map S/G table\n");
-   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
-  iv_dma, ivsize, 0, 0);
kfree(edesc);
-   return ERR_PTR(-ENOMEM);
+   goto unmap_caam;
}
edesc->iv_dma = iv_dma;
 
@@ -1811,6 +1806,11 @@ static struct ablkcipher_edesc 
*ablkcipher_giv_edesc_alloc(
 
*iv_contig_out = out_contig;
return edesc;
+
+unmap_caam:
+   caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
+  iv_dma, ivsize, 0, 0);
+   return ERR_PTR(-ENOMEM);
 }
 
 static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index dc269eba08ad..b5e43a1f38f0 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -371,16 +371,16 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, 
const u8 *key_in,
 DMA_TO_DEVICE);
if (dma_mapping_error(jrdev, src_dma)) {
dev_err(jrdev, "unable to map key input memory\n");
-   kfree(desc);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto free_desc;
}
dst_dma = dma_map_single(jrdev, (void *)key_out, digestsize,
 DMA_FROM_DEVICE);
if (dma_mapping_error(jrdev, dst_dma)) {
dev_err(jrdev, "unable to map key output memory\n");
dma_unmap_single(jrdev, src_dma, *keylen, DMA_TO_DEVICE);
-   kfree(desc);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto free_desc;
}
 
/* Job descriptor to perform unkeyed hash on key_in */
@@ -419,7 +419,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const 
u8 *key_in,
dma_unmap_single(jrdev, dst_dma, digestsize, 

[PATCH 1/2] crypto: caam: Delete an error message for a failed memory allocation in seven functions

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 18:22:38 +0100

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamalg.c  |  6 +-
 drivers/crypto/caam/caamhash.c | 12 +++-
 drivers/crypto/caam/key_gen.c  |  4 +---
 3 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 2188235be02d..d1f25a90552a 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1561,7 +1561,6 @@ static struct ablkcipher_edesc 
*ablkcipher_edesc_alloc(struct ablkcipher_request
edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
GFP_DMA | flags);
if (!edesc) {
-   dev_err(jrdev, "could not allocate extended descriptor\n");
caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
   iv_dma, ivsize, 0, 0);
return ERR_PTR(-ENOMEM);
@@ -1770,7 +1769,6 @@ static struct ablkcipher_edesc 
*ablkcipher_giv_edesc_alloc(
edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
GFP_DMA | flags);
if (!edesc) {
-   dev_err(jrdev, "could not allocate extended descriptor\n");
caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents,
   iv_dma, ivsize, 0, 0);
return ERR_PTR(-ENOMEM);
@@ -3372,10 +3370,8 @@ static struct caam_crypto_alg *caam_alg_alloc(struct 
caam_alg_template
struct crypto_alg *alg;
 
t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
-   if (!t_alg) {
-   pr_err("failed to allocate t_alg\n");
+   if (!t_alg)
return ERR_PTR(-ENOMEM);
-   }
 
alg = _alg->crypto_alg;
 
diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 0beb28196e20..dc269eba08ad 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -362,10 +362,8 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, 
const u8 *key_in,
int ret;
 
desc = kmalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA);
-   if (!desc) {
-   dev_err(jrdev, "unable to allocate key input memory\n");
+   if (!desc)
return -ENOMEM;
-   }
 
init_job_desc(desc, 0);
 
@@ -689,10 +687,8 @@ static struct ahash_edesc *ahash_edesc_alloc(struct 
caam_hash_ctx *ctx,
unsigned int sg_size = sg_num * sizeof(struct sec4_sg_entry);
 
edesc = kzalloc(sizeof(*edesc) + sg_size, GFP_DMA | flags);
-   if (!edesc) {
-   dev_err(ctx->jrdev, "could not allocate extended descriptor\n");
+   if (!edesc)
return NULL;
-   }
 
init_job_desc_shared(edesc->hw_desc, sh_desc_dma, desc_len(sh_desc),
 HDR_SHARE_DEFER | HDR_REVERSE);
@@ -1818,10 +1814,8 @@ caam_hash_alloc(struct caam_hash_template *template,
struct crypto_alg *alg;
 
t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
-   if (!t_alg) {
-   pr_err("failed to allocate t_alg\n");
+   if (!t_alg)
return ERR_PTR(-ENOMEM);
-   }
 
t_alg->ahash_alg = template->template_ahash;
halg = _alg->ahash_alg;
diff --git a/drivers/crypto/caam/key_gen.c b/drivers/crypto/caam/key_gen.c
index 312b5f042f31..dd077ac8c41e 100644
--- a/drivers/crypto/caam/key_gen.c
+++ b/drivers/crypto/caam/key_gen.c
@@ -66,10 +66,8 @@ int gen_split_key(struct device *jrdev, u8 *key_out,
return -EINVAL;
 
desc = kmalloc(CAAM_CMD_SZ * 6 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA);
-   if (!desc) {
-   dev_err(jrdev, "unable to allocate key input memory\n");
+   if (!desc)
return ret;
-   }
 
dma_addr_in = dma_map_single(jrdev, (void *)key_in, keylen,
 DMA_TO_DEVICE);
-- 
2.16.1



[PATCH 0/2] crypto/caam: Adjustments for eight function implementations

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 19:23:45 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation in seven functions
  Use common error handling code in four functions

 drivers/crypto/caam/caamalg.c  | 38 +-
 drivers/crypto/caam/caamhash.c | 35 +--
 drivers/crypto/caam/key_gen.c  |  4 +---
 3 files changed, 31 insertions(+), 46 deletions(-)

-- 
2.16.1



[PATCH] crypto: nx-842: Delete an error message for a failed memory allocation in nx842_pseries_init()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 17:05:13 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/nx/nx-842-pseries.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/nx/nx-842-pseries.c 
b/drivers/crypto/nx/nx-842-pseries.c
index bf52cd1d7fca..66869976cfa2 100644
--- a/drivers/crypto/nx/nx-842-pseries.c
+++ b/drivers/crypto/nx/nx-842-pseries.c
@@ -1105,10 +1105,9 @@ static int __init nx842_pseries_init(void)
 
RCU_INIT_POINTER(devdata, NULL);
new_devdata = kzalloc(sizeof(*new_devdata), GFP_KERNEL);
-   if (!new_devdata) {
-   pr_err("Could not allocate memory for device data\n");
+   if (!new_devdata)
return -ENOMEM;
-   }
+
RCU_INIT_POINTER(devdata, new_devdata);
 
ret = vio_register_driver(_vio_driver);
-- 
2.16.1



[PATCH 2/2] crypto: omap: Improve a size determination in three functions

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 16:12:05 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/omap-aes.c  | 3 +--
 drivers/crypto/omap-des.c  | 3 +--
 drivers/crypto/omap-sham.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index a2bac3b869b6..82282a5e9b3f 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -1032,14 +1032,13 @@ static int omap_aes_get_res_pdev(struct omap_aes_dev 
*dd,
 static int omap_aes_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
-   struct omap_aes_dev *dd;
struct crypto_alg *algp;
struct aead_alg *aalg;
struct resource res;
int err = -ENOMEM, i, j, irq = -1;
u32 reg;
+   struct omap_aes_dev *dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL);
 
-   dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL);
if (!dd)
goto err_data;
 
diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
index f4199be783a9..09833709fbed 100644
--- a/drivers/crypto/omap-des.c
+++ b/drivers/crypto/omap-des.c
@@ -957,13 +957,12 @@ static int omap_des_get_pdev(struct omap_des_dev *dd,
 static int omap_des_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
-   struct omap_des_dev *dd;
struct crypto_alg *algp;
struct resource *res;
int err = -ENOMEM, i, j, irq = -1;
u32 reg;
+   struct omap_des_dev *dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL);
 
-   dd = devm_kzalloc(dev, sizeof(struct omap_des_dev), GFP_KERNEL);
if (!dd)
goto err_data;
 
diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 7aa4eb50ebc9..ffa3ac3bde55 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -2015,14 +2015,13 @@ static int omap_sham_get_res_pdev(struct omap_sham_dev 
*dd,
 
 static int omap_sham_probe(struct platform_device *pdev)
 {
-   struct omap_sham_dev *dd;
struct device *dev = >dev;
struct resource res;
dma_cap_mask_t mask;
int err, i, j;
u32 rev;
+   struct omap_sham_dev *dd = devm_kzalloc(dev, sizeof(*dd), GFP_KERNEL);
 
-   dd = devm_kzalloc(dev, sizeof(struct omap_sham_dev), GFP_KERNEL);
if (dd == NULL) {
err = -ENOMEM;
goto data_err;
-- 
2.16.1



[PATCH 0/2] crypto/omap: Adjustments for three function implementations

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 16:18:19 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete error messages for a failed memory allocation
  Improve size determinations

 drivers/crypto/omap-aes.c  | 8 +++-
 drivers/crypto/omap-des.c  | 8 +++-
 drivers/crypto/omap-sham.c | 4 +---
 3 files changed, 7 insertions(+), 13 deletions(-)

-- 
2.16.1



[PATCH 2/2] crypto: sahara: Improve a size determination in sahara_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 14:14:05 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/sahara.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c
index 9f3cdda59139..0f2245e1af2b 100644
--- a/drivers/crypto/sahara.c
+++ b/drivers/crypto/sahara.c
@@ -1397,7 +1397,7 @@ static int sahara_probe(struct platform_device *pdev)
int err;
int i;
 
-   dev = devm_kzalloc(>dev, sizeof(struct sahara_dev), GFP_KERNEL);
+   dev = devm_kzalloc(>dev, sizeof(*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
 
-- 
2.16.1



[PATCH 0/2] crypto/sahara: Adjustments for sahara_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 14:30:28 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Delete an error message for a failed memory allocation
  Improve a size determination

 drivers/crypto/sahara.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

-- 
2.16.1



[PATCH 4/4] crypto: ux500: Delete two unnecessary variable initialisations in ux500_cryp_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 10:56:38 +0100

Two local variables will eventually be set to appropriate pointers
a bit later. Thus omit their explicit initialisation at the beginning.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ux500/cryp/cryp_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ux500/cryp/cryp_core.c 
b/drivers/crypto/ux500/cryp/cryp_core.c
index 7c811d7eb274..cb31b59c9d53 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -1404,8 +1404,8 @@ static void cryp_algs_unregister_all(void)
 static int ux500_cryp_probe(struct platform_device *pdev)
 {
int ret;
-   struct resource *res = NULL;
-   struct resource *res_irq = NULL;
+   struct resource *res;
+   struct resource *res_irq;
struct cryp_device_data *device_data;
struct cryp_protection_config prot = {
.privilege_access = CRYP_STATE_ENABLE
-- 
2.16.1



[PATCH 3/4] crypto: ux500: Adjust an error message in ux500_cryp_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 10:47:31 +0100

Replace the function name in this error message so that the same name
is mentioned according to what was called before.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ux500/cryp/cryp_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/ux500/cryp/cryp_core.c 
b/drivers/crypto/ux500/cryp/cryp_core.c
index 07cc92f88933..7c811d7eb274 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -1478,7 +1478,7 @@ static int ux500_cryp_probe(struct platform_device *pdev)
}
 
if (cryp_check(device_data)) {
-   dev_err(dev, "[%s]: cryp_init() failed!", __func__);
+   dev_err(dev, "[%s]: cryp_check() failed!", __func__);
ret = -EINVAL;
goto out_power;
}
-- 
2.16.1



[PATCH 2/4] crypto: ux500: Adjust two condition checks in ux500_cryp_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 10:38:44 +0100

The local variable "cryp_error" was used only for two condition checks.

* Check the return values from these function calls directly instead.

* Delete this variable which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ux500/cryp/cryp_core.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/ux500/cryp/cryp_core.c 
b/drivers/crypto/ux500/cryp/cryp_core.c
index 50bfc7b4c641..07cc92f88933 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -1404,7 +1404,6 @@ static void cryp_algs_unregister_all(void)
 static int ux500_cryp_probe(struct platform_device *pdev)
 {
int ret;
-   int cryp_error = 0;
struct resource *res = NULL;
struct resource *res_irq = NULL;
struct cryp_device_data *device_data;
@@ -1478,15 +1477,13 @@ static int ux500_cryp_probe(struct platform_device 
*pdev)
goto out_clk_unprepare;
}
 
-   cryp_error = cryp_check(device_data);
-   if (cryp_error != 0) {
+   if (cryp_check(device_data)) {
dev_err(dev, "[%s]: cryp_init() failed!", __func__);
ret = -EINVAL;
goto out_power;
}
 
-   cryp_error = cryp_configure_protection(device_data, );
-   if (cryp_error != 0) {
+   if (cryp_configure_protection(device_data, )) {
dev_err(dev, "[%s]: cryp_configure_protection() failed!",
__func__);
ret = -EINVAL;
-- 
2.16.1



[PATCH 1/4] crypto: ux500: Delete an error message for a failed memory allocation in ux500_cryp_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 10:12:38 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ux500/cryp/cryp_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/crypto/ux500/cryp/cryp_core.c 
b/drivers/crypto/ux500/cryp/cryp_core.c
index 765f53e548ab..50bfc7b4c641 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -1416,7 +1416,6 @@ static int ux500_cryp_probe(struct platform_device *pdev)
dev_dbg(dev, "[%s]", __func__);
device_data = devm_kzalloc(dev, sizeof(*device_data), GFP_ATOMIC);
if (!device_data) {
-   dev_err(dev, "[%s]: kzalloc() failed!", __func__);
ret = -ENOMEM;
goto out;
}
-- 
2.16.1



[PATCH 0/4] Ux500 crypto: Adjustments for ux500_cryp_probe()

2018-02-14 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 14 Feb 2018 11:12:34 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  Delete an error message for a failed memory allocation
  Adjust two condition checks
  Adjust an error message
  Delete two unnecessary variable initialisations

 drivers/crypto/ux500/cryp/cryp_core.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

-- 
2.16.1



Re: [PATCH] crypto/s5p-sss: Use common error handling code in s5p_aes_probe()

2017-10-22 Thread SF Markus Elfring
>> From: Markus Elfring 
>> Date: Sun, 22 Oct 2017 15:00:27 +0200
>>
>> Add a jump target so that a bit of exception handling can be better reused
>> at the end of this function.
>>
>> This issue was detected by using the Coccinelle software.
>>
>> Signed-off-by: Markus Elfring 
>> ---
>>  drivers/crypto/s5p-sss.c | 13 +++--
>>  1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
>> index 7ac657f46d15..ea59e184c199 100644
>> --- a/drivers/crypto/s5p-sss.c
>> +++ b/drivers/crypto/s5p-sss.c
>> @@ -863,16 +863,13 @@ static int s5p_aes_probe(struct platform_device *pdev)
>>  pdata->irq_fc = platform_get_irq(pdev, 0);
>>  if (pdata->irq_fc < 0) {
>>  err = pdata->irq_fc;
>> -dev_warn(dev, "feed control interrupt is not available.\n");
>> -goto err_irq;
>> +goto report_failure;
>>  }
>>  err = devm_request_threaded_irq(dev, pdata->irq_fc, NULL,
>>  s5p_aes_interrupt, IRQF_ONESHOT,
>>  pdev->name, pdev);
>> -if (err < 0) {
>> -dev_warn(dev, "feed control interrupt is not available.\n");
>> -goto err_irq;
>> -}
>> +if (err < 0)
>> +goto report_failure;
> 
> No, one exit path just to report error does not seem to be more readable.

I got an other development opinion on such an aspect.


> Instead, printing error after the code causing it looks to me
> as common pattern, easy to maintain.

Do you care for variations in corresponding messages?


> This patch does not bring improvement, in my opinion.

How do you generally think about the possibility for a bit of code reduction?


>>  
>>  pdata->busy = false;
>>  pdata->dev = dev;
>> @@ -906,6 +903,10 @@ static int s5p_aes_probe(struct platform_device *pdev)
>>  s5p_dev = NULL;
>>  
>>  return err;
>> +
>> +report_failure:
>> +dev_warn(dev, "feed control interrupt is not available.\n");
>> +goto err_irq;
>>  }
>>  
>>  static int s5p_aes_remove(struct platform_device *pdev)
>> -- 
>> 2.14.2
>>


Would you like to take another look at other adjustments in source files
which are affected by the shown change pattern?

Regards,
Markus


[PATCH] crypto/s5p-sss: Use common error handling code in s5p_aes_probe()

2017-10-22 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 22 Oct 2017 15:00:27 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/s5p-sss.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
index 7ac657f46d15..ea59e184c199 100644
--- a/drivers/crypto/s5p-sss.c
+++ b/drivers/crypto/s5p-sss.c
@@ -863,16 +863,13 @@ static int s5p_aes_probe(struct platform_device *pdev)
pdata->irq_fc = platform_get_irq(pdev, 0);
if (pdata->irq_fc < 0) {
err = pdata->irq_fc;
-   dev_warn(dev, "feed control interrupt is not available.\n");
-   goto err_irq;
+   goto report_failure;
}
err = devm_request_threaded_irq(dev, pdata->irq_fc, NULL,
s5p_aes_interrupt, IRQF_ONESHOT,
pdev->name, pdev);
-   if (err < 0) {
-   dev_warn(dev, "feed control interrupt is not available.\n");
-   goto err_irq;
-   }
+   if (err < 0)
+   goto report_failure;
 
pdata->busy = false;
pdata->dev = dev;
@@ -906,6 +903,10 @@ static int s5p_aes_probe(struct platform_device *pdev)
s5p_dev = NULL;
 
return err;
+
+report_failure:
+   dev_warn(dev, "feed control interrupt is not available.\n");
+   goto err_irq;
 }
 
 static int s5p_aes_remove(struct platform_device *pdev)
-- 
2.14.2



[PATCH] crypto-ccp: Use common error handling code in sp_get_irqs()

2017-10-22 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 22 Oct 2017 14:10:33 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ccp/sp-platform.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/ccp/sp-platform.c b/drivers/crypto/ccp/sp-platform.c
index 71734f254fd1..7d7670c7484a 100644
--- a/drivers/crypto/ccp/sp-platform.c
+++ b/drivers/crypto/ccp/sp-platform.c
@@ -78,25 +78,25 @@ static int sp_get_irqs(struct sp_device *sp)
sp_platform->irq_count = count;
 
ret = platform_get_irq(pdev, 0);
-   if (ret < 0) {
-   dev_notice(dev, "unable to get IRQ (%d)\n", ret);
-   return ret;
-   }
+   if (ret < 0)
+   goto report_failure;
 
sp->psp_irq = ret;
if (count == 1) {
sp->ccp_irq = ret;
} else {
ret = platform_get_irq(pdev, 1);
-   if (ret < 0) {
-   dev_notice(dev, "unable to get IRQ (%d)\n", ret);
-   return ret;
-   }
+   if (ret < 0)
+   goto report_failure;
 
sp->ccp_irq = ret;
}
 
return 0;
+
+report_failure:
+   dev_notice(dev, "unable to get IRQ (%d)\n", ret);
+   return ret;
 }
 
 static int sp_platform_probe(struct platform_device *pdev)
-- 
2.14.2



Re: crypto-testmgr: Use common error handling code in drbg_cavs_test()

2017-10-21 Thread SF Markus Elfring
> Though, jumping back and forth like this with goto directives is something 
> that looks a bit strange. At least to my taste, may I suggest to have gotos 
> pointing only downwards and not up again? (Note, the same applies to the 
> ansi_cprng patch set).
> 
> What about something like following:
> 
> ...
> memcmp
> goto free_rng;

Do you find an additional jump really acceptable at such a source code place?


> report_failure:
> 
> 
> free_rng:
> 

I am curious on how feedback will evolve also for the other design approach.

Regards,
Markus


[PATCH 2/2] crypto-testmgr: Delete an unnecessary variable initialisation in drbg_cavs_test()

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 19:33:45 +0200

The variable "ret" will eventually be set to an error code a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring 
---
 crypto/testmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 76c5128284f8..e46cf2c92497 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1901,7 +1901,7 @@ static int alg_test_cprng(const struct alg_test_desc 
*desc, const char *driver,
 static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
  const char *driver, u32 type, u32 mask)
 {
-   int ret = -EAGAIN;
+   int ret;
struct crypto_rng *drng;
struct drbg_test_data test_data;
struct drbg_string addtl, pers, testentropy;
-- 
2.14.2



[PATCH 1/2] crypto-testmgr: Use common error handling code in drbg_cavs_test()

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 19:29:11 +0200

Adjust jump targets so that a bit of exception handling can be better
reused at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 crypto/testmgr.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index dd9c7f1c1c7b..76c5128284f8 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1914,8 +1914,8 @@ static int drbg_cavs_test(const struct drbg_testvec 
*test, int pr,
if (IS_ERR(drng)) {
printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
   "%s\n", driver);
-   kzfree(buf);
-   return -ENOMEM;
+   ret = -ENOMEM;
+   goto free_buffer;
}
 
test_data.testentropy = 
@@ -1924,7 +1924,7 @@ static int drbg_cavs_test(const struct drbg_testvec 
*test, int pr,
ret = crypto_drbg_reset_test(drng, , _data);
if (ret) {
printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
-   goto outbuf;
+   goto free_rng;
}
 
drbg_string_fill(, test->addtla, test->addtllen);
@@ -1936,11 +1936,9 @@ static int drbg_cavs_test(const struct drbg_testvec 
*test, int pr,
ret = crypto_drbg_get_bytes_addtl(drng,
buf, test->expectedlen, );
}
-   if (ret < 0) {
-   printk(KERN_ERR "alg: drbg: could not obtain random data for "
-  "driver %s\n", driver);
-   goto outbuf;
-   }
+
+   if (ret < 0)
+   goto report_failure;
 
drbg_string_fill(, test->addtlb, test->addtllen);
if (pr) {
@@ -1951,18 +1949,21 @@ static int drbg_cavs_test(const struct drbg_testvec 
*test, int pr,
ret = crypto_drbg_get_bytes_addtl(drng,
buf, test->expectedlen, );
}
-   if (ret < 0) {
-   printk(KERN_ERR "alg: drbg: could not obtain random data for "
-  "driver %s\n", driver);
-   goto outbuf;
-   }
 
-   ret = memcmp(test->expected, buf, test->expectedlen);
+   if (ret < 0)
+   goto report_failure;
 
-outbuf:
+   ret = memcmp(test->expected, buf, test->expectedlen);
+free_rng:
crypto_free_rng(drng);
+free_buffer:
kzfree(buf);
return ret;
+
+report_failure:
+   pr_err("alg: drbg: could not obtain random data for driver %s\n",
+  driver);
+   goto free_rng;
 }
 
 
-- 
2.14.2



[PATCH 0/2] crypto-testmgr: Fine-tuning for drbg_cavs_test()

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 19:47:43 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Use common error handling code
  Delete an unnecessary variable initialisation

 crypto/testmgr.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

-- 
2.14.2



[PATCH 3/3] crypto-ansi_cprng: Delete unnecessary blank lines

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 16:27:56 +0200

The script "checkpatch.pl" pointed information out like the following.

CHECK: Please don't use multiple blank lines

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 crypto/ansi_cprng.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 3d805bf6d0c6..b9ec1975dde7 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -40,7 +40,6 @@
  * for implementation details
  */
 
-
 struct prng_context {
spinlock_t prng_lock;
unsigned char rand_data[DEFAULT_BLK_SZ];
@@ -77,8 +76,8 @@ static void xor_vectors(unsigned char *in1, unsigned char 
*in2,
 
for (i = 0; i < size; i++)
out[i] = in1[i] ^ in2[i];
-
 }
+
 /*
  * Returns DEFAULT_BLK_SZ bytes of random data per call
  * returns 0 if generation succeeded, <0 if something went wrong
@@ -89,7 +88,6 @@ static int _get_more_prng_bytes(struct prng_context *ctx, int 
cont_test)
unsigned char tmp[DEFAULT_BLK_SZ];
unsigned char *output = NULL;
 
-
dbgprint(KERN_CRIT "Calling _get_more_prng_bytes for context %p\n",
ctx);
 
@@ -101,7 +99,6 @@ static int _get_more_prng_bytes(struct prng_context *ctx, 
int cont_test)
 * This algorithm is a 3 stage state machine
 */
for (i = 0; i < 3; i++) {
-
switch (i) {
case 0:
/*
@@ -156,10 +153,8 @@ static int _get_more_prng_bytes(struct prng_context *ctx, 
int cont_test)
break;
}
 
-
/* do the encryption */
crypto_cipher_encrypt_one(ctx->tfm, output, tmp);
-
}
 
/*
@@ -190,7 +185,6 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
unsigned int byte_count = (unsigned int)nbytes;
int err;
 
-
spin_lock_bh(>prng_lock);
if (ctx->flags & PRNG_NEED_RESET)
goto failure_indication;
@@ -214,7 +208,6 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
dbgprint(KERN_CRIT "getting %d random bytes for context %p\n",
byte_count, ctx);
 
-
 remainder:
if (ctx->rand_data_valid == DEFAULT_BLK_SZ &&
_get_more_prng_bytes(ctx, do_cont_test) < 0)
-- 
2.14.2



[PATCH 2/3] crypto-ansi_cprng: Delete two variable assignments in get_prng_bytes()

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 16:10:43 +0200

Adjust a jump target so that two error code assignments which are redundant
before condition checks can be removed because the same value will be set
as an exception handling at the end of this function.

Signed-off-by: Markus Elfring 
---
 crypto/ansi_cprng.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 111c8982a47f..3d805bf6d0c6 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -192,19 +192,16 @@ static int get_prng_bytes(char *buf, size_t nbytes, 
struct prng_context *ctx,
 
 
spin_lock_bh(>prng_lock);
-
-   err = -EINVAL;
if (ctx->flags & PRNG_NEED_RESET)
-   goto unlock;
+   goto failure_indication;
 
/*
 * If the FIXED_SIZE flag is on, only return whole blocks of
 * pseudo random data
 */
-   err = -EINVAL;
if (ctx->flags & PRNG_FIXED_SIZE) {
if (nbytes < DEFAULT_BLK_SZ)
-   goto unlock;
+   goto failure_indication;
byte_count = DEFAULT_BLK_SZ;
}
 
@@ -267,6 +264,7 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
 
 reset_memory:
memset(buf, 0, nbytes);
+failure_indication:
err = -EINVAL;
goto unlock;
 }
-- 
2.14.2



[PATCH 1/3] crypto-ansi_cprng: Use common error handling code in get_prng_bytes()

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 15:17:52 +0200

Adjust jump targets so that a bit of exception handling can be better
reused at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 crypto/ansi_cprng.c | 34 --
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index eff337ce9003..111c8982a47f 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -195,7 +195,7 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
 
err = -EINVAL;
if (ctx->flags & PRNG_NEED_RESET)
-   goto done;
+   goto unlock;
 
/*
 * If the FIXED_SIZE flag is on, only return whole blocks of
@@ -204,7 +204,7 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
err = -EINVAL;
if (ctx->flags & PRNG_FIXED_SIZE) {
if (nbytes < DEFAULT_BLK_SZ)
-   goto done;
+   goto unlock;
byte_count = DEFAULT_BLK_SZ;
}
 
@@ -219,13 +219,9 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
 
 
 remainder:
-   if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
-   if (_get_more_prng_bytes(ctx, do_cont_test) < 0) {
-   memset(buf, 0, nbytes);
-   err = -EINVAL;
-   goto done;
-   }
-   }
+   if (ctx->rand_data_valid == DEFAULT_BLK_SZ &&
+   _get_more_prng_bytes(ctx, do_cont_test) < 0)
+   goto reset_memory;
 
/*
 * Copy any data less than an entire block
@@ -238,7 +234,7 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct 
prng_context *ctx,
byte_count--;
ctx->rand_data_valid++;
if (byte_count == 0)
-   goto done;
+   goto unlock;
}
}
 
@@ -246,13 +242,10 @@ static int get_prng_bytes(char *buf, size_t nbytes, 
struct prng_context *ctx,
 * Now copy whole blocks
 */
for (; byte_count >= DEFAULT_BLK_SZ; byte_count -= DEFAULT_BLK_SZ) {
-   if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
-   if (_get_more_prng_bytes(ctx, do_cont_test) < 0) {
-   memset(buf, 0, nbytes);
-   err = -EINVAL;
-   goto done;
-   }
-   }
+   if (ctx->rand_data_valid == DEFAULT_BLK_SZ &&
+   _get_more_prng_bytes(ctx, do_cont_test) < 0)
+   goto reset_memory;
+
if (ctx->rand_data_valid > 0)
goto empty_rbuf;
memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ);
@@ -266,11 +259,16 @@ static int get_prng_bytes(char *buf, size_t nbytes, 
struct prng_context *ctx,
if (byte_count)
goto remainder;
 
-done:
+unlock:
spin_unlock_bh(>prng_lock);
dbgprint(KERN_CRIT "returning %d from get_prng_bytes in context %p\n",
err, ctx);
return err;
+
+reset_memory:
+   memset(buf, 0, nbytes);
+   err = -EINVAL;
+   goto unlock;
 }
 
 static void free_prng_context(struct prng_context *ctx)
-- 
2.14.2



[PATCH 0/3] crypto-ansi_cprng: Fine-tuning for three function implementations

2017-10-21 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sat, 21 Oct 2017 19:06:54 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
  Use common error handling code in get_prng_bytes()
  Delete two variable assignments in get_prng_bytes()
  Delete unnecessary blank lines

 crypto/ansi_cprng.c | 47 ++-
 1 file changed, 18 insertions(+), 29 deletions(-)

-- 
2.14.2



[PATCH] crypto-testmgr: Delete an error message for a failed memory allocation in two functions

2017-05-11 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 11 May 2017 17:05:17 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Link: 
http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring 
---
 crypto/testmgr.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 6f5f3ed8376c..392bb4f95024 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -217,10 +217,9 @@ static int ahash_partial_update(struct ahash_request 
**preq,
statesize = crypto_ahash_statesize(
crypto_ahash_reqtfm(req));
state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
-   if (!state) {
-   pr_err("alt: hash: Failed to alloc state for %s\n", algo);
+   if (!state)
goto out_nostate;
-   }
+
memcpy(state + statesize, guard, sizeof(guard));
ret = crypto_ahash_export(req, state);
WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
@@ -1632,11 +1631,8 @@ static int test_cprng(struct crypto_rng *tfm,
seedsize = crypto_rng_seedsize(tfm);
 
seed = kmalloc(seedsize, GFP_KERNEL);
-   if (!seed) {
-   printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
-  "for %s\n", algo);
+   if (!seed)
return -ENOMEM;
-   }
 
for (i = 0; i < tcount; i++) {
memset(result, 0, 32);
-- 
2.12.3



[PATCH 2/2] n2rng: Combine substrings for two messages in n2rng_probe()

2017-04-19 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 19 Apr 2017 10:50:04 +0200

The script "checkpatch.pl" pointed information out like the following.

WARNING: quoted string split across lines

Thus fix the affected source code places.

Signed-off-by: Markus Elfring 
---
 drivers/char/hw_random/n2-drv.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 92dd4e925315..f3e67c768101 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -723,16 +723,16 @@ static int n2rng_probe(struct platform_device *op)
if (sun4v_hvapi_register(HV_GRP_RNG,
 np->hvapi_major,
 >hvapi_minor)) {
-   dev_err(>dev, "Cannot register suitable "
-   "HVAPI version.\n");
+   dev_err(>dev,
+   "Cannot register suitable HVAPI version.\n");
goto out;
}
}
 
if (np->flags & N2RNG_FLAG_MULTI) {
if (np->hvapi_major < 2) {
-   dev_err(>dev, "multi-unit-capable RNG requires "
-   "HVAPI major version 2 or later, got %lu\n",
+   dev_err(>dev,
+   "multi-unit-capable RNG requires HVAPI major 
version 2 or later, got %lu\n",
np->hvapi_major);
goto out_hvapi_unregister;
}
-- 
2.12.2



[PATCH 1/2] n2rng: Use devm_kcalloc() in n2rng_probe()

2017-04-19 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 19 Apr 2017 10:30:47 +0200

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "devm_kcalloc".

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/char/hw_random/n2-drv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 31cbdbbaebfc..92dd4e925315 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -748,9 +748,7 @@ static int n2rng_probe(struct platform_device *op)
 
dev_info(>dev, "Registered RNG HVAPI major %lu minor %lu\n",
 np->hvapi_major, np->hvapi_minor);
-
-   np->units = devm_kzalloc(>dev,
-sizeof(struct n2rng_unit) * np->num_units,
+   np->units = devm_kcalloc(>dev, np->num_units, sizeof(*np->units),
 GFP_KERNEL);
err = -ENOMEM;
if (!np->units)
-- 
2.12.2



[PATCH 0/2] n2rng: Fine-tuning for n2rng_probe()

2017-04-19 Thread SF Markus Elfring
From: Markus Elfring 
Date: Wed, 19 Apr 2017 11:00:11 +0200

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
  Use devm_kcalloc()
  Combine substrings for two messages

 drivers/char/hw_random/n2-drv.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

-- 
2.12.2



[PATCH 5/6] crypto-caamhash: Delete an unnecessary initialisation in seven functions

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 15 Sep 2016 15:24:02 +0200

The local variable "ret" will be set to an appropriate value a bit later.
Thus omit the explicit initialisation at the beginning.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamhash.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index b1dbc53..adb8b19 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -440,7 +440,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const 
u8 *key_in,
u32 *desc;
struct split_key_result result;
dma_addr_t src_dma, dst_dma;
-   int ret = 0;
+   int ret;
 
desc = kmalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA);
if (!desc) {
@@ -517,7 +517,7 @@ static int ahash_setkey(struct crypto_ahash *ahash,
struct device *jrdev = ctx->jrdev;
int blocksize = crypto_tfm_alg_blocksize(>base);
int digestsize = crypto_ahash_digestsize(ahash);
-   int ret = 0;
+   int ret;
u8 *hashed_key = NULL;
 
 #ifdef DEBUG
@@ -975,7 +975,7 @@ static int ahash_final_ctx(struct ahash_request *req)
int sec4_sg_bytes, sec4_sg_src_index;
int digestsize = crypto_ahash_digestsize(ahash);
struct ahash_edesc *edesc;
-   int ret = 0;
+   int ret;
 
sec4_sg_src_index = 1 + (buflen ? 1 : 0);
sec4_sg_bytes = sec4_sg_src_index * sizeof(struct sec4_sg_entry);
@@ -1055,7 +1055,7 @@ static int ahash_finup_ctx(struct ahash_request *req)
int src_nents, mapped_nents;
int digestsize = crypto_ahash_digestsize(ahash);
struct ahash_edesc *edesc;
-   int ret = 0;
+   int ret;
 
src_nents = sg_nents_for_len(req->src, req->nbytes);
if (src_nents < 0) {
@@ -1139,7 +1139,7 @@ static int ahash_digest(struct ahash_request *req)
int digestsize = crypto_ahash_digestsize(ahash);
int src_nents, mapped_nents;
struct ahash_edesc *edesc;
-   int ret = 0;
+   int ret;
 
src_nents = sg_nents_for_len(req->src, req->nbytes);
if (src_nents < 0) {
@@ -1218,7 +1218,7 @@ static int ahash_final_no_ctx(struct ahash_request *req)
u32 *desc;
int digestsize = crypto_ahash_digestsize(ahash);
struct ahash_edesc *edesc;
-   int ret = 0;
+   int ret;
 
/* allocate space for base edesc and hw desc commands, link tables */
edesc = ahash_edesc_alloc(ctx, 0, ctx->sh_desc_digest,
@@ -1408,7 +1408,7 @@ static int ahash_finup_no_ctx(struct ahash_request *req)
int sec4_sg_bytes, sec4_sg_src_index, src_nents, mapped_nents;
int digestsize = crypto_ahash_digestsize(ahash);
struct ahash_edesc *edesc;
-   int ret = 0;
+   int ret;
 
src_nents = sg_nents_for_len(req->src, req->nbytes);
if (src_nents < 0) {
-- 
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/6] crypto-caamhash: Return a value directly in caam_hash_cra_init()

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 15 Sep 2016 14:56:12 +0200

* Return a value at the end without storing it in an intermediate variable.

* Delete the local variable "ret" which became unnecessary with
  this refactoring.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamhash.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 933252f..b1dbc53 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -1846,7 +1846,6 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 HASH_MSG_LEN + SHA256_DIGEST_SIZE,
 HASH_MSG_LEN + 64,
 HASH_MSG_LEN + SHA512_DIGEST_SIZE };
-   int ret = 0;
 
/*
 * Get a Job ring from Job Ring driver to ensure in-order
@@ -1866,10 +1865,7 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
 
crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
 sizeof(struct caam_hash_state));
-
-   ret = ahash_set_sh_desc(ahash);
-
-   return ret;
+   return ahash_set_sh_desc(ahash);
 }
 
 static void caam_hash_cra_exit(struct crypto_tfm *tfm)
-- 
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/6] crypto-caamhash: Rename a jump label in five functions

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 15 Sep 2016 14:43:38 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamhash.c | 49 +++---
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index 6017470..933252f 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -889,7 +889,7 @@ static int ahash_update_ctx(struct ahash_request *req)
ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
 edesc->sec4_sg, DMA_BIDIRECTIONAL);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
state->buf_dma = try_buf_map_to_sec4_sg(jrdev,
edesc->sec4_sg + 1,
@@ -919,7 +919,7 @@ static int ahash_update_ctx(struct ahash_request *req)
if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
dev_err(jrdev, "unable to map S/G table\n");
ret = -ENOMEM;
-   goto err;
+   goto unmap_ctx;
}
 
append_seq_in_ptr(desc, edesc->sec4_sg_dma, ctx->ctx_len +
@@ -935,7 +935,7 @@ static int ahash_update_ctx(struct ahash_request *req)
 
ret = caam_jr_enqueue(jrdev, desc, ahash_done_bi, req);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
ret = -EINPROGRESS;
} else if (*next_buflen) {
@@ -953,8 +953,7 @@ static int ahash_update_ctx(struct ahash_request *req)
 #endif
 
return ret;
-
- err:
+ unmap_ctx:
ahash_unmap_ctx(jrdev, edesc, req, ctx->ctx_len, DMA_BIDIRECTIONAL);
kfree(edesc);
return ret;
@@ -996,7 +995,7 @@ static int ahash_final_ctx(struct ahash_request *req)
ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
 edesc->sec4_sg, DMA_TO_DEVICE);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1,
buf, state->buf_dma, buflen,
@@ -1009,7 +1008,7 @@ static int ahash_final_ctx(struct ahash_request *req)
if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
dev_err(jrdev, "unable to map S/G table\n");
ret = -ENOMEM;
-   goto err;
+   goto unmap_ctx;
}
 
append_seq_in_ptr(desc, edesc->sec4_sg_dma, ctx->ctx_len + buflen,
@@ -1020,7 +1019,7 @@ static int ahash_final_ctx(struct ahash_request *req)
if (dma_mapping_error(jrdev, edesc->dst_dma)) {
dev_err(jrdev, "unable to map dst\n");
ret = -ENOMEM;
-   goto err;
+   goto unmap_ctx;
}
 
 #ifdef DEBUG
@@ -1030,11 +1029,10 @@ static int ahash_final_ctx(struct ahash_request *req)
 
ret = caam_jr_enqueue(jrdev, desc, ahash_done_ctx_src, req);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
return -EINPROGRESS;
-
-err:
+ unmap_ctx:
ahash_unmap_ctx(jrdev, edesc, req, digestsize, DMA_FROM_DEVICE);
kfree(edesc);
return ret;
@@ -1094,7 +1092,7 @@ static int ahash_finup_ctx(struct ahash_request *req)
ret = ctx_map_to_sec4_sg(desc, jrdev, state, ctx->ctx_len,
 edesc->sec4_sg, DMA_TO_DEVICE);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
state->buf_dma = try_buf_map_to_sec4_sg(jrdev, edesc->sec4_sg + 1,
buf, state->buf_dma, buflen,
@@ -1104,14 +1102,14 @@ static int ahash_finup_ctx(struct ahash_request *req)
  sec4_sg_src_index, ctx->ctx_len + buflen,
  req->nbytes);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
edesc->dst_dma = map_seq_out_ptr_result(desc, jrdev, req->result,
digestsize);
if (dma_mapping_error(jrdev, edesc->dst_dma)) {
dev_err(jrdev, "unable to map dst\n");
ret = -ENOMEM;
-   goto err;
+   goto unmap_ctx;
}
 
 #ifdef DEBUG
@@ -1121,11 +1119,10 @@ static int ahash_finup_ctx(struct ahash_request *req)
 
ret = caam_jr_enqueue(jrdev, desc, ahash_done_ctx_src, req);
if (ret)
-   goto err;
+   goto unmap_ctx;
 
return -EINPROGRESS;
-
-err:
+ unmap_ctx:
ahash_unmap_ctx(jrdev, edesc, req, digestsize, DMA_FROM_DEVICE);
kfree(edesc);
return ret;
@@ -1350,14 +1347,14 @@ 

[PATCH 2/6] crypto-caamhash: Rename jump labels in ahash_setkey()

2016-09-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Thu, 15 Sep 2016 13:54:49 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/caam/caamhash.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c
index f19df8f..6017470 100644
--- a/drivers/crypto/caam/caamhash.c
+++ b/drivers/crypto/caam/caamhash.c
@@ -533,7 +533,7 @@ static int ahash_setkey(struct crypto_ahash *ahash,
ret = hash_digest_key(ctx, key, , hashed_key,
  digestsize);
if (ret)
-   goto badkey;
+   goto bad_free_key;
key = hashed_key;
}
 
@@ -551,14 +551,14 @@ static int ahash_setkey(struct crypto_ahash *ahash,
 
ret = gen_split_hash_key(ctx, key, keylen);
if (ret)
-   goto badkey;
+   goto bad_free_key;
 
ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len,
  DMA_TO_DEVICE);
if (dma_mapping_error(jrdev, ctx->key_dma)) {
dev_err(jrdev, "unable to map key i/o memory\n");
ret = -ENOMEM;
-   goto map_err;
+   goto error_free_key;
}
 #ifdef DEBUG
print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
@@ -571,11 +571,10 @@ static int ahash_setkey(struct crypto_ahash *ahash,
dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len,
 DMA_TO_DEVICE);
}
-
-map_err:
+ error_free_key:
kfree(hashed_key);
return ret;
-badkey:
+ bad_free_key:
kfree(hashed_key);
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
-- 
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] hwrng-PIC32: Delete unnecessary assignment for the field "owner"

2016-08-16 Thread SF Markus Elfring
From: Markus Elfring 
Date: Tue, 16 Aug 2016 07:51:21 +0200

The field "owner" is set by the core.
Thus delete an unneeded initialisation.

Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
Signed-off-by: Markus Elfring 
---
 drivers/char/hw_random/pic32-rng.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/char/hw_random/pic32-rng.c 
b/drivers/char/hw_random/pic32-rng.c
index 108897b..11dc9b7 100644
--- a/drivers/char/hw_random/pic32-rng.c
+++ b/drivers/char/hw_random/pic32-rng.c
@@ -143,7 +143,6 @@ static struct platform_driver pic32_rng_driver = {
.remove = pic32_rng_remove,
.driver = {
.name   = "pic32-rng",
-   .owner  = THIS_MODULE,
.of_match_table = of_match_ptr(pic32_rng_of_match),
},
 };
-- 
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/3] crypto-ixp4xx: Delete unnecessary checks before the function call "dma_pool_destroy"

2015-11-17 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 16:51:21 +0100

The dma_pool_destroy() function tests whether its argument is NULL
and then returns immediately. Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 8f27903..e52496a 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -510,10 +510,8 @@ npe_error:
printk(KERN_ERR "%s not responding\n", npe_name(npe_c));
ret = -EIO;
 err:
-   if (ctx_pool)
-   dma_pool_destroy(ctx_pool);
-   if (buffer_pool)
-   dma_pool_destroy(buffer_pool);
+   dma_pool_destroy(ctx_pool);
+   dma_pool_destroy(buffer_pool);
npe_release(npe_c);
return ret;
 }
-- 
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/3] crypto-ixp4xx: Reduce assignment for a variable in init_ixp_crypto()

2015-11-17 Thread SF Markus Elfring
From: Markus Elfring 
Date: Tue, 17 Nov 2015 15:45:32 +0100

The variable "ret" was set more often than necessary by the
init_ixp_crypto() function.

* Omit its initialisation at the beginning.

* Use an error return code in two cases directly.

* Improve compliance with the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index e52496a..79b6958 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -433,17 +433,17 @@ static void crypto_done_action(unsigned long arg)
 
 static int init_ixp_crypto(struct device *dev)
 {
-   int ret = -ENODEV;
+   int ret;
u32 msg[2] = { 0, 0 };
 
if (! ( ~(*IXP4XX_EXP_CFG2) & (IXP4XX_FEATURE_HASH |
IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) {
printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
-   return ret;
+   return -ENODEV;
}
npe_c = npe_request(NPE_ID);
if (!npe_c)
-   return ret;
+   return -ENODEV;
 
if (!npe_running(npe_c)) {
ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
@@ -481,13 +481,14 @@ static int init_ixp_crypto(struct device *dev)
BUILD_BUG_ON(SHA1_DIGEST_SIZE > sizeof(struct buffer_desc));
buffer_pool = dma_pool_create("buffer", dev,
sizeof(struct buffer_desc), 32, 0);
-   ret = -ENOMEM;
if (!buffer_pool) {
+   ret = -ENOMEM;
goto err;
}
ctx_pool = dma_pool_create("context", dev,
NPE_CTX_LEN, 16, 0);
if (!ctx_pool) {
+   ret = -ENOMEM;
goto err;
}
ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0,
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/3] crypto-ixp4xx: Less function calls in init_ixp_crypto() after error detection

2015-11-17 Thread SF Markus Elfring
From: Markus Elfring 
Date: Tue, 17 Nov 2015 16:15:21 +0100

The dma_pool_destroy() function was called in up to two cases by the
init_ixp_crypto() function during error handling even if a call of
the dma_pool_create() function failed.

This implementation detail could be improved by the adjustment
of jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 79b6958..0a5969c 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -483,23 +483,23 @@ static int init_ixp_crypto(struct device *dev)
sizeof(struct buffer_desc), 32, 0);
if (!buffer_pool) {
ret = -ENOMEM;
-   goto err;
+   goto release_npe;
}
ctx_pool = dma_pool_create("context", dev,
NPE_CTX_LEN, 16, 0);
if (!ctx_pool) {
ret = -ENOMEM;
-   goto err;
+   goto destroy_buffer_pool;
}
ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0,
 "ixp_crypto:out", NULL);
if (ret)
-   goto err;
+   goto destroy_ctx_pool;
ret = qmgr_request_queue(RECV_QID, NPE_QLEN, 0, 0,
 "ixp_crypto:in", NULL);
if (ret) {
qmgr_release_queue(SEND_QID);
-   goto err;
+   goto destroy_ctx_pool;
}
qmgr_set_irq(RECV_QID, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
tasklet_init(_done_tasklet, crypto_done_action, 0);
@@ -510,9 +510,11 @@ static int init_ixp_crypto(struct device *dev)
 npe_error:
printk(KERN_ERR "%s not responding\n", npe_name(npe_c));
ret = -EIO;
-err:
+destroy_ctx_pool:
dma_pool_destroy(ctx_pool);
+destroy_buffer_pool:
dma_pool_destroy(buffer_pool);
+release_npe:
npe_release(npe_c);
return ret;
 }
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/3] crypto-ixp4xx: Deletion of a few unnecessary checks

2015-11-17 Thread SF Markus Elfring
From: Markus Elfring 
Date: Tue, 17 Nov 2015 16:26:01 +0100
Subject: [PATCH 0/3] crypto-ixp4xx: Deletion of a few unnecessary checks

Further update suggestions were taken into account after a patch
was applied from static source code analysis.

Markus Elfring (3):
  Delete unnecessary checks before the function call "dma_pool_destroy"
  Reduce assignment for a variable in init_ixp_crypto()
  crypto-ixp4xx: Less function calls in init_ixp_crypto() after error detection

 drivers/crypto/ixp4xx_crypto.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

-- 
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] crypto-ixp4xx: Two function calls less in init_ixp_crypto() after error detection

2015-11-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 18:28:39 +0100

The dma_pool_destroy() function was called twice with a null pointer
if a "npe_error" was reported.

This implementation detail could be improved by the introduction
of another jump label.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index e52496a..efe0eca 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -509,9 +509,11 @@ static int init_ixp_crypto(struct device *dev)
 npe_error:
printk(KERN_ERR "%s not responding\n", npe_name(npe_c));
ret = -EIO;
+   goto release_npe;
 err:
dma_pool_destroy(ctx_pool);
dma_pool_destroy(buffer_pool);
+release_npe:
npe_release(npe_c);
return ret;
 }
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/4] crypto-ixp4xx: Deletion of a few unnecessary checks

2015-11-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 19:39:00 +0100

Further update suggestions were taken into account after a patch
was applied from static source code analysis.

Markus Elfring (4):
  Delete unnecessary checks before the function call "dma_pool_destroy"
  Two function calls less in init_ixp_crypto() after error detection
  Reduce assignment for a variable in init_ixp_crypto()
  Less function calls in init_ixp_crypto() after error detection

 drivers/crypto/ixp4xx_crypto.c | 28 +++-
 1 file changed, 15 insertions(+), 13 deletions(-)

-- 
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] crypto-ixp4xx: Delete unnecessary checks before the function call "dma_pool_destroy"

2015-11-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 16:51:21 +0100

The dma_pool_destroy() function tests whether its argument is NULL
and then returns immediately. Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 8f27903..e52496a 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -510,10 +510,8 @@ npe_error:
printk(KERN_ERR "%s not responding\n", npe_name(npe_c));
ret = -EIO;
 err:
-   if (ctx_pool)
-   dma_pool_destroy(ctx_pool);
-   if (buffer_pool)
-   dma_pool_destroy(buffer_pool);
+   dma_pool_destroy(ctx_pool);
+   dma_pool_destroy(buffer_pool);
npe_release(npe_c);
return ret;
 }
-- 
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] crypto-ixp4xx: Reduce assignment for a variable in init_ixp_crypto()

2015-11-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 19:06:44 +0100

The variable "ret" was set more often than necessary by the
init_ixp_crypto() function.

* Omit its initialisation at the beginning.

* Use an error return code in two cases directly.

* Improve compliance with the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index efe0eca..97da36a 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -433,17 +433,17 @@ static void crypto_done_action(unsigned long arg)
 
 static int init_ixp_crypto(struct device *dev)
 {
-   int ret = -ENODEV;
+   int ret;
u32 msg[2] = { 0, 0 };
 
if (! ( ~(*IXP4XX_EXP_CFG2) & (IXP4XX_FEATURE_HASH |
IXP4XX_FEATURE_AES | IXP4XX_FEATURE_DES))) {
printk(KERN_ERR "ixp_crypto: No HW crypto available\n");
-   return ret;
+   return -ENODEV;
}
npe_c = npe_request(NPE_ID);
if (!npe_c)
-   return ret;
+   return -ENODEV;
 
if (!npe_running(npe_c)) {
ret = npe_load_firmware(npe_c, npe_name(npe_c), dev);
@@ -481,13 +481,14 @@ static int init_ixp_crypto(struct device *dev)
BUILD_BUG_ON(SHA1_DIGEST_SIZE > sizeof(struct buffer_desc));
buffer_pool = dma_pool_create("buffer", dev,
sizeof(struct buffer_desc), 32, 0);
-   ret = -ENOMEM;
if (!buffer_pool) {
+   ret = -ENOMEM;
goto err;
}
ctx_pool = dma_pool_create("context", dev,
NPE_CTX_LEN, 16, 0);
if (!ctx_pool) {
+   ret = -ENOMEM;
goto err;
}
ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0,
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] crypto-ixp4xx: Less function calls in init_ixp_crypto() after error detection

2015-11-15 Thread SF Markus Elfring
From: Markus Elfring 
Date: Sun, 15 Nov 2015 19:23:55 +0100

The dma_pool_destroy() function was called in up to two cases by the
init_ixp_crypto() function during error handling even if a call of
the dma_pool_create() function failed.

This implementation detail could be improved by the adjustment
of jump targets according to the Linux coding style convention.

Signed-off-by: Markus Elfring 
---
 drivers/crypto/ixp4xx_crypto.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index 97da36a..a2c3155 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -483,23 +483,23 @@ static int init_ixp_crypto(struct device *dev)
sizeof(struct buffer_desc), 32, 0);
if (!buffer_pool) {
ret = -ENOMEM;
-   goto err;
+   goto release_npe;
}
ctx_pool = dma_pool_create("context", dev,
NPE_CTX_LEN, 16, 0);
if (!ctx_pool) {
ret = -ENOMEM;
-   goto err;
+   goto destroy_buffer_pool;
}
ret = qmgr_request_queue(SEND_QID, NPE_QLEN_TOTAL, 0, 0,
 "ixp_crypto:out", NULL);
if (ret)
-   goto err;
+   goto destroy_ctx_pool;
ret = qmgr_request_queue(RECV_QID, NPE_QLEN, 0, 0,
 "ixp_crypto:in", NULL);
if (ret) {
qmgr_release_queue(SEND_QID);
-   goto err;
+   goto destroy_ctx_pool;
}
qmgr_set_irq(RECV_QID, QUEUE_IRQ_SRC_NOT_EMPTY, irqhandler, NULL);
tasklet_init(_done_tasklet, crypto_done_action, 0);
@@ -511,8 +511,9 @@ npe_error:
printk(KERN_ERR "%s not responding\n", npe_name(npe_c));
ret = -EIO;
goto release_npe;
-err:
+destroy_ctx_pool:
dma_pool_destroy(ctx_pool);
+destroy_buffer_pool:
dma_pool_destroy(buffer_pool);
 release_npe:
npe_release(npe_c);
-- 
2.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto-qat: Deletion of unnecessary checks before two function calls

2015-06-26 Thread SF Markus Elfring
From: Markus Elfring elfr...@users.sourceforge.net
Date: Fri, 26 Jun 2015 20:30:11 +0200

The functions kfree() and release_firmware() test whether their argument
is NULL and then return immediately.
Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring elfr...@users.sourceforge.net
---
 drivers/crypto/qat/qat_common/adf_accel_engine.c | 5 +
 drivers/crypto/qat/qat_common/adf_transport.c| 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/adf_accel_engine.c 
b/drivers/crypto/qat/qat_common/adf_accel_engine.c
index 7f8b66c..fdda8e7 100644
--- a/drivers/crypto/qat/qat_common/adf_accel_engine.c
+++ b/drivers/crypto/qat/qat_common/adf_accel_engine.c
@@ -88,10 +88,7 @@ void adf_ae_fw_release(struct adf_accel_dev *accel_dev)
 
qat_uclo_del_uof_obj(loader_data-fw_loader);
qat_hal_deinit(loader_data-fw_loader);
-
-   if (loader_data-uof_fw)
-   release_firmware(loader_data-uof_fw);
-
+   release_firmware(loader_data-uof_fw);
loader_data-uof_fw = NULL;
loader_data-fw_loader = NULL;
 }
diff --git a/drivers/crypto/qat/qat_common/adf_transport.c 
b/drivers/crypto/qat/qat_common/adf_transport.c
index ccec3274..db2926b 100644
--- a/drivers/crypto/qat/qat_common/adf_transport.c
+++ b/drivers/crypto/qat/qat_common/adf_transport.c
@@ -449,7 +449,7 @@ static int adf_init_bank(struct adf_accel_dev *accel_dev,
 err:
for (i = 0; i  ADF_ETR_MAX_RINGS_PER_BANK; i++) {
ring = bank-rings[i];
-   if (hw_data-tx_rings_mask  (1  i)  ring-inflights)
+   if (hw_data-tx_rings_mask  (1  i))
kfree(ring-inflights);
}
return -ENOMEM;
-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto-jitterentropy: Delete unnecessary checks before the function call kzfree

2015-06-23 Thread SF Markus Elfring
From: Markus Elfring elfr...@users.sourceforge.net
Date: Tue, 23 Jun 2015 22:30:21 +0200

The kzfree() function tests whether its argument is NULL and then
returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring elfr...@users.sourceforge.net
---
 crypto/jitterentropy.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/crypto/jitterentropy.c b/crypto/jitterentropy.c
index d3c3045..22ded3e 100644
--- a/crypto/jitterentropy.c
+++ b/crypto/jitterentropy.c
@@ -698,11 +698,9 @@ static struct rand_data 
*jent_entropy_collector_alloc(unsigned int osr,
 
 static void jent_entropy_collector_free(struct rand_data *entropy_collector)
 {
-   if (entropy_collector-mem)
-   kzfree(entropy_collector-mem);
+   kzfree(entropy_collector-mem);
entropy_collector-mem = NULL;
-   if (entropy_collector)
-   kzfree(entropy_collector);
+   kzfree(entropy_collector);
entropy_collector = NULL;
 }
 
-- 
2.4.4

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: crypto-drbg: Deletion of unnecessary checks before the function call kzfree

2014-11-20 Thread SF Markus Elfring
 Sorry but you're too late as someone else has already fixed this :)

Thanks for your feedback.

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/crypto/drbg.c?id=46f64f6ef978dc1f36ebaa50ed79c7c8386711ee

Regards,
Markus

--
To unsubscribe from this list: send the line unsubscribe linux-crypto in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html