[PATCH 1/2] staging: ccree: remove unnecessary cast on kmalloc

2017-07-09 Thread Gustavo A. R. Silva
The assignment operator implicitly converts a void pointer to the type of the
pointer it is assigned to.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression * e;
expression arg1, arg2;
type T;
@@

- e=(T*)
+ e=
kmalloc(arg1, arg2);

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index b35871e..18a8694 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -1725,8 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
struct buff_mgr_handle *buff_mgr_handle;
struct device *dev = >plat_dev->dev;
 
-   buff_mgr_handle = (struct buff_mgr_handle *)
-   kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+   buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
if (!buff_mgr_handle)
return -ENOMEM;
 
-- 
2.5.0



[PATCH 2/2] staging: ccree: use sizeof(*var) in kmalloc

2017-07-08 Thread Gustavo A. R. Silva
Fix the following checkpatch warning:

CHECK: Prefer kmalloc(sizeof(*buff_mgr_handle)...)
over kmalloc(sizeof(struct buff_mgr_handle)...)

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/ccree/ssi_buffer_mgr.c 
b/drivers/staging/ccree/ssi_buffer_mgr.c
index 18a8694..9caff9b 100644
--- a/drivers/staging/ccree/ssi_buffer_mgr.c
+++ b/drivers/staging/ccree/ssi_buffer_mgr.c
@@ -1725,7 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
struct buff_mgr_handle *buff_mgr_handle;
struct device *dev = >plat_dev->dev;
 
-   buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+   buff_mgr_handle = kmalloc(sizeof(*buff_mgr_handle), GFP_KERNEL);
if (!buff_mgr_handle)
return -ENOMEM;
 
-- 
2.5.0



[PATCH] crypto: omap-sham: remove unnecessary static in omap_sham_remove()

2017-07-18 Thread Gustavo A. R. Silva
Remove unnecessary static on local variable dd. Such variable
is initialized before being used, on every execution path throughout
the function. The static has no benefit and, removing it reduces the
object file size.

This issue was detected using Coccinelle and the following semantic patch:
https://github.com/GustavoARSilva/coccinelle/blob/master/static/static_unused.cocci

In the following log you can see a difference in the object file size.
This log is the output of the size command, before and after the code
change:

before:
   textdata bss dec hex filename
  26135   11944 128   38207953f drivers/crypto/omap-sham.o

after:
   textdata bss dec hex filename
  26084   11856  64   380049474 drivers/crypto/omap-sham.o

Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 drivers/crypto/omap-sham.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 9ad9d39..c40ac30 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -2133,7 +2133,7 @@ static int omap_sham_probe(struct platform_device *pdev)
 
 static int omap_sham_remove(struct platform_device *pdev)
 {
-   static struct omap_sham_dev *dd;
+   struct omap_sham_dev *dd;
int i, j;
 
dd = platform_get_drvdata(pdev);
-- 
2.5.0



[PATCH] crypto: img-hash: remove unnecessary static in img_hash_remove()

2017-07-18 Thread Gustavo A. R. Silva
Remove unnecessary static on local variable hdev. Such variable
is initialized before being used, on every execution path throughout
the function. The static has no benefit and, removing it reduces the
object file size.

This issue was detected using Coccinelle and the following semantic patch:
https://github.com/GustavoARSilva/coccinelle/blob/master/static/static_unused.cocci

In the following log you can see a significant difference in the object
file size. This log is the output of the size command, before and after
the code change:

before:
   textdata bss dec hex filename
  148426464 128   2143453ba drivers/crypto/img-hash.o

after:
   textdata bss dec hex filename
  147896376  64   2122952ed drivers/crypto/img-hash.o

Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 drivers/crypto/img-hash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c
index 0c6a917..b87000a 100644
--- a/drivers/crypto/img-hash.c
+++ b/drivers/crypto/img-hash.c
@@ -1054,7 +1054,7 @@ static int img_hash_probe(struct platform_device *pdev)
 
 static int img_hash_remove(struct platform_device *pdev)
 {
-   static struct img_hash_dev *hdev;
+   struct img_hash_dev *hdev;
 
hdev = platform_get_drvdata(pdev);
spin_lock(_hash.lock);
-- 
2.5.0



[PATCH] crypto: atmel-sha: remove unnecessary static in atmel_sha_remove()

2017-07-18 Thread Gustavo A. R. Silva
Remove unnecessary static on local variable sha_dd. Such variable
is initialized before being used, on every execution path throughout
the function. The static has no benefit and, removing it reduces the
object file size.

This issue was detected using Coccinelle and the following semantic patch:
https://github.com/GustavoARSilva/coccinelle/blob/master/static/static_unused.cocci

In the following log you can see a significant difference in the object
file size. This log is the output of the size command, before and after
the code change:

before:
   textdata bss dec hex filename
  30005   10264 128   403979dcd drivers/crypto/atmel-sha.o

after:
   textdata bss dec hex filename
  29934   10208  64   402069d0e drivers/crypto/atmel-sha.o

Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 drivers/crypto/atmel-sha.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index dad4e5b..3e2f41b 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -2883,7 +2883,7 @@ static int atmel_sha_probe(struct platform_device *pdev)
 
 static int atmel_sha_remove(struct platform_device *pdev)
 {
-   static struct atmel_sha_dev *sha_dd;
+   struct atmel_sha_dev *sha_dd;
 
sha_dd = platform_get_drvdata(pdev);
if (!sha_dd)
-- 
2.5.0



[PATCH] crypto: atmel-tdes: remove unnecessary static in atmel_tdes_remove()

2017-07-18 Thread Gustavo A. R. Silva
Remove unnecessary static on local variable tdes_dd. Such variable
is initialized before being used, on every execution path throughout
the function. The static has no benefit and, removing it reduces the
object file size.

This issue was detected using Coccinelle and the following semantic patch:
https://github.com/GustavoARSilva/coccinelle/blob/master/static/static_unused.cocci

In the following log you can see a significant difference in the object
file size. This log is the output of the size command, before and after
the code change:

before:
   textdata bss dec hex filename
  170798704 128   259116537 drivers/crypto/atmel-tdes.o

after:
   textdata bss dec hex filename
  170398616  64   257196477 drivers/crypto/atmel-tdes.o

Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 drivers/crypto/atmel-tdes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index b25f1b3..f4b335d 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -1487,7 +1487,7 @@ static int atmel_tdes_probe(struct platform_device *pdev)
 
 static int atmel_tdes_remove(struct platform_device *pdev)
 {
-   static struct atmel_tdes_dev *tdes_dd;
+   struct atmel_tdes_dev *tdes_dd;
 
tdes_dd = platform_get_drvdata(pdev);
if (!tdes_dd)
-- 
2.5.0



[PATCH] crypto: mediatek: fix error return code in mtk_crypto_probe()

2017-06-30 Thread Gustavo A. R. Silva
Propagate the return value of platform_get_irq on failure.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/mediatek/mtk-platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/mediatek/mtk-platform.c 
b/drivers/crypto/mediatek/mtk-platform.c
index 000b650..b182e94 100644
--- a/drivers/crypto/mediatek/mtk-platform.c
+++ b/drivers/crypto/mediatek/mtk-platform.c
@@ -500,7 +500,7 @@ static int mtk_crypto_probe(struct platform_device *pdev)
cryp->irq[i] = platform_get_irq(pdev, i);
if (cryp->irq[i] < 0) {
dev_err(cryp->dev, "no IRQ:%d resource info\n", i);
-   return -ENXIO;
+   return cryp->irq[i];
}
}
 
-- 
2.5.0



[PATCH] crypto: ccp-platform: print error message on platform_get_irq failure

2017-06-30 Thread Gustavo A. R. Silva
Print error message on platform_get_irq failure before return.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/ccp/ccp-platform.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/ccp/ccp-platform.c 
b/drivers/crypto/ccp/ccp-platform.c
index e26969e..6020c4a 100644
--- a/drivers/crypto/ccp/ccp-platform.c
+++ b/drivers/crypto/ccp/ccp-platform.c
@@ -66,8 +66,10 @@ static int ccp_get_irq(struct ccp_device *ccp)
int ret;
 
ret = platform_get_irq(pdev, 0);
-   if (ret < 0)
+   if (ret < 0) {
+   dev_notice(dev, "unable to get IRQ (%d)\n", ret);
return ret;
+   }
 
ccp->irq = ret;
ret = request_irq(ccp->irq, ccp->vdata->perform->irqhandler, 0,
-- 
2.5.0



[PATCH] crypto: omap-aes: fix error return code in omap_aes_probe()

2017-06-30 Thread Gustavo A. R. Silva
Propagate the return value of platform_get_irq on failure.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/omap-aes.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index 5120a17..c376a3e 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -1095,6 +1095,7 @@ static int omap_aes_probe(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_err(dev, "can't get IRQ resource\n");
+   err = irq;
goto err_irq;
}
 
-- 
2.5.0



[PATCH] crypto: mxc-scc: fix error code in mxc_scc_probe()

2017-06-30 Thread Gustavo A. R. Silva
Print and propagate the return value of platform_get_irq on failure.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/mxc-scc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/mxc-scc.c b/drivers/crypto/mxc-scc.c
index ee4be1b0..e01c463 100644
--- a/drivers/crypto/mxc-scc.c
+++ b/drivers/crypto/mxc-scc.c
@@ -708,8 +708,8 @@ static int mxc_scc_probe(struct platform_device *pdev)
for (i = 0; i < 2; i++) {
irq = platform_get_irq(pdev, i);
if (irq < 0) {
-   dev_err(dev, "failed to get irq resource\n");
-   ret = -EINVAL;
+   dev_err(dev, "failed to get irq resource: %d\n", irq);
+   ret = irq;
goto err_out;
}
 
-- 
2.5.0



[PATCH] crypto: omap-des: fix error return code in omap_des_probe()

2017-06-30 Thread Gustavo A. R. Silva
Print and propagate the return value of platform_get_irq on failure.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/omap-des.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
index 0bcab00..d37c950 100644
--- a/drivers/crypto/omap-des.c
+++ b/drivers/crypto/omap-des.c
@@ -1023,7 +1023,8 @@ static int omap_des_probe(struct platform_device *pdev)
 
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
-   dev_err(dev, "can't get IRQ resource\n");
+   dev_err(dev, "can't get IRQ resource: %d\n", irq);
+   err = irq;
goto err_irq;
}
 
-- 
2.5.0



[PATCH] crypto: mxs-dcp: print error message on platform_get_irq failure

2017-06-30 Thread Gustavo A. R. Silva
Print error message on platform_get_irq failure before return.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/mxs-dcp.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index 625ee50..764be3e 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -908,12 +908,16 @@ static int mxs_dcp_probe(struct platform_device *pdev)
 
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
dcp_vmi_irq = platform_get_irq(pdev, 0);
-   if (dcp_vmi_irq < 0)
+   if (dcp_vmi_irq < 0) {
+   dev_err(dev, "Failed to get IRQ: (%d)!\n", dcp_vmi_irq);
return dcp_vmi_irq;
+   }
 
dcp_irq = platform_get_irq(pdev, 1);
-   if (dcp_irq < 0)
+   if (dcp_irq < 0) {
+   dev_err(dev, "Failed to get IRQ: (%d)!\n", dcp_irq);
return dcp_irq;
+   }
 
sdcp = devm_kzalloc(dev, sizeof(*sdcp), GFP_KERNEL);
if (!sdcp)
-- 
2.5.0



[PATCH] crypto: brcm: add NULL check on of_match_device() return value

2017-07-07 Thread Gustavo A. R. Silva
Check return value from call to of_match_device()
in order to prevent a NULL pointer dereference.

In case of NULL print error message and return -ENODEV

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/bcm/cipher.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c
index 9cfd36c..f1a826f 100644
--- a/drivers/crypto/bcm/cipher.c
+++ b/drivers/crypto/bcm/cipher.c
@@ -4813,6 +4813,11 @@ static int spu_dt_read(struct platform_device *pdev)
int err;
 
match = of_match_device(of_match_ptr(bcm_spu_dt_ids), dev);
+   if (!match) {
+   dev_err(>dev, "Failed to match device\n");
+   return -ENODEV;
+   }
+
matched_spu_type = match->data;
 
if (iproc_priv.spu.num_spu > 1) {
-- 
2.5.0



[PATCH] crypto: tcrypt: mark expected switch fall-throughs in do_test()

2017-10-09 Thread Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Cc: Herbert Xu <herb...@gondor.apana.org.au>
Cc: "David S. Miller" <da...@davemloft.net>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 crypto/tcrypt.c | 108 ++--
 1 file changed, 51 insertions(+), 57 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index a371c072..28bffa6 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -1606,119 +1606,116 @@ static int do_test(const char *alg, u32 type, u32 
mask, int m)
  speed_template_32);
break;
 
-
case 300:
if (alg) {
test_hash_speed(alg, sec, generic_hash_speed_template);
break;
}
-
/* fall through */
-
case 301:
test_hash_speed("md4", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 302:
test_hash_speed("md5", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 303:
test_hash_speed("sha1", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 304:
test_hash_speed("sha256", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 305:
test_hash_speed("sha384", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 306:
test_hash_speed("sha512", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 307:
test_hash_speed("wp256", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 308:
test_hash_speed("wp384", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 309:
test_hash_speed("wp512", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 310:
test_hash_speed("tgr128", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 311:
test_hash_speed("tgr160", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 312:
test_hash_speed("tgr192", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 313:
test_hash_speed("sha224", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 314:
test_hash_speed("rmd128", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 315:
test_hash_speed("rmd160", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 316:
test_hash_speed("rmd256", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 317:
test_hash_speed("rmd320", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 318:
test_hash_speed("ghash-generic", sec, hash_speed_template_16);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 319:
test_hash_speed("crc32c", sec, generic_hash_speed_template);
if (mode > 300 && mode < 400) break;
-
+   /* fall through */
case 320:
test_hash_speed("crct10dif"

[PATCH] crypto: qat: qat_common: qat_uclo - mark expected switch fall-throughs

2017-10-12 Thread Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/qat/qat_common/qat_uclo.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/crypto/qat/qat_common/qat_uclo.c 
b/drivers/crypto/qat/qat_common/qat_uclo.c
index e2454d9..61ae091 100644
--- a/drivers/crypto/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/qat/qat_common/qat_uclo.c
@@ -791,6 +791,7 @@ static int qat_uclo_init_reg(struct 
icp_qat_fw_loader_handle *handle,
case ICP_GPA_ABS:
case ICP_GPB_ABS:
ctx_mask = 0;
+   /* fall through */
case ICP_GPA_REL:
case ICP_GPB_REL:
return qat_hal_init_gpr(handle, ae, ctx_mask, reg_type,
@@ -800,6 +801,7 @@ static int qat_uclo_init_reg(struct 
icp_qat_fw_loader_handle *handle,
case ICP_SR_RD_ABS:
case ICP_DR_RD_ABS:
ctx_mask = 0;
+   /* fall through */
case ICP_SR_REL:
case ICP_DR_REL:
case ICP_SR_RD_REL:
@@ -809,6 +811,7 @@ static int qat_uclo_init_reg(struct 
icp_qat_fw_loader_handle *handle,
case ICP_SR_WR_ABS:
case ICP_DR_WR_ABS:
ctx_mask = 0;
+   /* fall through */
case ICP_SR_WR_REL:
case ICP_DR_WR_REL:
return qat_hal_init_wr_xfer(handle, ae, ctx_mask, reg_type,
-- 
2.7.4



Re: [PATCH] crypto: qat: qat_common: qat_uclo - mark expected switch fall-throughs

2017-11-03 Thread Gustavo A. R. Silva


Quoting Herbert Xu <herb...@gondor.apana.org.au>:


On Thu, Oct 12, 2017 at 05:55:29PM -0500, Gustavo A. R. Silva wrote:

In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>


Patch applied.  Thanks.


Thank you, Herbert.
--
Gustavo A. R. Silva






[PATCH] crypto: chcr - Replace _manual_ swap with swap macro

2017-11-03 Thread Gustavo A. R. Silva
Make use of the swap macro and remove unnecessary variable temp.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <garsi...@embeddedor.com>
---
 drivers/crypto/chelsio/chcr_algo.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_algo.c 
b/drivers/crypto/chelsio/chcr_algo.c
index 936bdd8..4b508cb 100644
--- a/drivers/crypto/chelsio/chcr_algo.c
+++ b/drivers/crypto/chelsio/chcr_algo.c
@@ -1469,11 +1469,8 @@ static int chcr_ahash_update(struct ahash_request *req)
return -ENOMEM;
 
if (remainder) {
-   u8 *temp;
/* Swap buffers */
-   temp = req_ctx->reqbfr;
-   req_ctx->reqbfr = req_ctx->skbfr;
-   req_ctx->skbfr = temp;
+   swap(req_ctx->reqbfr, req_ctx->skbfr);
sg_pcopy_to_buffer(req->src, sg_nents(req->src),
   req_ctx->reqbfr, remainder, req->nbytes -
   remainder);
-- 
2.7.4



Re: [RESEND] SHASH_DESC_ON_STACK macro

2018-04-05 Thread Gustavo A. R. Silva

Hi Herbert,

On 03/27/2018 05:07 AM, Herbert Xu wrote:

On Fri, Mar 23, 2018 at 02:09:46PM -0500, Gustavo A. R. Silva wrote:


Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and
while working on that I came across the following macro at
include/crypto/hash.h:154:

#define SHASH_DESC_ON_STACK(shash, ctx)   \
 char __##shash##_desc[sizeof(struct shash_desc) + \
 crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
 struct shash_desc *shash = (struct shash_desc *)__##shash##_desc


Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?


descsize is capped at PAGE_SIZE / 8.



Sorry for the late response. It seems I lost track of this email somehow.

OK. So based on your response I will propose a patch for this.

Thanks!
--
Gustavo



[PATCH] crypto : chtls_cm - Fix potential NULL pointer dereferences

2018-04-03 Thread Gustavo A. R. Silva
Add null checks on lookup_tid() return value in order to prevent
null pointer dereferences.

Addresses-Coverity-ID: 1467422 ("Dereference null return value")
Addresses-Coverity-ID: 1467443 ("Dereference null return value")
Addresses-Coverity-ID: 1467445 ("Dereference null return value")
Addresses-Coverity-ID: 1467449 ("Dereference null return value")
Fixes: cc35c88ae4db ("crypto : chtls - CPL handler definition")
Signed-off-by: Gustavo A. R. Silva <gust...@embeddedor.com>
---
 drivers/crypto/chelsio/chtls/chtls_cm.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/crypto/chelsio/chtls/chtls_cm.c 
b/drivers/crypto/chelsio/chtls/chtls_cm.c
index 82a473a..23c43b8 100644
--- a/drivers/crypto/chelsio/chtls/chtls_cm.c
+++ b/drivers/crypto/chelsio/chtls/chtls_cm.c
@@ -1537,6 +1537,10 @@ static int chtls_rx_data(struct chtls_dev *cdev, struct 
sk_buff *skb)
struct sock *sk;
 
sk = lookup_tid(cdev->tids, hwtid);
+   if (unlikely(!sk)) {
+   pr_err("can't find conn. for hwtid %u.\n", hwtid);
+   return -EINVAL;
+   }
skb_dst_set(skb, NULL);
process_cpl_msg(chtls_recv_data, sk, skb);
return 0;
@@ -1585,6 +1589,10 @@ static int chtls_rx_pdu(struct chtls_dev *cdev, struct 
sk_buff *skb)
struct sock *sk;
 
sk = lookup_tid(cdev->tids, hwtid);
+   if (unlikely(!sk)) {
+   pr_err("can't find conn. for hwtid %u.\n", hwtid);
+   return -EINVAL;
+   }
skb_dst_set(skb, NULL);
process_cpl_msg(chtls_recv_pdu, sk, skb);
return 0;
@@ -1646,6 +1654,10 @@ static int chtls_rx_cmp(struct chtls_dev *cdev, struct 
sk_buff *skb)
struct sock *sk;
 
sk = lookup_tid(cdev->tids, hwtid);
+   if (unlikely(!sk)) {
+   pr_err("can't find conn. for hwtid %u.\n", hwtid);
+   return -EINVAL;
+   }
skb_dst_set(skb, NULL);
process_cpl_msg(chtls_rx_hdr, sk, skb);
 
@@ -2105,6 +2117,10 @@ static int chtls_wr_ack(struct chtls_dev *cdev, struct 
sk_buff *skb)
struct sock *sk;
 
sk = lookup_tid(cdev->tids, hwtid);
+   if (unlikely(!sk)) {
+   pr_err("can't find conn. for hwtid %u.\n", hwtid);
+   return -EINVAL;
+   }
process_cpl_msg(chtls_rx_ack, sk, skb);
 
return 0;
-- 
2.7.4



[crypto-chtls] Supicious code in chtls_io

2018-04-03 Thread Gustavo A. R. Silva
Hi all,

While doing some static analysis I came across the following piece of code at 
drivers/crypto/chelsio/chtls/chtls_io.c:1203:

1203 if (!size)
1204 break;
1205 
1206 if (unlikely(ULP_SKB_CB(skb)->flags & 
ULPCB_FLAG_NO_APPEND))
1207 push_frames_if_head(sk);
1208 continue;
1209 
1210 set_bit(SOCK_NOSPACE, >sk_socket->flags);
1211 }


The issue is that in the code above, set_bit is never reached due to the 
'continue' statement at line 1208.

I wonder if the actual intention of the code was something like this:

diff --git a/drivers/crypto/chelsio/chtls/chtls_io.c 
b/drivers/crypto/chelsio/chtls/chtls_io.c
index 5a75be4..a949a6c 100644
--- a/drivers/crypto/chelsio/chtls/chtls_io.c
+++ b/drivers/crypto/chelsio/chtls/chtls_io.c
@@ -1203,9 +1203,10 @@ int chtls_sendpage(struct sock *sk, struct page *page,
if (!size)
break;
 
-   if (unlikely(ULP_SKB_CB(skb)->flags & ULPCB_FLAG_NO_APPEND))
+   if (unlikely(ULP_SKB_CB(skb)->flags & ULPCB_FLAG_NO_APPEND)) {
push_frames_if_head(sk);
-   continue;
+   continue;
+   }
 
set_bit(SOCK_NOSPACE, >sk_socket->flags);
}


What do you think?

I can send a proper patch for this.

Thanks
--
Gustavo


[RESEND] SHASH_DESC_ON_STACK macro

2018-03-23 Thread Gustavo A. R. Silva


Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and 
while working on that I came across the following macro at 
include/crypto/hash.h:154:


#define SHASH_DESC_ON_STACK(shash, ctx)   \
char __##shash##_desc[sizeof(struct shash_desc) + \
crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
struct shash_desc *shash = (struct shash_desc *)__##shash##_desc


Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

Do you think it is feasible to replace the call to crypto_shash_descsize 
with a constant value and get rid of 46 VLA warnings?


I have sent some patches to replace the use of this macro with dynamic 
memory allocation instead, but it seems that this is not a suitable 
solution for all cases due to performance issues.


[1] https://lkml.org/lkml/2018/3/7/621

I'd really appreciate any feedback.
Thanks
--
Gustavo


[RFC] SHASH_DESC_ON_STACK macro

2018-03-21 Thread Gustavo A. R. Silva

Hi Herbert,

There is an ongoing effort to remove all VLAs from the code base [1] and 
while working on that I came across the following macro at 
include/crypto/hash.h:154:


#define SHASH_DESC_ON_STACK(shash, ctx)   \
char __##shash##_desc[sizeof(struct shash_desc) + \
crypto_shash_descsize(ctx)] CRYPTO_MINALIGN_ATTR; \
struct shash_desc *shash = (struct shash_desc *)__##shash##_desc


Currently, this macro is being used in 46 different places.

I wonder how big can tfm->descsize can get?

Do you think it is feasible to replace the call to crypto_shash_descsize 
with a constant value and get rid of 46 VLA warnings?


I have sent some patches to replace the use of this macro with dynamic 
memory allocation instead, but it seems that this is not a suitable 
solution for all cases due to performance issues.


[1] https://lkml.org/lkml/2018/3/7/621

I'd really appreciate any feedback.
Thanks
--
Gustavo