Skip to contentSkip to conversation

xen: simplify balloon_first_page() with list_first_entry_or_null()

PATCH Superseded Jeff Liu 2 participants 3 messages Nov 13, 2013 Xen hypervisor interface

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 1/1 xen: simplify balloon_first_page() with list_first_entry_or_null()

From: Jie Liu <[email protected]>

Simplify the code logic of balloon_first_page() by replacing the combination of list_empty() and list_first_entry() with list_first_entry_or_null(). As a net win, we can change this routine to inline as now it's one line.

---
 drivers/xen/balloon.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/xen/balloon.c +3 -4
index b232908..0e4ca20 100644
@@ -157,11 +157,10 @@ static struct page *balloon_retrieve(bool prefer_highmem)
 	return page;
 }
 
-static struct page *balloon_first_page(void)
+static inline struct page *balloon_first_page(void)
 {
-	if (list_empty(&ballooned_pages))
-		return NULL;
-	return list_entry(ballooned_pages.next, struct page, lru);
+	return list_first_entry_or_null(&ballooned_pages,
+					struct page, lru);
 }
 
 static struct page *balloon_next_page(struct page *page)
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 20 lines · Jeff Liu

From: Jie Liu <[email protected]>

Simplify the code logic of balloon_first_page() by replacing the combination of list_empty() and list_first_entry() with list_first_entry_or_null(). As a net win, we can change this routine to inline as now it's one line.

---
 drivers/xen/balloon.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/xen/balloon.c +0 -0
index b232908..0e4ca20 100644
@@ -157,11 +157,10 @@ static struct page *balloon_retrieve(bool prefer_highmem)
 	return page;
 }

drivers/xen/balloon.c static struct page *balloon_retrieve(bool prefer_highmem) · line 164

Quoted 10 lines
drivers/xen/balloon.c +3 -4
 
-static struct page *balloon_first_page(void)
+static inline struct page *balloon_first_page(void)
 {
-	if (list_empty(&ballooned_pages))
-		return NULL;
-	return list_entry(ballooned_pages.next, struct page, lru);
+	return list_first_entry_or_null(&ballooned_pages,
+					struct page, lru);
 }

There's only one user of balloon_first_page(), can you remove balloon_first_page() and just use list_first_entry_or_null()?

David

author
#2 lore raw
Quoted 22 lines · David Vrabel
Quoted 21 lines · Jeff Liu

From: Jie Liu <[email protected]>

Simplify the code logic of balloon_first_page() by replacing the combination of list_empty() and list_first_entry() with list_first_entry_or_null(). As a net win, we can change this routine to inline as now it's one line.

---
 drivers/xen/balloon.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/xen/balloon.c +0 -0
index b232908..0e4ca20 100644
@@ -157,11 +157,10 @@ static struct page *balloon_retrieve(bool prefer_highmem)
 	return page;
 }
 
Quoted 12 lines

drivers/xen/balloon.c static struct page *balloon_retrieve(bool prefer_highmem) · line 164

Quoted 9 lines
drivers/xen/balloon.c +3 -4
-static struct page *balloon_first_page(void)
+static inline struct page *balloon_first_page(void)
 {
-	if (list_empty(&ballooned_pages))
-		return NULL;
-	return list_entry(ballooned_pages.next, struct page, lru);
+	return list_first_entry_or_null(&ballooned_pages,
+					struct page, lru);
 }

There's only one user of balloon_first_page(), can you remove balloon_first_page() and just use list_first_entry_or_null()?

Sure, will post the revised version a little while.

Thanks,
-Jeff