This helper tests whether a given node is currently linked into a drm_mm
manager. We use the node->mm pointer for that as it is set for all linked
objects.

We also reset node->mm whenever a node is removed. All such access is
currently safe as everyone calls kfree() on the object directly after
removing it. Furthermore, no-one is supposed to access node->mm from
outside drm_mm.c, anyway.

Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
---
 drivers/gpu/drm/drm_mm.c | 1 +
 include/drm/drm_mm.h     | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 7917729..3bd43ce 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -374,6 +374,7 @@ void drm_mm_remove_node(struct drm_mm_node *node)

        list_del(&node->node_list);
        node->allocated = 0;
+       node->mm = NULL;
 }
 EXPORT_SYMBOL(drm_mm_remove_node);

diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h
index de92425..d83b966 100644
--- a/include/drm/drm_mm.h
+++ b/include/drm/drm_mm.h
@@ -85,6 +85,11 @@ static inline bool drm_mm_node_allocated(struct drm_mm_node 
*node)
        return node->allocated;
 }

+static inline bool drm_mm_node_linked(struct drm_mm_node *node)
+{
+       return node->mm;
+}
+
 static inline bool drm_mm_initialized(struct drm_mm *mm)
 {
        return mm->hole_stack.next;
-- 
1.8.3.2

Reply via email to