mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (occ) Delete unnecessary NULL check
@ 2022-06-06 13:14 Ziyang Xuan
  2022-06-06 13:33 ` Eddie James
  0 siblings, 1 reply; 3+ messages in thread
From: Ziyang Xuan @ 2022-06-06 13:14 UTC (permalink / raw)
  To: jdelvare, linux, eajames, joel, penberg, akpm, linux-hwmon, linux-kernel
  Cc: william.xuanziyang

kvfree(NULL) is safe. NULL check before kvfree() is not needed.
Delete them to simplify the code.

Generated by coccinelle script:
	scripts/coccinelle/free/ifnullfree.cocci

Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.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.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (occ) Delete unnecessary NULL check
@ 2022-06-06 14:19 Guenter Roeck
  0 siblings, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2022-06-06 14:19 UTC (permalink / raw)
  To: Ziyang Xuan
  Cc: jdelvare, eajames, joel, penberg, akpm, linux-hwmon, linux-kernel

On Mon, Jun 06, 2022 at 09:14:01PM +0800, Ziyang Xuan wrote:
> kvfree(NULL) is safe. NULL check before kvfree() is not needed.
> Delete them to simplify the code.
> 
> Generated by coccinelle script:
> 	scripts/coccinelle/free/ifnullfree.cocci
> 
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>

Applied to hwmon-next.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-06 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 13:14 [PATCH] hwmon: (occ) Delete unnecessary NULL check Ziyang Xuan
2022-06-06 13:33 ` Eddie James
2022-06-06 14:19 Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®