linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: NULL check before kfree is not needed
@ 2018-08-03  6:39 YueHaibing
  2018-08-04 16:05 ` Anton Ivanov
  0 siblings, 1 reply; 2+ messages in thread
From: YueHaibing @ 2018-08-03  6:39 UTC (permalink / raw)
  To: jdike, richard, anton.ivanov, christophe.jaillet, keescook
  Cc: linux-kernel, linux-um, YueHaibing

kfree(NULL) is safe,so this removes NULL check before freeing the mem

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 arch/um/drivers/vector_kern.c | 15 +++++----------
 arch/um/drivers/vector_user.c |  6 ++----
 arch/um/kernel/irq.c          |  3 +--
 3 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 50ee3bb..c84133c 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -1118,16 +1118,11 @@ static int vector_net_close(struct net_device *dev)
 		os_close_file(vp->fds->tx_fd);
 		vp->fds->tx_fd = -1;
 	}
-	if (vp->bpf != NULL)
-		kfree(vp->bpf);
-	if (vp->fds->remote_addr != NULL)
-		kfree(vp->fds->remote_addr);
-	if (vp->transport_data != NULL)
-		kfree(vp->transport_data);
-	if (vp->header_rxbuffer != NULL)
-		kfree(vp->header_rxbuffer);
-	if (vp->header_txbuffer != NULL)
-		kfree(vp->header_txbuffer);
+	kfree(vp->bpf);
+	kfree(vp->fds->remote_addr);
+	kfree(vp->transport_data);
+	kfree(vp->header_rxbuffer);
+	kfree(vp->header_txbuffer);
 	if (vp->rx_queue != NULL)
 		destroy_queue(vp->rx_queue);
 	if (vp->tx_queue != NULL)
diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
index 4d6a78e..3d8cdbd 100644
--- a/arch/um/drivers/vector_user.c
+++ b/arch/um/drivers/vector_user.c
@@ -267,8 +267,7 @@ static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
 		os_close_file(rxfd);
 	if (txfd >= 0)
 		os_close_file(txfd);
-	if (result != NULL)
-		kfree(result);
+	kfree(result);
 	return NULL;
 }
 
@@ -434,8 +433,7 @@ static struct vector_fds *user_init_socket_fds(struct arglist *ifspec, int id)
 	if (fd >= 0)
 		os_close_file(fd);
 	if (result != NULL) {
-		if (result->remote_addr != NULL)
-			kfree(result->remote_addr);
+		kfree(result->remote_addr);
 		kfree(result);
 	}
 	return NULL;
diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
index 6b7f382..8360fa3 100644
--- a/arch/um/kernel/irq.c
+++ b/arch/um/kernel/irq.c
@@ -244,8 +244,7 @@ static void garbage_collect_irq_entries(void)
 			to_free = NULL;
 		}
 		walk = walk->next;
-		if (to_free != NULL)
-			kfree(to_free);
+		kfree(to_free);
 	}
 }
 
-- 
2.7.0



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

* Re: [PATCH] um: NULL check before kfree is not needed
  2018-08-03  6:39 [PATCH] um: NULL check before kfree is not needed YueHaibing
@ 2018-08-04 16:05 ` Anton Ivanov
  0 siblings, 0 replies; 2+ messages in thread
From: Anton Ivanov @ 2018-08-04 16:05 UTC (permalink / raw)
  To: YueHaibing, jdike, richard, christophe.jaillet, keescook
  Cc: linux-um, linux-kernel

On 03/08/18 07:39, YueHaibing wrote:

> kfree(NULL) is safe,so this removes NULL check before freeing the mem
>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>   arch/um/drivers/vector_kern.c | 15 +++++----------
>   arch/um/drivers/vector_user.c |  6 ++----
>   arch/um/kernel/irq.c          |  3 +--
>   3 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
> index 50ee3bb..c84133c 100644
> --- a/arch/um/drivers/vector_kern.c
> +++ b/arch/um/drivers/vector_kern.c
> @@ -1118,16 +1118,11 @@ static int vector_net_close(struct net_device *dev)
>   		os_close_file(vp->fds->tx_fd);
>   		vp->fds->tx_fd = -1;
>   	}
> -	if (vp->bpf != NULL)
> -		kfree(vp->bpf);
> -	if (vp->fds->remote_addr != NULL)
> -		kfree(vp->fds->remote_addr);
> -	if (vp->transport_data != NULL)
> -		kfree(vp->transport_data);
> -	if (vp->header_rxbuffer != NULL)
> -		kfree(vp->header_rxbuffer);
> -	if (vp->header_txbuffer != NULL)
> -		kfree(vp->header_txbuffer);
> +	kfree(vp->bpf);
> +	kfree(vp->fds->remote_addr);
> +	kfree(vp->transport_data);
> +	kfree(vp->header_rxbuffer);
> +	kfree(vp->header_txbuffer);
>   	if (vp->rx_queue != NULL)
>   		destroy_queue(vp->rx_queue);
>   	if (vp->tx_queue != NULL)
> diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
> index 4d6a78e..3d8cdbd 100644
> --- a/arch/um/drivers/vector_user.c
> +++ b/arch/um/drivers/vector_user.c
> @@ -267,8 +267,7 @@ static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
>   		os_close_file(rxfd);
>   	if (txfd >= 0)
>   		os_close_file(txfd);
> -	if (result != NULL)
> -		kfree(result);
> +	kfree(result);
>   	return NULL;
>   }
>   
> @@ -434,8 +433,7 @@ static struct vector_fds *user_init_socket_fds(struct arglist *ifspec, int id)
>   	if (fd >= 0)
>   		os_close_file(fd);
>   	if (result != NULL) {
> -		if (result->remote_addr != NULL)
> -			kfree(result->remote_addr);
> +		kfree(result->remote_addr);
>   		kfree(result);
>   	}
>   	return NULL;
> diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
> index 6b7f382..8360fa3 100644
> --- a/arch/um/kernel/irq.c
> +++ b/arch/um/kernel/irq.c
> @@ -244,8 +244,7 @@ static void garbage_collect_irq_entries(void)
>   			to_free = NULL;
>   		}
>   		walk = walk->next;
> -		if (to_free != NULL)
> -			kfree(to_free);
> +		kfree(to_free);
>   	}
>   }
>   
kfree in both slab and slob check for NULLs before freeing so this is 
correct. Thanks for noticing.

Richard, please apply,

A.

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

end of thread, other threads:[~2018-08-04 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-03  6:39 [PATCH] um: NULL check before kfree is not needed YueHaibing
2018-08-04 16:05 ` Anton Ivanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).