diff mbox series

mm/list_lru: Remove redundant NULL check before kfree()

Message ID 20250228141856.730825-1-eleanor15x@gmail.com (mailing list archive)
State New
Headers show
Series mm/list_lru: Remove redundant NULL check before kfree() | expand

Commit Message

Yu-Chun Lin Feb. 28, 2025, 2:18 p.m. UTC
The kernel's kfree() documentation states: "If @object is NULL, no
operation is performed." Remove checking for NULL before calling kfree().

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202502250720.9ueIb7Xh-lkp@intel.com/
Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>
---
 mm/list_lru.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vlastimil Babka Feb. 28, 2025, 4:39 p.m. UTC | #1
On 2/28/25 15:18, Yu-Chun Lin wrote:
> The kernel's kfree() documentation states: "If @object is NULL, no
> operation is performed." Remove checking for NULL before calling kfree().
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202502250720.9ueIb7Xh-lkp@intel.com/
> Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>

This is already in mm-unstable:
https://lore.kernel.org/all/20250227082223.1173847-1-jingxiangzeng.cas@gmail.com/

> ---
>  mm/list_lru.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/list_lru.c b/mm/list_lru.c
> index 7d69434c70e0..7c8fb17d9027 100644
> --- a/mm/list_lru.c
> +++ b/mm/list_lru.c
> @@ -548,8 +548,7 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
>  			}
>  			xas_unlock_irqrestore(&xas, flags);
>  		} while (xas_nomem(&xas, gfp));
> -		if (mlru)
> -			kfree(mlru);
> +		kfree(mlru);
>  	} while (pos != memcg && !css_is_dying(&pos->css));
>  
>  	return xas_error(&xas);
diff mbox series

Patch

diff --git a/mm/list_lru.c b/mm/list_lru.c
index 7d69434c70e0..7c8fb17d9027 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -548,8 +548,7 @@  int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
 			}
 			xas_unlock_irqrestore(&xas, flags);
 		} while (xas_nomem(&xas, gfp));
-		if (mlru)
-			kfree(mlru);
+		kfree(mlru);
 	} while (pos != memcg && !css_is_dying(&pos->css));
 
 	return xas_error(&xas);