Skip to contentSkip to conversation

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

PATCH In review Yu-Chun Lin 2 participants 2 messages Feb 28, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

The kernel's kfree() documentation states: "If @object is NULL, no operation is performed." Remove checking for NULL before calling kfree().

---
 mm/list_lru.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/list_lru.c +1 -2
index 7d69434c70e0..7c8fb17d9027 100644
@@ -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);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · Yu-Chun Lin

The kernel's kfree() documentation states: "If @object is NULL, no operation is performed." Remove checking for NULL before calling kfree().

This is already in mm-unstable:
https://lore.kernel.org/all/[email protected]/

Quoted 18 lines
---
 mm/list_lru.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/list_lru.c +1 -2
index 7d69434c70e0..7c8fb17d9027 100644
@@ -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);