Skip to contentSkip to conversation

crypto/bcm: Adjustments for do_shash()

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

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

cover crypto/bcm: Adjustments for do_shash()

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

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

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

---
 drivers/crypto/bcm/util.c | 1 -
 1 file changed, 1 deletion(-)
drivers/crypto/bcm/util.c +0 -1
index d543c010ccd9..a912c6ad3e85 100644
@@ -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;
Signature · 1 line
2.16.1
#3 lore raw

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

In reply to SF Markus Elfring

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

---
 drivers/crypto/bcm/util.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/crypto/bcm/util.c +3 -3
index a912c6ad3e85..c141a0242223 100644
@@ -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;
 }
 
Signature · 1 line
2.16.1
maintainer
#4 lore raw

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

Quoted 9 lines · SF Markus Elfring

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

This patch is pointless as kfree on NULL is a no-op.

Cheers,

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
maintainer
#2 lore raw

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

In reply to SF Markus Elfring
Quoted 8 lines · SF Markus Elfring

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

Patch applied. 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
#5 lore raw

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

In reply to Herbert Xu
Quoted 1 line

This patch is pointless as kfree on NULL is a no-op.

I prefer to avoid unnecessary function calls generally.

Regards,
Markus