linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition
@ 2026-01-16 19:27 Joshua Hahn
  2026-01-16 19:27 ` [PATCH v2 2/2] mm/hugetlb: Enforce brace style Joshua Hahn
  2026-01-17 10:25 ` [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Joshua Hahn @ 2026-01-16 19:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Muchun Song, Oscar Salvador, linux-kernel,
	linux-mm, kernel-team

if (map_chg) is always true, since it is nested in another if statement
which checks for map_chg == MAP_CHG_NEEDED, which is equal to 1.

if (unlikely(map_chg == MAP_CHG_NEEDED && retval == 0)) {
	...

	if (map_chg) {
		...
	}
}

Remove the check, un-indent, and collapse the function call for
readability.

No functional change intended.

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
---
v1 --> v2:
- Collapse the "folio" argument into the line above, as suggested by Andrew
  and SeongJae.
- Explicitly note that MAP_CHG_NEEDED == 1, as suggested by David.
- Collect signatures.

 mm/hugetlb.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5a147026633f..2e5592c5cbb2 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3028,13 +3028,10 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,
 
 			rsv_adjust = hugepage_subpool_put_pages(spool, 1);
 			hugetlb_acct_memory(h, -rsv_adjust);
-			if (map_chg) {
-				spin_lock_irq(&hugetlb_lock);
-				hugetlb_cgroup_uncharge_folio_rsvd(
-				    hstate_index(h), pages_per_huge_page(h),
-				    folio);
-				spin_unlock_irq(&hugetlb_lock);
-			}
+			spin_lock_irq(&hugetlb_lock);
+			hugetlb_cgroup_uncharge_folio_rsvd(
+			    hstate_index(h), pages_per_huge_page(h), folio);
+			spin_unlock_irq(&hugetlb_lock);
 		}
 	}
 
-- 
2.47.3


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

* [PATCH v2 2/2] mm/hugetlb: Enforce brace style
  2026-01-16 19:27 [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Joshua Hahn
@ 2026-01-16 19:27 ` Joshua Hahn
  2026-01-17 10:25 ` [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Joshua Hahn @ 2026-01-16 19:27 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Muchun Song, Oscar Salvador, linux-kernel,
	linux-mm, kernel-team

Documentation/process/coding-style.rst explicitly notes that if only one
branch of a conditional statement is a single statement, braces should
be used in both branches. Enforce this in mm/hugetlb.c.

While add it, fix the indentation for vma_end_reservation.

No functional change intended.

Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
---
v1 --> v2:
- Remove accidental newline, noted by Andrew and David.
- Fix vma_end_reservation's indentation while at it, as suggested by
  SeongJae.

 mm/hugetlb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2e5592c5cbb2..120ebd448b42 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -578,8 +578,9 @@ hugetlb_resv_map_add(struct resv_map *map, struct list_head *rg, long from,
 		record_hugetlb_cgroup_uncharge_info(cg, h, map, nrg);
 		list_add(&nrg->link, rg);
 		coalesce_file_region(map, nrg);
-	} else
+	} else {
 		*regions_needed += 1;
+	}
 
 	return to - from;
 }
@@ -1247,8 +1248,9 @@ void hugetlb_dup_vma_private(struct vm_area_struct *vma)
 
 		if (vma_lock && vma_lock->vma != vma)
 			vma->vm_private_data = NULL;
-	} else
+	} else {
 		vma->vm_private_data = NULL;
+	}
 }
 
 /*
@@ -2076,8 +2078,9 @@ int dissolve_free_hugetlb_folio(struct folio *folio)
 				h->max_huge_pages++;
 				goto out;
 			}
-		} else
+		} else {
 			rc = 0;
+		}
 
 		update_and_free_hugetlb_folio(h, folio, false);
 		return rc;
@@ -2672,11 +2675,12 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma,
 				 * be consumed on a subsequent allocation.
 				 */
 				folio_set_hugetlb_restore_reserve(folio);
-		} else
+		} else {
 			/*
 			 * No reservation present, do nothing
 			 */
-			 vma_end_reservation(h, vma, address);
+			vma_end_reservation(h, vma, address);
+		}
 	}
 }
 
@@ -4711,10 +4715,12 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
 			if (vma_lock->vma != vma) {
 				vma->vm_private_data = NULL;
 				hugetlb_vma_lock_alloc(vma);
-			} else
+			} else {
 				pr_warn("HugeTLB: vma_lock already exists in %s.\n", __func__);
-		} else
+			}
+		} else {
 			hugetlb_vma_lock_alloc(vma);
+		}
 	}
 }
 
-- 
2.47.3


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

* Re: [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition
  2026-01-16 19:27 [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Joshua Hahn
  2026-01-16 19:27 ` [PATCH v2 2/2] mm/hugetlb: Enforce brace style Joshua Hahn
@ 2026-01-17 10:25 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-01-17 10:25 UTC (permalink / raw)
  To: Joshua Hahn, linux-mm, Andrew Morton
  Cc: kernel-team, LKML, David Hildenbrand, Muchun Song, Oscar Salvador

…
> Remove the check, un-indent, and collapse the function call for
> readability.
…

Would a cover letter be helpful also for such a small patch series?

Regards,
Markus


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

end of thread, other threads:[~2026-01-17 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-16 19:27 [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Joshua Hahn
2026-01-16 19:27 ` [PATCH v2 2/2] mm/hugetlb: Enforce brace style Joshua Hahn
2026-01-17 10:25 ` [PATCH v2 1/2] mm/hugetlb: Remove unnecessary if condition Markus Elfring

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