From: Markus Elfring <[email protected]>
Date: Sun, 12 Jul 2026 16:48:41 +0200

The address of a data structure member was determined before
a corresponding null pointer check in the implementation of
the macro “DECLARE_NEXT_HOLE_ADDR”.

Thus avoid the risk for undefined behaviour by moving the assignment
for the variable “node” behind a condition check.

This issue was detected by using the Coccinelle software.

Fixes: 5fad79fd66ff90b8c0a95319dad0b099008f8347 ("drm/mm: cleanup and improve 
next_hole_*_addr()")
Cc: [email protected]
Signed-off-by: Markus Elfring <[email protected]>
---
 drivers/gpu/drm/drm_mm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 6692abe564d3..9b9bece8da7d 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -390,9 +390,13 @@ first_hole(struct drm_mm *mm,
 #define DECLARE_NEXT_HOLE_ADDR(name, first, last)                      \
 static struct drm_mm_node *name(struct drm_mm_node *entry, u64 size)   \
 {                                                                      \
-       struct rb_node *parent, *node = &entry->rb_hole_addr;           \
+       struct rb_node *parent, *node;                                  \
                                                                        \
-       if (!entry || RB_EMPTY_NODE(node))                              \
+       if (!entry)                                                     \
+               return NULL;                                            \
+                                                                       \
+       node = &entry->rb_hole_addr;                                    \
+       if (RB_EMPTY_NODE(node))                                        \
                return NULL;                                            \
                                                                        \
        if (usable_hole_addr(node->first, size)) {                      \
-- 
2.55.0

Reply via email to