Skip to contentSkip to conversation

crypto/omap: Adjustments for three function implementations

PATCH In review SF Markus Elfring 2 participants 5 messages Feb 14, 2018 – Feb 23, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover crypto/omap: Adjustments for three function implementations

From: Markus Elfring <[email protected]>
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(-)
Signature · 1 line
2.16.1
#1 lore raw

PATCH 1/2 crypto: omap: Delete an error message for a failed memory allocation in three functions

From: Markus Elfring <[email protected]>
Date: Wed, 14 Feb 2018 16:00:33 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/crypto/omap-aes.c  | 5 ++---
 drivers/crypto/omap-des.c  | 5 ++---
 drivers/crypto/omap-sham.c | 1 -
 3 files changed, 4 insertions(+), 7 deletions(-)
drivers/crypto/omap-aes.c +2 -3
index fbec0a2e76dd..a2bac3b869b6 100644
@@ -1040,10 +1040,9 @@ static int omap_aes_probe(struct platform_device *pdev)
 	u32 reg;
 
 	dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL);
-	if (dd = NULL) {
-		dev_err(dev, "unable to alloc data struct.\n");
+	if (!dd)
 		goto err_data;
-	}
+
 	dd->dev = dev;
 	platform_set_drvdata(pdev, dd);
 
drivers/crypto/omap-des.c +2 -3
index ebc5c0f11f03..f4199be783a9 100644
@@ -964,10 +964,9 @@ static int omap_des_probe(struct platform_device *pdev)
 	u32 reg;
 
 	dd = devm_kzalloc(dev, sizeof(struct omap_des_dev), GFP_KERNEL);
-	if (dd = NULL) {
-		dev_err(dev, "unable to alloc data struct.\n");
+	if (!dd)
 		goto err_data;
-	}
+
 	dd->dev = dev;
 	platform_set_drvdata(pdev, dd);
 
drivers/crypto/omap-sham.c +0 -1
index 86b89ace836f..7aa4eb50ebc9 100644
@@ -2024,7 +2024,6 @@ static int omap_sham_probe(struct platform_device *pdev)
 
 	dd = devm_kzalloc(dev, sizeof(struct omap_sham_dev), GFP_KERNEL);
 	if (dd = NULL) {
-		dev_err(dev, "unable to alloc data struct.\n");
 		err = -ENOMEM;
 		goto data_err;
 	}
Signature · 1 line
2.16.1
#2 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 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(-)
drivers/crypto/omap-aes.c +1 -2
index a2bac3b869b6..82282a5e9b3f 100644
@@ -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 = &pdev->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;
 
drivers/crypto/omap-des.c +1 -2
index f4199be783a9..09833709fbed 100644
@@ -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 = &pdev->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;
 
drivers/crypto/omap-sham.c +1 -2
index 7aa4eb50ebc9..ffa3ac3bde55 100644
@@ -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 = &pdev->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;
Signature · 1 line
2.16.1
maintainer
#3 lore raw

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

Quoted 23 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

---
 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(-)
drivers/crypto/omap-aes.c +0 -0
index a2bac3b869b6..82282a5e9b3f 100644
@@ -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)
 {

drivers/crypto/omap-aes.c static int omap_aes_get_res_pdev(struct omap_aes_dev *dd, · line 1042

Quoted 10 lines
drivers/crypto/omap-aes.c +1 -2
 	struct device *dev = &pdev->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) but please don't combine the allocation with the declaration.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw

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

Quoted 12 lines
Quoted 12 lines
drivers/crypto/omap-aes.c +1 -1
@@ -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 = &pdev->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);
 
Quoted 3 lines

drivers/crypto/omap-aes.c static int omap_aes_get_res_pdev(struct omap_aes_dev *dd, · line 1042

Quoted 1 line
drivers/crypto/omap-aes.c +0 -1
-	dd = devm_kzalloc(dev, sizeof(struct omap_aes_dev), GFP_KERNEL);

I'm fine with sizeof(*dd)

Thanks for your feedback.

Quoted 1 line

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

Why do you not like such an implementation detail?

Regards,
Markus