public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* BUG_ON(x) instead of if (x) BUG() in mm/page_alloc,swap_state.c
@ 2002-07-01 12:31 Lightweight patch manager
  2002-07-01 17:40 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Lightweight patch manager @ 2002-07-01 12:31 UTC (permalink / raw)
  To: andrea; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4989 bytes --]

This replaces if(x) BUG() with BUG_ON(x) where necessarry, at least in mm/page_alloc.c and mm/swap_state.c

This patch is also available from http://luckynet.dynu.com/~thunder/patches/mm_pages-use-BUG_ON.patch

Index: mm/page_alloc.c
===================================================================
RCS file: /var/cvs/thunder-2.5/mm/page_alloc.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 page_alloc.c
--- mm/page_alloc.c	20 Jun 2002 22:53:44 -0000	1.1.1.1
+++ mm/page_alloc.c	1 Jul 2002 12:09:32 -0000
@@ -86,18 +86,12 @@
 	struct page *base;
 	zone_t *zone;
 
-	if (PagePrivate(page))
-		BUG();
-	if (page->mapping)
-		BUG();
-	if (PageLocked(page))
-		BUG();
-	if (PageLRU(page))
-		BUG();
-	if (PageActive(page))
-		BUG();
-	if (PageWriteback(page))
-		BUG();
+	BUG_ON(PagePrivate(page));
+	BUG_ON(page->mapping);
+	BUG_ON(PageLocked(page));
+	BUG_ON(PageLRU(page));
+	BUG_ON(PageActive(page));
+	BUG_ON(PageWriteback(page));
 	ClearPageDirty(page);
 	page->flags &= ~(1<<PG_referenced);
 
@@ -110,8 +104,7 @@
 	mask = (~0UL) << order;
 	base = zone->zone_mem_map;
 	page_idx = page - base;
-	if (page_idx & ~mask)
-		BUG();
+	BUG_ON(page_idx & ~mask);
 	index = page_idx >> (1 + order);
 
 	area = zone->free_area + order;
@@ -123,8 +116,8 @@
 	while (mask + (1 << (MAX_ORDER-1))) {
 		struct page *buddy1, *buddy2;
 
-		if (area >= zone->free_area + MAX_ORDER)
-			BUG();
+		BUG_ON(area >= zone->free_area + MAX_ORDER);
+
 		if (!__test_and_change_bit(index, area->map))
 			/*
 			 * the buddy page is still allocated.
@@ -137,10 +130,8 @@
 		 */
 		buddy1 = base + (page_idx ^ -mask);
 		buddy2 = base + page_idx;
-		if (bad_range(zone, buddy1))
-			BUG();
-		if (bad_range(zone, buddy2))
-			BUG();
+		BUG_ON(bad_range(zone, buddy1));
+		BUG_ON(bad_range(zone, buddy2));
 
 		list_del(&buddy1->list);
 		mask <<= 1;
@@ -173,8 +164,7 @@
 	unsigned long size = 1 << high;
 
 	while (high > low) {
-		if (bad_range(zone, page))
-			BUG();
+		BUG_ON(bad_range(zone, page));
 		area--;
 		high--;
 		size >>= 1;
@@ -183,8 +173,7 @@
 		index += size;
 		page += size;
 	}
-	if (bad_range(zone, page))
-		BUG();
+	BUG_ON(bad_range(zone, page));
 	return page;
 }
 
@@ -206,8 +195,7 @@
 			unsigned int index;
 
 			page = list_entry(curr, struct page, list);
-			if (bad_range(zone, page))
-				BUG();
+			BUG_ON(bad_range(zone, page));
 			list_del(curr);
 			index = page - zone->zone_mem_map;
 			if (curr_order != MAX_ORDER-1)
@@ -218,12 +206,9 @@
 			spin_unlock_irqrestore(&zone->lock, flags);
 
 			set_page_count(page, 1);
-			if (bad_range(zone, page))
-				BUG();
-			if (PageLRU(page))
-				BUG();
-			if (PageActive(page))
-				BUG();
+			BUG_ON(bad_range(zone, page));
+			BUG_ON(PageLRU(page));
+			BUG_ON(PageActive(page));
 			return page;	
 		}
 		curr_order++;
@@ -274,8 +259,7 @@
 
 	if (!(gfp_mask & __GFP_WAIT))
 		goto out;
-	if (in_interrupt())
-		BUG();
+	BUG_ON(in_interrupt());
 
 	current->allocation_order = order;
 	current->flags |= PF_MEMALLOC | PF_FREE_PAGES;
@@ -302,20 +286,13 @@
 					set_page_count(tmp, 1);
 					page = tmp;
 
-					if (PagePrivate(page))
-						BUG();
-					if (page->mapping)
-						BUG();
-					if (PageLocked(page))
-						BUG();
-					if (PageLRU(page))
-						BUG();
-					if (PageActive(page))
-						BUG();
-					if (PageDirty(page))
-						BUG();
-					if (PageWriteback(page))
-						BUG();
+					BUG_ON(PagePrivate(page));
+					BUG_ON(page->mapping)
+					BUG_ON(PageLocked(page))
+					BUG_ON(PageLRU(page))
+					BUG_ON(PageActive(page))
+					BUG_ON(PageDirty(page))
+					BUG_ON(PageWriteback(page))
 
 					break;
 				}
@@ -328,8 +305,7 @@
 			list_del(entry);
 			tmp = list_entry(entry, struct page, list);
 			__free_pages_ok(tmp, tmp->index);
-			if (!nr_pages--)
-				BUG();
+			BUG_ON(!nr_pages--)
 		}
 		current->nr_local_pages = 0;
 	}
@@ -800,8 +776,7 @@
 	unsigned long totalpages, offset, realtotalpages;
 	const unsigned long zone_required_alignment = 1UL << (MAX_ORDER-1);
 
-	if (zone_start_paddr & ~PAGE_MASK)
-		BUG();
+	BUG_ON(zone_start_paddr & ~PAGE_MASK);
 
 	totalpages = 0;
 	for (i = 0; i < MAX_NR_ZONES; i++) {
Index: mm/swap_state.c
===================================================================
RCS file: /var/cvs/thunder-2.5/mm/swap_state.c,v
retrieving revision 1.2
diff -u -r1.2 swap_state.c
--- mm/swap_state.c	22 Jun 2002 11:09:20 -0000	1.2
+++ mm/swap_state.c	1 Jul 2002 12:10:46 -0000
@@ -76,8 +76,7 @@
 {
 	int error;
 
-	if (page->mapping)
-		BUG();
+	BUG_ON(page->mapping);
 	if (!swap_duplicate(entry)) {
 		INC_CACHE_INFO(noent_race);
 		return -ENOENT;
@@ -90,10 +89,8 @@
 			INC_CACHE_INFO(exist_race);
 		return error;
 	}
-	if (!PageLocked(page))
-		BUG();
-	if (!PageSwapCache(page))
-		BUG();
+	BUG_ON(!PageLocked(page));
+	BUG_ON(!PageSwapCache(page));
 	INC_CACHE_INFO(add_total);
 	return 0;
 }
@@ -142,8 +139,7 @@
 	void **pslot;
 	int err;
 
-	if (!mapping)
-		BUG();
+	BUG_ON(!mapping);
 
 	if (!swap_duplicate(entry)) {
 		INC_CACHE_INFO(noent_race);

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

* Re: BUG_ON(x) instead of if (x) BUG() in mm/page_alloc,swap_state.c
  2002-07-01 12:31 BUG_ON(x) instead of if (x) BUG() in mm/page_alloc,swap_state.c Lightweight patch manager
@ 2002-07-01 17:40 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2002-07-01 17:40 UTC (permalink / raw)
  To: Lightweight patch manager; +Cc: andrea, linux-kernel

Lightweight patch manager wrote:
> 
> This replaces if(x) BUG() with BUG_ON(x) where necessarry, at least in
> mm/page_alloc.c and mm/swap_state.c

Thanks - I'll add to my pile.

> ...
> -                       if (!nr_pages--)
> -                               BUG();
> +                       BUG_ON(!nr_pages--)

Except for this chunk.  It's best to avoid putting statements
with side-effects inside BUG_ON().  If someone wants to build
a super-small kernel with a no-op BUG_ON() then code such as the
above will cause it to fail.

It'll probably fail anyway, but hey - may as well try.

-

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

end of thread, other threads:[~2002-07-01 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-01 12:31 BUG_ON(x) instead of if (x) BUG() in mm/page_alloc,swap_state.c Lightweight patch manager
2002-07-01 17:40 ` Andrew Morton

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