diff mbox

crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

Message ID 5589CD95.9080508@users.sourceforge.net (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

SF Markus Elfring June 23, 2015, 9:20 p.m. UTC
From: Markus Elfring <elfring@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 <elfring@users.sourceforge.net>
---
 crypto/jitterentropy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Stephan Mueller June 23, 2015, 9:44 p.m. UTC | #1
Am Dienstag, 23. Juni 2015, 23:20:21 schrieb SF Markus Elfring:

Hi Markus,

> From: Markus Elfring <elfring@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.

Ack: the patch is correct and I was overzealous.

Nack: I just proposed a patch earlier today to avoid compiler warnings [1]. 
That patch clashes with yours. May I ask you to wait briefly to see whether 
that patch will be accepted? If yes, it would be great if you could repost the 
patch that applies to the changed code.

PS: when you are at it, maybe even the last line in the function can be 
removed: setting the entropy_collector to NULL at that the end of the function 
is moot as well.

Thanks.

[1] http://lkml.iu.edu/hypermail/linux/kernel/1506.2/05196.html
> 
> Signed-off-by: Markus Elfring <elfring@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;
>  }
Dan Carpenter June 24, 2015, 7:48 a.m. UTC | #2
The other NULL assignment isn't useful either.  Also If
"entropy_collector" is NULL then we would oops calling
kzfree(entropy_collector->mem);
       ^^^^^^^^^^^^^^^^^^^^^^
Dereference.

I don't understand the patch that you sent.  We shouldn't be introducing
jent_zalloc() or jent_zfree().  Why are you adding abstractions there?
Quite bad ones as well.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stephan Mueller June 24, 2015, 7:54 a.m. UTC | #3
Am Mittwoch, 24. Juni 2015, 10:48:19 schrieb Dan Carpenter:

Hi Dan,

>The other NULL assignment isn't useful either.  Also If
>"entropy_collector" is NULL then we would oops calling
>kzfree(entropy_collector->mem);
>       ^^^^^^^^^^^^^^^^^^^^^^
>Dereference.
>
>I don't understand the patch that you sent.  We shouldn't be introducing
>jent_zalloc() or jent_zfree().  Why are you adding abstractions there?

The one C file should have no dependencies on any kernel header files. Thus, 
all links to kernel functions are wrapped.

>Quite bad ones as well.

What would you suggest to change?

Thanks.

Ciao
Stephan
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dan Carpenter June 24, 2015, 9:19 a.m. UTC | #4
Ah.  I should have read the whole thread.  I sort of assumed we were
just adding abstractions for the fun of it (because I have worked in
staging for too long).

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Herbert Xu June 25, 2015, 3:37 p.m. UTC | #5
On Tue, Jun 23, 2015 at 11:20:21PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@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 <elfring@users.sourceforge.net>

Applied.
diff mbox

Patch

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;
 }