[PATCH] driver: hwmon: remove NULL check before kvfree

Dongliang Mu posted 1 patch 3 years, 10 months ago
drivers/hwmon/occ/p9_sbe.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH] driver: hwmon: remove NULL check before kvfree
Posted by Dongliang Mu 3 years, 10 months ago
From: mudongliang <mudongliangabcd@gmail.com>

kvfree can handle NULL pointer as its argument.
According to coccinelle isnullfree check, remove NULL check
before kvfree operation.

Signed-off-by: mudongliang <mudongliangabcd@gmail.com>
---
 drivers/hwmon/occ/p9_sbe.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c
index 42fc7b97bb34..01405ae2f9bd 100644
--- a/drivers/hwmon/occ/p9_sbe.c
+++ b/drivers/hwmon/occ/p9_sbe.c
@@ -55,8 +55,7 @@ static bool p9_sbe_occ_save_ffdc(struct p9_sbe_occ *ctx, const void *resp,
 	mutex_lock(&ctx->sbe_error_lock);
 	if (!ctx->sbe_error) {
 		if (resp_len > ctx->ffdc_size) {
-			if (ctx->ffdc)
-				kvfree(ctx->ffdc);
+			kvfree(ctx->ffdc);
 			ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL);
 			if (!ctx->ffdc) {
 				ctx->ffdc_len = 0;
@@ -171,8 +170,7 @@ static int p9_sbe_occ_remove(struct platform_device *pdev)
 	ctx->sbe = NULL;
 	occ_shutdown(occ);
 
-	if (ctx->ffdc)
-		kvfree(ctx->ffdc);
+	kvfree(ctx->ffdc);
 
 	return 0;
 }
-- 
2.35.1
Re: [PATCH] driver: hwmon: remove NULL check before kvfree
Posted by Guenter Roeck 3 years, 10 months ago
On 6/14/22 01:56, Dongliang Mu wrote:
> From: mudongliang <mudongliangabcd@gmail.com>
> 
> kvfree can handle NULL pointer as its argument.
> According to coccinelle isnullfree check, remove NULL check
> before kvfree operation.
> 

Please add driver information to your subject lines, and drop
"driver:". It should be

  [PATCH] hwmon: (occ) remove NULL check before kvfree

> Signed-off-by: mudongliang <mudongliangabcd@gmail.com>

Please provide your full name here. This should be

Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Thanks,
Guenter

> ---
>   drivers/hwmon/occ/p9_sbe.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c
> index 42fc7b97bb34..01405ae2f9bd 100644
> --- a/drivers/hwmon/occ/p9_sbe.c
> +++ b/drivers/hwmon/occ/p9_sbe.c
> @@ -55,8 +55,7 @@ static bool p9_sbe_occ_save_ffdc(struct p9_sbe_occ *ctx, const void *resp,
>   	mutex_lock(&ctx->sbe_error_lock);
>   	if (!ctx->sbe_error) {
>   		if (resp_len > ctx->ffdc_size) {
> -			if (ctx->ffdc)
> -				kvfree(ctx->ffdc);
> +			kvfree(ctx->ffdc);
>   			ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL);
>   			if (!ctx->ffdc) {
>   				ctx->ffdc_len = 0;
> @@ -171,8 +170,7 @@ static int p9_sbe_occ_remove(struct platform_device *pdev)
>   	ctx->sbe = NULL;
>   	occ_shutdown(occ);
>   
> -	if (ctx->ffdc)
> -		kvfree(ctx->ffdc);
> +	kvfree(ctx->ffdc);
>   
>   	return 0;
>   }