drm/mm: Move a variable assignment behind a condition check in DECLARE_NEXT_HOLE_ADDR()
Subsystems (3)
PATCH 1/1 drm/mm: Move a variable assignment behind a condition check in DECLARE_NEXT_HOLE_ADDR()
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()")
Signed-off-by Markus Elfring <[email protected]>
--- drivers/gpu/drm/drm_mm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_mm.c +6 -2
@@ -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)) { \
Signature · 1 line
2.55.0