mm/vmalloc.c: switch to WARN_ON() and move it under unlink_va()
authorUladzislau Rezki (Sony) <urezki@gmail.com>
Fri, 12 Jul 2019 03:59:03 +0000 (20:59 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 12 Jul 2019 18:05:46 +0000 (11:05 -0700)
Trigger a warning if an object that is about to be freed is detached.  We
used to have a BUG_ON(), but even though it is considered as faulty
behaviour that is not a good reason to break a system.

Link: http://lkml.kernel.org/r/20190606120411.8298-5-urezki@gmail.com
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/vmalloc.c

index 857dd8415a2e0a06e0d2dd2bf58d376cef4e7da1..84f50d7e40bcf9c27dd0cac749a769cf050e92ba 100644 (file)
@@ -534,20 +534,17 @@ link_va(struct vmap_area *va, struct rb_root *root,
 static __always_inline void
 unlink_va(struct vmap_area *va, struct rb_root *root)
 {
-       /*
-        * During merging a VA node can be empty, therefore
-        * not linked with the tree nor list. Just check it.
-        */
-       if (!RB_EMPTY_NODE(&va->rb_node)) {
-               if (root == &free_vmap_area_root)
-                       rb_erase_augmented(&va->rb_node,
-                               root, &free_vmap_area_rb_augment_cb);
-               else
-                       rb_erase(&va->rb_node, root);
+       if (WARN_ON(RB_EMPTY_NODE(&va->rb_node)))
+               return;
 
-               list_del(&va->list);
-               RB_CLEAR_NODE(&va->rb_node);
-       }
+       if (root == &free_vmap_area_root)
+               rb_erase_augmented(&va->rb_node,
+                       root, &free_vmap_area_rb_augment_cb);
+       else
+               rb_erase(&va->rb_node, root);
+
+       list_del(&va->list);
+       RB_CLEAR_NODE(&va->rb_node);
 }
 
 #if DEBUG_AUGMENT_PROPAGATE_CHECK
@@ -1162,8 +1159,6 @@ EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);
 
 static void __free_vmap_area(struct vmap_area *va)
 {
-       BUG_ON(RB_EMPTY_NODE(&va->rb_node));
-
        /*
         * Remove from the busy tree/list.
         */