mm.h: fix BUG_ON() condition in put_page_alloc_ref()
diff mbox series

Message ID 20190716110550.19086-1-paul.durrant@citrix.com
State New
Headers show
Series
  • mm.h: fix BUG_ON() condition in put_page_alloc_ref()
Related show

Commit Message

Paul Durrant July 16, 2019, 11:05 a.m. UTC
The BUG_ON() was misplaced when this function was introduced in commit
ec83f825 "mm.h: add helper function to test-and-clear _PGC_allocated".
It will fire incorrectly if _PGC_allocated is already clear on entry. Thus
it should be moved after the if statement.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wl@xen.org>
---
 xen/include/xen/mm.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jan Beulich July 16, 2019, 11:27 a.m. UTC | #1
On 16.07.2019 13:05, Paul Durrant wrote:
> The BUG_ON() was misplaced when this function was introduced in commit
> ec83f825 "mm.h: add helper function to test-and-clear _PGC_allocated".
> It will fire incorrectly if _PGC_allocated is already clear on entry. Thus
> it should be moved after the if statement.
> 
> Signed-off-by: Paul Durrant <paul.durrant@citrix.com>

And indeed I should have noticed during review. Thanks.

Reviewed-by: Jan Beulich <jbeulich@suse.com>
and in it goes.

Jan

Patch
diff mbox series

diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 5d0c19f011..cfea38f801 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -667,9 +667,11 @@  static inline void put_page_alloc_ref(struct page_info *page)
      * the caller holding an additional reference. I.e. the allocation
      * reference must never be the last reference held.
      */
-    BUG_ON((page->count_info & PGC_count_mask) <= 1);
     if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
+    {
+        BUG_ON((page->count_info & PGC_count_mask) <= 1);
         put_page(page);
+    }
 }
 
 #endif /* __XEN_MM_H__ */